- Issue created by @michaellander
- Merge request !863Added multiple handling and minItem, maxItem support. β (Merged) created by michaellander
Context definitions have a 'multiple' property, which turns them into a list/array with the original data_type used as the 'item' definition.
Just before $properties[] = $property;
in \Drupal\ai\Utility\ContextDefinitionNormalizer::normalize
, we add:
// If multiple, wrap in array.
if ($definition->isMultiple()) {
$array_property = new ToolsPropertyInput($key);
$array_property->setType('array');
$array_property->setDescription('List of ' . $definition->getLabel());
$array_property->setItems($property);
$property = $array_property;
}
We also need to map over other properties as well (ex.. if item is required, set required or minItems, etc..)? The \Drupal\ai\OperationType\Chat\Tools\ToolsPropertyInput::setItems
method also only accepts array|string
, when I think we may actually want it to accept ToolPropertyInputInterface
, as most definitions I've found have a single definition and not an array for 'items'
. The exception are items that use anyOf
, oneOf
, etc...
An example array usage:
{
"type": "function",
"function": {
"name": "record_weather",
"description": "Record temperatures by city.",
"parameters": {
"type": "object",
"properties": {
"readings": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"city": { "type": "string", "minLength": 1 },
"temperature": { "type": "number" },
"unit": { "type": "string", "enum": ["C", "F"] }
},
"required": ["city", "temperature"],
"additionalProperties": false
}
}
},
"required": ["readings"],
"additionalProperties": false
}
}
}
Active
1.2
...to be triaged