pub fn chat(model: Model) -> ChatBuilderExpand description
Creates a new ChatBuilder with the specified model.
This is a convenience function that returns a ChatBuilder instance initialized with the given model. You can then chain additional methods to configure the chat request before sending it.
ยงExample
use ic_llm::{Model, ChatMessage, Response};
// Basic usage
ic_llm::chat(Model::Llama3_1_8B)
.with_messages(vec![
ChatMessage::System {
content: "You are a helpful assistant".to_string(),
},
ChatMessage::User {
content: "How big is the sun?".to_string(),
},
])
.send()
.awaitYou can also add tools to the chat:
use ic_llm::{Model, ChatMessage, ParameterType, Response};
ic_llm::chat(Model::Llama3_1_8B)
.with_messages(vec![
ChatMessage::System {
content: "You are a helpful assistant".to_string(),
},
ChatMessage::User {
content: "What's the balance of account abc123?".to_string(),
},
])
.with_tools(vec![
ic_llm::tool("icp_account_balance")
.with_description("Lookup the balance of an ICP account")
.with_parameter(
ic_llm::parameter("account", ParameterType::String)
.with_description("The ICP account to look up")
.is_required()
)
.build()
])
.send()
.await