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 {
  StringProperty(description: String)
  IntegerProperty(description: String)
  NumberProperty(description: String)
  BooleanProperty(description: String)
  ArrayProperty(
    description: String,
    item_type: ParameterProperty,
  )
  ObjectProperty(
    description: String,
    properties: List(#(String, ParameterProperty)),
  )
}

Constructors

  • StringProperty(description: String)

    A string property type

  • IntegerProperty(description: String)

    An integer property type

  • NumberProperty(description: String)

    A number property type (float or integer)

  • BooleanProperty(description: String)

    A boolean property type

  • ArrayProperty(description: String, item_type: ParameterProperty)

    An array property type with an item type (string, integer, number, boolean)

  • ObjectProperty(
      description: String,
      properties: List(#(String, ParameterProperty)),
    )

    An object property type

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 tools
  • None: Do not use tools
  • Any: Allow the model to use any available tool
  • Required: Require the model to use tools
  • Choice(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,
    )

Values

pub fn create_function_tool(
  name: String,
  description: String,
  strict: Bool,
  property_types: List(#(String, String)),
  required: List(String),
  additional_properties: Bool,
) -> Tool

Deprecated: Please use the tool/new_basic_function or make your own Tool type.

pub fn new_basic_function(
  name: String,
  description: String,
  properties: List(#(String, ParameterProperty)),
) -> Tool

Creates a new basic function tool with the given name, description, and properties.

Parameters

  • name: The name of the function tool.
  • description: A brief description of the function tool.
  • properties: A list of tuples where each tuple contains a property name and its type.

Returns

A Tool representing the function tool.

Examples

let tool = new_basic_function(
  "get_weather",
  "Get the current weather for the provided city. Use the unit for the temperature.",
  [#("city", "string"), #("unit", "string")]
)
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_decoder() -> Decoder(Tool)

Decodes a tool from JSON

pub fn tool_encoder(tool: Tool) -> Json
Search Document