pdf-icon

Product Guide

Industrial Control

Real-Time AI Voice Assistant

AtomS3R-M12 Volcengine Kit

Offline Voice Recognition

Thread

Module Gateway H2

IoT Measuring Instruments

IoT Cloud

Ethernet Camera

DIP Switch Usage Guide

Module GPS v2.0

Module GNSS

Module ExtPort For Core2

Module LoRa868 V1.2

Chat Completion

The Chat Completion API endpoint constructs a conversation based on the provided list of messages, then generates a response using the model.

Example

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)

Request Parameters

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.

Response Example

ChatCompletionMessage(content='Hello! How can I assist you today?', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None)
On This Page