[promptulate] Failed to get data. Please check your network or api key. [output] Failed to get data.
这个错误莫名其妙,我的key没问题,也有代理,各种解决不了
可以附上你的相关代码吗
from promptulate.llms import OpenAI from promptulate.utils import set_proxy_mode import os
os.environ['OPENAI_API_KEY'] = "**"
llm = OpenAI() llm("你知道鸡哥的《只因你太美》?")
def set_free_proxy(): set_proxy_mode("promptulate")
def set_custom_proxy(): proxies = {'http': 'http://127.0.0.1:1080'} set_proxy_mode("custom", proxies=proxies)
def turn_off_proxy(): set_proxy_mode("off")
def main(): set_free_proxy() llm = OpenAI() llm("你知道鸡哥的《只因你太美》?")
if name == 'main': main() requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001BF9654D690>, 'Connection to api.openai.com timed out. (connect timeout=None)'))
在这个代码的main中中,你使用了set_free_proxy(),即本项目的免费代理,因此不需要使用科学上网就可以使用,你需要把VPN关掉,使用国内免费代理 url 的时候不能开代理访问。
如果需要使用自己的代理,则main的代码应该为:
def main():
proxies = {'http': 'your proxies'}
set_proxy_mode("custom", proxies)
llm = OpenAI()
llm("你知道鸡哥的《只因你太美》?")
无论哪种我测试了2台机器都是如此, sad
试试下面的代码,打开VPN,看看输出结果是什么
from promptulate.llms import OpenAI
from promptulate.utils import set_proxy_mode, enable_log
def main():
enable_log()
proxies = {'http': 'your proxies'}
set_proxy_mode("custom", proxies)
llm = OpenAI()
print(llm("你知道《只因你太美》吗?"))
if __name__ == '__main__':
main()
使用set_free_proxy(),即本项目的免费代理,有的时候其访问量过大也免费代理也会崩掉,后续会完善这一机制,可以使用代理池的方式来解决。
base_url 可以替换为https://api.openai-proxy.com/v1/chat/completions
base_url 可以替换为https://api.openai-proxy.com/v1/chat/completions
可以按照下面的方式先配置一下,后续的版本中会更新更灵活的代理池
from promptulate.llms import OpenAI
from promptulate.utils import set_proxy_mode, enable_log
from promptulate.config import Config
def main():
cfg = Config()
cfg.openai_proxy_url = "https://api.openai-proxy.com/v1/chat/completions"
set_proxy_mode("promptulate")
# proxies = {'http': 'http://127.0.0.1:7890'}
# set_proxy_mode("custom", proxies)
llm = OpenAI()
print(llm("引力波的放射与广义相对论的必然关系"))
if __name__ == '__main__':
main()
proxy不能使用https,要使用全局代理工具才能在关闭proxy配置下正常使用。
proxy不能使用https,要使用全局代理工具才能在关闭proxy配置下正常使用。
这确实是requests的一个问题,可以尝试在文档的相关部分声明一下,提交一份pr。
我直接部署在美国,机子在美国没有vpn,也会遇到同样的问题,代码如下:
from promptulate import Conversation from promptulate.memory import FileChatMemory from promptulate.llms import OpenAI
def main(): memory = FileChatMemory() llm = OpenAI(model="gpt-3.5-turbo", temperature=0.9, top_p=1, stream=False, presence_penalty=0, n=1) conversation = Conversation(llm=llm, memory=memory) ret = conversation.predict("你知道鸡哥的著作《只因你太美》吗?") print(f"[predict] {ret}") ret = conversation.predict_by_translate("你知道鸡哥会什么技能吗?", country='America') print(f"[translate output] {ret}") ret = conversation.summary_content() print(f"[summary content] {ret}") ret = conversation.summary_topic() print(f"[summary topic] {ret}") ret = conversation.export_message_to_markdown(output_type="file", file_path="output.md") print(f"[export markdown] {ret}")
if name == 'main': main()
@xitinghe 可以展示具体的报错信息吗?
Bot detected the issue body's language is not English, translate it automatically.
@xitinghe Can you show the specific error message?