gleamstral/tool
Types
Represents a function call within a tool call
Contains the name of the function and its arguments as a JSON string
pub type FunctionCall {
FunctionCall(name: String, arguments: String)
}
Constructors
-
FunctionCall(name: String, arguments: String)
Property definition for a tool parameter
pub type ParameterProperty {
ParameterProperty(param_type: String)
}
Constructors
-
ParameterProperty(param_type: String)
Represents a tool that can be used by the model
Function
: A function tool with name, description, and parameters
pub type Tool {
Function(
name: String,
description: String,
strict: Bool,
parameters: ToolParameters,
)
}
Constructors
-
Function( name: String, description: String, strict: Bool, parameters: ToolParameters, )
Represents a tool call made by the model
Contains the ID, type, function call details, and index of the tool call
pub type ToolCall {
ToolCall(
id: String,
tool_type: String,
function: FunctionCall,
index: Int,
)
}
Constructors
-
ToolCall( id: String, tool_type: String, function: FunctionCall, index: Int, )
Tool choice options for API requests
Auto
: Let the model decide when to use toolsNone
: Do not use toolsAny
: Allow the model to use any available toolRequired
: Require the model to use toolsChoice(Tool)
: Require the model to use a specific tool
pub type ToolChoice {
Auto
None
Any
Required
Choice(Tool)
}
Constructors
-
Auto
-
None
-
Any
-
Required
-
Choice(Tool)
Parameters for a tool function
Contains the structure of parameters expected by the tool
pub type ToolParameters {
ToolParameters(
tool_type: String,
properties: List(#(String, ParameterProperty)),
required: List(String),
additional_properties: Bool,
)
}
Constructors
-
ToolParameters( tool_type: String, properties: List(#(String, ParameterProperty)), required: List(String), additional_properties: Bool, )
Functions
pub fn create_function_tool(
name: String,
description: String,
strict: Bool,
property_types: List(#(String, String)),
required: List(String),
additional_properties: Bool,
) -> Tool
Create a function tool with parameters
Example
let weather_tool = tool.create_function_tool(
name: "get_weather",
description: "Get current temperature for provided coordinates in celsius.",
strict: True,
property_types: [
#("latitude", "number"),
#("longitude", "number"),
],
required: ["latitude", "longitude"],
additional_properties: False,
)
pub fn tool_call_decoder() -> Decoder(ToolCall)
Decodes a tool call from JSON
Used to parse tool calls in model responses
pub fn tool_calls_encoder(
tool_calls: Option(List(ToolCall)),
) -> Json
pub fn tool_choice_encoder(tool_choice: ToolChoice) -> Json
pub fn tool_encoder(tool: Tool) -> Json