Chat Completions
Documentation for the Goodfire Chat API
The Chat API provides methods for interacting with Goodfire’s language models in a chat format. The base chat interface is OpenAI-compatible. It supports both streaming and non-streaming completions, as well as logits computation.
Once you have a model variant, you can use it to create chat completions.
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 of messages in the conversation. Each message should have role
(“user”,
“assistant”, or “system”) and content
fields.
Model identifier or variant to use for completion
Whether to stream the response tokens
Maximum number of tokens to generate
Nucleus sampling parameter
Sampling temperature
Sequences where the API will stop generating further tokens
Random seed for reproducible outputs
System prompt to prepend to the conversation
Returns:
- If
stream=False
:ChatCompletion
object - If
stream=True
: Iterator ofStreamingChatCompletionChunk
objects
Examples:
Non-streaming completion:
Streaming completion:
logits()
Compute token probabilities for the next token in a conversation.
Parameters:
List of messages in the conversation
Model identifier or variant to use
Limit response to top K most likely tokens
List of tokens to compute probabilities for
Returns: LogitsResponse
containing token probabilities
Example:
Response Objects
ChatCompletion
Response from a non-streaming chat completion.
Properties:
Unique identifier for the completion
Object type identifier
Unix timestamp of when the completion was created
ID of the model used
System fingerprint for the completion
List of completion choices
StreamingChatCompletionChunk
Individual chunk from a streaming chat completion.
Properties:
Unique identifier for the completion
Object type identifier
Unix timestamp of when the chunk was created
ID of the model used
System fingerprint for the completion
List of completion choices in this chunk
LogitsResponse
Response from a logits computation request.
Properties:
Dictionary mapping tokens to their probabilities