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"El tipo de herramienta. Currently supports "function", "custom", and other built-in types.
strictBooleanFalseWhether to enforce strict schema validation for function parameters.

Propiedades comunes

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.

Propiedades específicas de la función

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

Constructor

new()

new(object : Object) : OpenAITool

ParámetrosTipoDescripción
objectObjectObjeto de configuración de la herramienta
ResultadoOpenAIToolNew instance of OpenAITool

Crea una nueva instancia de OpenAITool. The constructor accepts both simplified format and OpenAI API format.

Formatos soportados

Formato simplificado:

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"] \
} \
})

Formato de la API OpenAI

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

Las herramientas se utilizan normalmente con la propiedad OpenAIChatCompletionsParameters.tools:

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

Nota: puede pasar objetos planos directamente, se convertirán automáticamente en instancias OpenAITool. No es necesario crear explícitamente objetos OpenAITool.

Ver también