The Chat Completion API endpoint constructs a conversation based on the provided list of messages, then generates a response using the model.
On the PC side, construct a dialogue by passing a list of messages to the OpenAI API. Before running the program, modify the IP portion of base_url
below to match the actual device IP address, and install the corresponding model package on the device. For instructions on installing model packages, refer to the Model List section.
from openai import OpenAI
client = OpenAI(
api_key="sk-",
base_url="http://192.168.20.186:8000/v1"
)
completion = client.chat.completions.create(
model="qwen2.5-0.5B-p256-ax630c",
messages=[
{"role": "developer", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(completion.choices[0].message)
Parameter Name | Type | Required | Example Value | Description |
---|---|---|---|---|
messages | array | Yes | [{"role": "user", "content": "你好"}] | The conversation history, composed of multiple messages; supports text, images, audio, and other modalities (depending on the model). |
model | string | Yes | qwen2.5-0.5B-p256-ax630c | The model ID used to generate the reply. Multiple models are supported; see the Model List section. |
audio | – | No | – | Audio output is not currently supported. |
function_call | – | No | – | Function calling is not currently supported. |
max_tokens | integer | No | 1024 | The maximum number of tokens the model is allowed to generate; content beyond this limit will be truncated. |
response_format | object | No | "json_object" | Specifies the format of the model’s output; currently only "json_object" is supported. |
ChatCompletionMessage(content='Hello! How can I assist you today?', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None)