gleamstral/chat/chat
Types
Represents a chat conversation with configuration options
pub type Chat {
Chat(client: client.Client, config: Config)
}
Constructors
-
Chat(client: client.Client, config: Config)
pub type Config {
Config(
temperature: Float,
max_tokens: Int,
top_p: Float,
stream: Bool,
stop: List(String),
random_seed: Int,
response_format: ResponseFormat,
tools: List(tool.Tool),
tool_choice: tool.ToolChoice,
presence_penalty: Float,
frequency_penalty: Float,
n: Int,
prediction: Prediction,
safe_prompt: Bool,
)
}
Constructors
-
Config( temperature: Float, max_tokens: Int, top_p: Float, stream: Bool, stop: List(String), random_seed: Int, response_format: ResponseFormat, tools: List(tool.Tool), tool_choice: tool.ToolChoice, presence_penalty: Float, frequency_penalty: Float, n: Int, prediction: Prediction, safe_prompt: Bool, )
pub type Prediction {
Content(String)
}
Constructors
-
Content(String)
pub type ResponseFormat {
JsonObject
Text
}
Constructors
-
JsonObject
-
Text
Functions
pub fn complete(
chat: Chat,
model: Model,
messages: List(Message),
) -> Result(Response, Error)
Sends a chat completion request to the API and returns the response
Parameters
chat
: The configured Chat instancemodel
: The model to use for the completionmessages
: The conversation history as a list of messages
Returns
Ok(response.Response)
: The successful response from the APIError(client.Error)
: An error that occurred during the request
Example
let result = chat
|> chat.set_temperature(0.7)
|> chat.complete(model.MistralSmall, messages)
pub fn new(client: Client) -> Chat
Creates a new Chat with default configuration using the provided client
Example
let client = client.new("your-api-key")
let chat = chat.new(client)
pub fn set_frequency_penalty(
chat: Chat,
frequency_penalty: Float,
) -> Chat
pub fn set_max_tokens(chat: Chat, max_tokens: Int) -> Chat
pub fn set_prediction(chat: Chat, prediction: Prediction) -> Chat
pub fn set_presence_penalty(
chat: Chat,
presence_penalty: Float,
) -> Chat
pub fn set_random_seed(chat: Chat, random_seed: Int) -> Chat
pub fn set_response_format(
chat: Chat,
response_format: ResponseFormat,
) -> Chat
pub fn set_safe_prompt(chat: Chat, safe_prompt: Bool) -> Chat
pub fn set_stream(chat: Chat, stream: Bool) -> Chat
pub fn set_temperature(chat: Chat, temperature: Float) -> Chat
pub fn set_tool_choice(
chat: Chat,
tool_choice: ToolChoice,
) -> Chat