Python
Path Parameters
string
required
The conversation ID.
conv_xxx
Body
application/jsonobject[]
required
Message items to add (up to 20 per request).
items <= 20
Add message items to a conversation.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.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"
}The conversation ID.
Message items to add (up to 20 per request).
Show child attributes
Only message is supported.
Message role. system and developer roles have higher priority than user. assistant indicates model-generated messages from previous interactions.
Message content as a plain text string or a structured content list (such as ResponseInputText object array).
Created message items.
Show child attributes
The message item ID.
Message content. A plain text string or a structured content list (such as ResponseInputText object array).
Message role: user, assistant, system, or developer.
Processing status: in_progress, completed, or incomplete.
Always message.
ID of the first message item.
Whether more data is available.
ID of the last message item.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.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"
}