promptulate icon indicating copy to clipboard operation
promptulate copied to clipboard

[promptulate] Failed to get data. Please check your network or api key. [output] Failed to get data.

Open sunhaha123 opened this issue 2 years ago • 14 comments

这个错误莫名其妙,我的key没问题,也有代理,各种解决不了

sunhaha123 avatar Jun 02 '23 10:06 sunhaha123

可以附上你的相关代码吗

Undertone0809 avatar Jun 02 '23 10:06 Undertone0809

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)'))

sunhaha123 avatar Jun 02 '23 10:06 sunhaha123

在这个代码的main中中,你使用了set_free_proxy(),即本项目的免费代理,因此不需要使用科学上网就可以使用,你需要把VPN关掉,使用国内免费代理 url 的时候不能开代理访问。

Undertone0809 avatar Jun 02 '23 10:06 Undertone0809

如果需要使用自己的代理,则main的代码应该为:

def main():
    proxies = {'http': 'your proxies'}
    set_proxy_mode("custom", proxies)
    llm = OpenAI()
    llm("你知道鸡哥的《只因你太美》?")

Undertone0809 avatar Jun 02 '23 10:06 Undertone0809

无论哪种我测试了2台机器都是如此, sad

sunhaha123 avatar Jun 02 '23 10:06 sunhaha123

试试下面的代码,打开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()

Undertone0809 avatar Jun 02 '23 10:06 Undertone0809

使用set_free_proxy(),即本项目的免费代理,有的时候其访问量过大也免费代理也会崩掉,后续会完善这一机制,可以使用代理池的方式来解决。

Undertone0809 avatar Jun 02 '23 10:06 Undertone0809

base_url 可以替换为https://api.openai-proxy.com/v1/chat/completions

sunhaha123 avatar Jun 02 '23 18:06 sunhaha123

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()

Undertone0809 avatar Jun 03 '23 08:06 Undertone0809

proxy不能使用https,要使用全局代理工具才能在关闭proxy配置下正常使用。

ruanrongman avatar Aug 09 '23 07:08 ruanrongman

proxy不能使用https,要使用全局代理工具才能在关闭proxy配置下正常使用。

这确实是requests的一个问题,可以尝试在文档的相关部分声明一下,提交一份pr。

Undertone0809 avatar Aug 09 '23 07:08 Undertone0809

我直接部署在美国,机子在美国没有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 avatar Nov 07 '23 08:11 xitinghe

@xitinghe 可以展示具体的报错信息吗?

Undertone0809 avatar Nov 07 '23 17:11 Undertone0809

Bot detected the issue body's language is not English, translate it automatically.


@xitinghe Can you show the specific error message?

Issues-translate-bot avatar Nov 07 '23 17:11 Issues-translate-bot