Python
鉴权
string
header
必填
千问AI平台 API Key。详见获取 API Key。
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qianwenaiapi.com/compatible-mode/v1",
)
conversation = client.conversations.create(
metadata={"topic": "demo"},
items=[
{"type": "message", "role": "system", "content": "Alice, a gentle and resilient woman, was born in Beijing. She is 20 years old, and her hobbies are music and chess."}
]
)
print(conversation){
"created_at": 1771316949128,
"id": "conv_xxx",
"metadata": {
"topic": "demo"
},
"object": "conversation"
}千问AI平台 API Key。详见获取 API Key。
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qianwenaiapi.com/compatible-mode/v1",
)
conversation = client.conversations.create(
metadata={"topic": "demo"},
items=[
{"type": "message", "role": "system", "content": "Alice, a gentle and resilient woman, was born in Beijing. She is 20 years old, and her hobbies are music and chess."}
]
)
print(conversation){
"created_at": 1771316949128,
"id": "conv_xxx",
"metadata": {
"topic": "demo"
},
"object": "conversation"
}