var availableTools = []llms.Tool{
{
Type: "function",
Function: &llms.FunctionDefinition{
Name: "getCurrentWeather",
Description: "Get the current weather in a given location",
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"location": map[string]any{
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
},
"required": []string{"location"},
},
},
},
}
Assistant
The error you're encountering is due to an incomplete JSON Schema definition for the items property in your function's parameters. In JSON Schema, when you define a property of type "array", you must specify the "items" field to define the schema of the elements within the array. Without this, the schema is incomplete, and the LLM (Language Model) cannot process it correctly.
In your non-working code:
go
"items": map[string]any{
"type": "array",
"description": "Array of items to add to To-Do list",
},
Here, you've defined items as an array but haven't specified what each element in the array should look like. The error message points out this exact issue:
To fix the issue, you need to define the "items" field within your array definition to specify the type of elements the array should contain. For example, if the array should contain strings:
go
"items": map[string]any{
"type": "array",
"description": "Array of items to add to To-Do list",
"items": map[string]any{
"type": "string",
},
},
This tells the schema that items is an array where each element is a string. Here's the corrected code:
go
var availableTools = []llms.Tool{
{
Type: "function",
Function: &llms.FunctionDefinition{
Name: "createNewToDo",
Description: "Create a new To-Do List.",
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"name": map[string]any{
"type": "string",
"description": "Name of the To-Do",
},
"items": map[string]any{
"type": "array",
"description": "Array of items to add to To-Do list",
"items": map[string]any{
"type": "string",
},
},
},
"required": []string{"name", "items"},
},
},
},
}
Explanation:
"items" Field in JSON Schema: When defining an array in JSON Schema, the "items" field is required and specifies the schema of each element in the array.
Missing "items" Field: Omitting the "items" field in an array definition leads to an incomplete schema, causing the error you've encountered.
Providing Element Schema: By adding the "items" field with a type (e.g., "type": "string"), you complete the schema, allowing the LLM to process it correctly.
Reference: The JSON Schema documentation specifies that for arrays, the "items" keyword is used to define the type and structure of each item within the array. Here's the relevant excerpt:
items: This keyword defines the type and structure of each item in an array instance. The value of "items" is a schema that applies to each item in the array instance.
Summary: The error occurs because the array definition for items lacks the required "items" field specifying the schema of its elements. By adding this field and defining the element type, the LLM can process the function definition correctly.
Note: Always ensure that your JSON Schemas are complete and adhere to the specifications required by the tools or libraries you're using. Incomplete or incorrect schemas can lead to processing errors.