You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import os
|
|
|
|
|
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
client = OpenAI(
|
|
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
|
|
api_key='sk-f6da0c787eff4b0389e4ad03a35a911f',
|
|
|
|
|
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
completion = client.chat.completions.create(
|
|
|
|
|
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
|
|
model="qwen-plus",
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
|
|
{"role": "user", "content": "你是谁?"},
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
print(completion.choices[0].message.content)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"错误信息:{e}")
|
|
|
|
|
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
|