baidubce / bce-qianfan-sdk

Provide best practices for LMOps, as well as elegant and convenient access to the features of the Qianfan MaaS Platform. (提供大模型工具链最佳实践,以及优雅且便捷地访问千帆大模型平台)
https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html
Apache License 2.0
308 stars 48 forks source link

异步刷新accessToken报连接不上服务器 #1258 #786

Open ming1028 opened 1 week ago

ming1028 commented 1 week ago

Issue you'd like to raise.

base.py:406 [t:140096597632832]: retry is not available when stream is enabled WARNING:qianfan:retry is not available when stream is enabled openapi_requestor.py:377 [t:140096597632832]: async requesting llm api endpoint: /chat/completions INFO:qianfan:async requesting llm api endpoint: /chat/completions [INFO] [09-09 10:08:13] oauth.py:229 [t:140096597632832]: trying to refresh access_token for ak yf7AZx INFO:qianfan:trying to refresh access_token for ak yf7AZx [INFO:qianfan:sucessfully refresh access_token for ak yf7AZx***](oauth.py:240 [t:140096597632832]: refresh access token failed with exception Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable]) 服务器能ping通,调用同步方法可以调通

Suggestion:

No response

Dobiichi-Origami commented 1 week ago

烦请提供当前正在使用的 SDK 版本号,并且更新 SDK 到最新版本再次尝试

ming1028 commented 1 week ago

0.3.7升级最新的之后,还是同样错误,只发生在异步调用下,模型ERNIE-Bot ERROR:qianfan:request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... [WARNING][2024-09-09 15:22:16.479] oauth.py:170 [t:140389062383424]: access token is not available for ak yf7AZx*** WARNING:qianfan:access token is not available for ak yf7AZx*** [ERROR][2024-09-09 15:22:16.507] base.py:475 [t:140389062383424]: request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... ERROR:qianfan:request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... [WARNING][2024-09-09 15:22:19.296] oauth.py:170 [t:140389062383424]: access token is not available for ak yf7AZx*** WARNING:qianfan:access token is not available for ak yf7AZx*** [ERROR][2024-09-09 15:22:19.320] base.py:475 [t:140389062383424]: request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying... ERROR:qianfan:request exception: Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable], retrying...

Dobiichi-Origami commented 1 week ago

如果可以的话,麻烦提供下能够复现的代码,方便我们进一步定位问题,thx

ming1028 commented 1 week ago

使用的fastapi @appRouter.post("/chatAsync", response_model=Resp) async def chatAsync(): template = """你是一个信息提炼专家、网页研究分析师、教育设计专家和知识整合专家,你能够通读这个网页,提取出这篇论文的核心要点,确保完全理解这个网页的上下文和要点,并且根据网页内容,设计与上下文相关的问题,旨在更好地记忆和理解网页。\n 你的任务是帮助我阅读和理解网页,根据网页内容提供30个与网页介绍的核心论点问题,要求这30个问题涉及不同的内容,使我浏览网页时可以留意你提供的问题。\n 下面是文章内容:\n “这140亿,会投给哪些供应商?”、“我们有机会竞标新车型吗?”

昨天傍晚,中国本土供应商热情沸腾了,他们隐约看见了一个难得的机会——成为梅赛德斯-奔驰的供应商。这不仅能增加销量,更意味着他们将提升至豪华品牌的制造品质,拥有进军国际的可能。指向性如此明显的询问背后,过去半年,奔驰中国已经为特定车型的供应商公开竞标在做准备了。

点燃这一切的导火索,是奔驰9月4日宣布的两项重磅消息:与合作伙伴共同在华投资增加140亿元;2025年起,将推出三款由中国团队主导开发的国产化新车型。


输出格式要求: 1,只输出30个问题,且只要问题的标题 2,输出的问题需要带上数字编号 3,输出的文本以正文格式返回,不需要粗体、加粗、不要strong标签 4,避免回复重复或多余""" answer_data = dict() try: chat_comp = qianfan.ChatCompletion() resp = await chat_comp.ado(model="ERNIE-Bot", messages=[{ "role": "user", "content": template }], stream=True)

    all_text = ""
    async for r in resp:
        text = r.body.get("result")
        logger.info("item text:%s", text)
        all_text += text
        if r.body.get("is_end"):
            answer_data["answer"] = tools_fun.Fun.extract_questions(all_text)
except Exception as e:
     return Resp(msg=str(e))
return Resp(data=answer_data)
ming1028 commented 6 days ago

借鉴:https://stackoverflow.com/questions/63347818/aiohttp-client-exceptions-clientconnectorerror-cannot-connect-to-host-stackover

chat_comp = qianfan.ChatCompletion(ssl=False)
resp = await chat_comp.ado(model="ERNIE-Bot", messages=[{
"role": "user",
"content": template
}], stream=True)

增加ssl=False之后,接口可以调通,但是报错日志还在 [ERROR][2024-09-11 10:37:32.993] oauth.py:338 [t:139944482232128]: refresh access token failed with exception Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable] ERROR:qianfan:refresh access token failed with exception Cannot connect to host aip.baidubce.com:443 ssl:default [Network is unreachable] [WARNING][2024-09-11 10:37:32.993] oauth.py:170 [t:139944482232128]: access token is not available for ak yf7AZx*** WARNING:qianfan:access token is not available for ak yf7AZx*** ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f4740ab4490>