Saltar al contenido principal
Versión: Siguiente

OpenAITool

The OpenAITool class represents a tool that can be called by the OpenAI model during a conversation. Tools allow the AI to perform specific functions and interact with external systems or retrieve information.

See OpenAIMessage to see how to responds to a tool call.

Note: The tool calls are handled automatically when using OpenAIChatHelper with autoHandleToolCalls enabled.

Propiedades

Root Properties

PropiedadTipoPor defectoDescripción
tipoText"function"The type of tool. Currently supports "function", "custom", and other built-in types.
strictBooleanFalseWhether to enforce strict schema validation for function parameters.

Common Properties

PropiedadTipoDescripción
nameTextThe name of the tool, which works as an identifier.
descripciónTextDescription of the tool to help the LLM decide when to use it.

Function-specific Properties

PropiedadTipoDescripción
parámetrosObjectParameters definition for the function using JSON schema format.

Constructor

new()

new(object : Object) : OpenAITool

ParámetrosTipoDescripción
objectObjectConfiguration object for the tool
ResultadoOpenAIToolNew instance of OpenAITool

Creates a new OpenAITool instance. The constructor accepts both simplified format and OpenAI API format.

Supported formats

Simplified format:

var $tool := cs.OpenAITool.new({ \
name: "get_weather"; \
description: "Get current weather for a location"; \
parameters: { \
type: "object"; \
properties: { \
location: {type: "string"; description: "City name"} \
}; \
required: ["location"] \
} \
})

OpenAI API format:

var $tool := cs.OpenAITool.new({ \
type: "function"; \
strict: True; \
function: { \
name: "get_weather"; \
description: "Get current weather for a location"; \
parameters: { \
type: "object"; \
properties: { \
location: {type: "string"; description: "City name"} \
}; \
required: ["location"] \
} \
} \
})

Integration with Chat Completions

Tools are typically used with the OpenAIChatCompletionsParameters.tools property:

var $parameters := cs.AIKit.OpenAIChatCompletionsParameters.new({ \
model: "gpt-4o-mini"; \
tools: [$tool1; $tool2; $tool3] \
})

Note: You can pass plain objects directly - they will be automatically converted to OpenAITool instances. There's no need to explicitly create OpenAITool objects.

Ver también