会话
添加消息
Python
复制
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)
items = client.conversations.items.create(
"conv_xxx",
items=[
{
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "Alice's major is teacher education"}],
}
],
)
print(items.data)复制
{
"data": [
{
"content": [
{
"text": "Alice's major is teacher education",
"type": "input_text"
}
],
"id": "msg_xxx",
"role": "user",
"status": "completed",
"type": "message"
}
],
"first_id": "msg_xxx",
"has_more": false,
"last_id": "msg_xxx"
}
