Examples
Basic Chat Completion
Streaming Chat Completion
Using with Model Variants
Computing Token Probabilities
Methods
create()
Create a chat completion with the model. Parameters:list[ChatMessage]
required
List of messages in the conversation. Each message should have
role (“user”,
“assistant”, or “system”) and content fields.Union[str, VariantInterface]
required
Model identifier or variant to use for completion
bool
default:"False"
Whether to stream the response tokens
Optional[int]
default:"2048"
Maximum number of tokens to generate
float
default:"0.9"
Nucleus sampling parameter
float
default:"0.6"
Sampling temperature
Optional[Union[str, list[str]]]
Sequences where the API will stop generating further tokens
Optional[int]
default:"42"
Random seed for reproducible outputs
str
System prompt to prepend to the conversation
- If
stream=False:ChatCompletionobject - If
stream=True: Iterator ofStreamingChatCompletionChunkobjects
Basic Chat Completion
Streaming Chat Completion
logits()
Compute token probabilities for the next token in a conversation. Parameters:list[ChatMessage]
required
List of messages in the conversation
Union[str, VariantInterface]
required
Model identifier or variant to use
Optional[int]
Limit response to top K most likely tokens
Optional[list[str]]
List of tokens to compute probabilities for
LogitsResponse containing token probabilities
Example:
Token Probabilities
Response Objects
ChatCompletion
Response from a non-streaming chat completion. Properties:str
Unique identifier for the completion
str
Object type identifier
Optional[int]
Unix timestamp of when the completion was created
str
ID of the model used
str
System fingerprint for the completion
list[ChatCompletionChoice]
List of completion choices
StreamingChatCompletionChunk
Individual chunk from a streaming chat completion. Properties:str
Unique identifier for the completion
str
Object type identifier
Optional[int]
Unix timestamp of when the chunk was created
str
ID of the model used
str
System fingerprint for the completion
list[StreamingChoice]
List of completion choices in this chunk
LogitsResponse
Response from a logits computation request. Properties:dict[str, float]
Dictionary mapping tokens to their probabilities