Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/oci/generative_ai_inference/models/cohere_chat_request_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ def tools(self, tools):
"""
self._tools = tools

def tools_as_dicts(self):
"""
Helper to represent tools in a plain dict form for interoperability with
frameworks that expect OpenAI-style tool mappings.

:return: A list of dicts representing the tools, or None if no tools are set.
:rtype: list[dict] or None
"""
if self._tools is None:
return None
return [t._to_tool_dict() if hasattr(t, "_to_tool_dict") else t for t in self._tools]

@property
def is_strict_tools_enabled(self):
"""
Expand Down
41 changes: 41 additions & 0 deletions src/oci/generative_ai_inference/models/cohere_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,47 @@ def parameter_definitions(self, parameter_definitions):
"""
self._parameter_definitions = parameter_definitions

def _to_tool_dict(self):
"""
Internal helper to expose this tool as a mapping compatible with OpenAI-style
tool descriptions (used by some orchestration libraries that expect dicts).
"""
return {
"type": "function",
"function": {
"name": self.name,
"description": self.description,
# Parameter definitions are already a mapping of parameter name to
# CohereParameterDefinition model objects.
"parameters": self.parameter_definitions or {}
}
}

def get(self, key, default=None):
"""
Provide a dict-like .get() so that consumers treating tools as mappings
(for example, some LangGraph helpers) can work with CohereTool instances.
"""
return self._to_tool_dict().get(key, default)

def __getitem__(self, key):
return self._to_tool_dict()[key]

def items(self):
return self._to_tool_dict().items()

def keys(self):
return self._to_tool_dict().keys()

def values(self):
return self._to_tool_dict().values()

def __iter__(self):
return iter(self._to_tool_dict())

def __len__(self):
return len(self._to_tool_dict())

def __repr__(self):
return formatted_flat_dict(self)

Expand Down
35 changes: 35 additions & 0 deletions src/oci/generative_ai_inference/models/cohere_tool_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,41 @@ def function(self, function):
"""
self._function = function

def _to_tool_dict(self):
"""
Internal helper to expose this tool as a mapping compatible with OpenAI-style
tool descriptions (used by some orchestration libraries that expect dicts).
"""
return {
"type": self.type,
"function": self.function
}

def get(self, key, default=None):
"""
Provide a dict-like .get() so that consumers treating tools as mappings
(for example, some LangGraph helpers) can work with CohereToolV2 instances.
"""
return self._to_tool_dict().get(key, default)

def __getitem__(self, key):
return self._to_tool_dict()[key]

def items(self):
return self._to_tool_dict().items()

def keys(self):
return self._to_tool_dict().keys()

def values(self):
return self._to_tool_dict().values()

def __iter__(self):
return iter(self._to_tool_dict())

def __len__(self):
return len(self._to_tool_dict())

def __repr__(self):
return formatted_flat_dict(self)

Expand Down