Package com.tnsai.llm.providers
Class CohereToolConverter
java.lang.Object
com.tnsai.llm.providers.CohereToolConverter
Translates the OpenAI-flavoured intermediate tool schema into
Cohere's chat-API tool shape.
Cohere's tool definition is structurally different from OpenAI's:
{
"name": "search",
"description": "Searches a database",
"parameter_definitions": {
"query": { "description": "...", "type": "str", "required": true }
}
}
Two shape differences from OpenAI:
- Parameters are flat (
parameter_definitions: {name → spec}) rather than nested under a JSON-Schemaparameters.properties. requiredlives on each individual parameter spec, not in a separaterequired: [...]array.
Cohere has no native examples surface, so @ToolExample
positives + negatives both fold into description via
ToolExampleConverter.foldAllExamplesIntoDescription(java.lang.String, java.util.List<java.util.Map<java.lang.String, java.lang.Object>>).
Type names are translated from JSON-Schema to Cohere's
Python-style aliases (string → str, integer → int,
etc.) — Cohere's API documents type names rather than parsing
arbitrary JSON-Schema.
- See Also:
-
Method Summary
-
Method Details
-
convertToCohereTools
Convert an OpenAI-flavoured tool list into Cohere's tool list.Tools whose
typeis not"function", or whosefunctionobject is missing, are skipped silently — the intermediate schema only emitsfunction-typed entries today.- Parameters:
tools- intermediate tools (OpenAI shape); may benull- Returns:
- Cohere-shaped tools; empty list if the input is empty
-