pub struct Chat { /* private fields */ }Implementations§
Source§impl Chat
impl Chat
Sourcepub fn new<T>(model: T) -> Self
pub fn new<T>(model: T) -> Self
Creates a new Chat with the selected model.
§Example
use rustylms::{
chat::Chat,
lmsserver::LMSServer
};
let server = LMSServer::new("http://localhost:1234");
let chat = Chat::new("model-name").system_prompt("You are a helpful assistant.").user_prompt("Why does iron rust?");
let completion = chat.get_completions(&server).await.expect("Could not get completions");
println!("From assistant: {}", completion.get_message().unwrap().content);Sourcepub fn temperature(self, temperature: f32) -> Self
pub fn temperature(self, temperature: f32) -> Self
Sets the temperature of the model. The default value for this is 0.7.
Sourcepub fn max_tokens(self, max_tokens: i32) -> Self
pub fn max_tokens(self, max_tokens: i32) -> Self
Sets the maximum tokens a completion can generate. The default value is -1 meaning no limit.
Sourcepub fn system_prompt<T>(self, system_prompt: T) -> Self
pub fn system_prompt<T>(self, system_prompt: T) -> Self
This function adds a system prompt to the messages.
NOTE: This function doesn’t clear the messages array before adding the system prompt!
Sourcepub fn user_prompt<T>(self, user_prompt: T) -> Self
pub fn user_prompt<T>(self, user_prompt: T) -> Self
This function adds a user prompt to the messages.
NOTE: This function doesn’t clear the messages array before adding the user prompt!
Sourcepub fn clear_messages(&mut self)
pub fn clear_messages(&mut self)
Clears all messages in the chat including system prompts.
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Adds the provided Message to the chat.
Sourcepub fn add_system_message<T>(&mut self, message: T)
pub fn add_system_message<T>(&mut self, message: T)
Adds the provided message content as a system message.
Sourcepub fn add_assistant_message<T>(&mut self, message: T)
pub fn add_assistant_message<T>(&mut self, message: T)
Adds the provided message content as a message from the assistant.
Sourcepub fn add_user_message<T>(&mut self, message: T)
pub fn add_user_message<T>(&mut self, message: T)
Adds the provided message content as a message from the user.
Sourcepub async fn get_completions(
&self,
server: &LMSServer,
) -> Result<ChatCompletionsResponse>
pub async fn get_completions( &self, server: &LMSServer, ) -> Result<ChatCompletionsResponse>
Gets the completion from the server by sending the current Chat struct.