pub struct ChatToolFunction {
pub name: String,
pub description: Option<String>,
pub parameters: Option<Value>,
pub strict: Option<bool>,
}
Fields§
§name: String
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
description: Option<String>
A description of what the function does, used by the model to choose when and how to call the function.
parameters: Option<Value>
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting parameters
defines a function with an empty parameter list.
strict: Option<bool>
Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters
field. Only a subset of JSON Schema is supported when strict
is true
. Learn more about Structured Outputs in the function calling guide.
Implementations§
Source§impl ChatToolFunction
impl ChatToolFunction
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Examples found in repository?
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
More examples
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"llama3.2:3b",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"mistralai/ministral-8b",
// "openai/gpt-4o-mini",
// "google/gemini-flash-1.5-8b", // error
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Examples found in repository?
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
More examples
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"llama3.2:3b",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"mistralai/ministral-8b",
// "openai/gpt-4o-mini",
// "google/gemini-flash-1.5-8b", // error
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
Sourcepub fn strict(self, value: bool) -> Self
pub fn strict(self, value: bool) -> Self
Examples found in repository?
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
More examples
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"llama3.2:3b",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"mistralai/ministral-8b",
// "openai/gpt-4o-mini",
// "google/gemini-flash-1.5-8b", // error
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
Sourcepub fn parameters(self, parameters: Value) -> Self
pub fn parameters(self, parameters: Value) -> Self
Examples found in repository?
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
More examples
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"llama3.2:3b",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"gpt-4o-mini",
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
async fn example_tool_calls() -> Result<(), Error> {
let request = ChatRequest::new(
"mistralai/ministral-8b",
// "openai/gpt-4o-mini",
// "google/gemini-flash-1.5-8b", // error
vec![
ChatMessage::system("You are a helpful assistant"),
ChatMessage::user(r#"What's the weather like in Vietnam?"#),
],
)
.tools(vec![ChatToolFunction::new("get_current_weather")
.strict(true)
.description("Get the current weather in a given location")
.parameters(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
],
"additionalProperties": false
}))]);
tracing::info!("request: \n{}", request.to_string_pretty()?);
let response = request.send().await?;
tracing::info!("response: \n{}", response.to_string_pretty()?);
Ok(())
}
Trait Implementations§
Source§impl Clone for ChatToolFunction
impl Clone for ChatToolFunction
Source§fn clone(&self) -> ChatToolFunction
fn clone(&self) -> ChatToolFunction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more