Streaming Messages
Streaming messages enables users to receive the model's responses in chunks, rather than waiting for the compete response to be generated. This is done by incrementally transmitting chunks of content to the user. This feature enables users to:
Instant Responses: Content appears progressively without waiting for the full output.
Enhanced User Experience: Minimizes waiting time and offers immediate feedback.
Lower Latency: Information is delivered as it’s created, reducing perceived delay.
Dynamic Handling: Allows real-time processing and display while data is being received.
Parameter
To enable streaming, set stream=True.
Code
curl https://api.arcee.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "arcee-ai/AFM-4.5B",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the difference between SLMs and LLMs?"
}
],
"stream":true
}'from openai import OpenAI
client = OpenAI(
api_key="", # Your Arcee API Platform API Key
base_url="https://api.arcee.ai/api/v1/")
response = client.chat.completions.create(
model="arcee-ai/AFM-4.5B",
messages=[
{"role":"system", "content":"You are a helpful assistant"},
{"role":"user", "content": "What is the difference between SLMs and LLMs?"},
],
stream=True
)
for chunk in response:
if chunk and hasattr(chunk, 'choices') and chunk.choices:
delta = chunk.choices[0].delta
if hasattr(delta, 'content') and delta.content is not None:
print(delta.content, end="", flush=True)Response Example
data: {"choices": [{"delta": {"content": "Hello"}}]}
data: {"choices": [{"delta": {"content": "!"}}]}
data: {"choices": [{"delta": {"content": " How"}}]}
...
data: {"choices": [{"delta": {"content": " today"}}]}
data: {"choices": [{"delta": {"content": "?"}}]}
data: [DONE]Last updated


