QwenLM / Qwen-Agent

Agent framework and applications built upon Qwen2, featuring Function Calling, Code Interpreter, RAG, and Chrome extension.
https://pypi.org/project/qwen-agent/
Other
2.51k stars 249 forks source link

DASHSCOPE网络访问错误 #196

Closed gaozhiguang closed 4 days ago

gaozhiguang commented 2 weeks ago

您好,我用dashscope访问,报错: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dashscope.aliyuncs.com', port=443): Max retries exceeded with url: /api/v1/services/aigc/text-generation/generation (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x1026a9670>: Failed to establish a new connection: [Errno 61] Connection refused'))

代码如下: from http import HTTPStatus import dashscope import os

def sample_sync_call(): prompt_text = '用萝卜、土豆、茄子做饭,给我个菜谱。' resp = dashscope.Generation.call( model='qwen-turbo', prompt=prompt_text )

The response status_code is HTTPStatus.OK indicate success,

# otherwise indicate request is failed, you can get error code
# and message from code and message.
if resp.status_code == HTTPStatus.OK:
    print(resp.output)  # The output text
    print(resp.usage)  # The usage information
else:
    print('=='*20)
    print(resp.code)  # The error code.
    print(resp.message)  # The error message.

sample_sync_call()

用openai接口可正常访问,代码如下 from openai import OpenAI import os

def get_response(): client = OpenAI( api_key=os.getenv("DASHSCOPE_API_KEY"), # 如果您没有配置环境变量,请在此处用您的API Key进行替换 base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # 填写DashScope SDK的base_url ) completion = client.chat.completions.create( model="qwen-plus", messages=[{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': '你是谁?'}] ) print(completion.model_dump_json())

if name == 'main': get_response()

请问如何解决上述问题呢?

JianxinMa commented 2 weeks ago

我这边用您给的dashscope例子执行是正常的,无法复现。。(另,本项目没有dashscope的同事。。)