Skip to content

Commit a1f6f14

Browse files
small formatting
1 parent 059c17b commit a1f6f14

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ This repository provides LangChain components for various OCI services. It aims
1313
## Installation
1414

1515
You can install the `langchain-oci` package from PyPI.
16+
17+
release:
18+
/github subscribe langchain-ai/langchain-oci releases workflows:{name:"release"}
19+
/github unsubscribe langchain-ai/langchain-oci issues pulls commits deployments

libs/oci/langchain_oci/chat_models/oci_generative_ai.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def remove_signature_from_tool_description(name: str, description: str) -> str:
8080
"""
8181
Remove the tool signature and Args section from a tool description.
8282
83-
The signature is typically prefixed to the description and followed by an Args section.
83+
The signature is typically prefixed to the description and followed
84+
85+
by an Args section.
8486
"""
8587
description = re.sub(rf"^{name}\(.*?\) -(?:> \w+? -)? ", "", description)
8688
description = re.sub(r"(?s)(?:\n?\n\s*?)?Args:.*$", "", description)
@@ -164,8 +166,7 @@ def messages_to_oci_params(self, messages: Any, **kwargs: Any) -> Dict[str, Any]
164166

165167
@abstractmethod
166168
def convert_to_oci_tool(
167-
self,
168-
tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]
169+
self, tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]
169170
) -> Dict[str, Any]:
170171
"""Convert a tool definition into the provider-specific OCI tool format."""
171172
...
@@ -363,7 +364,7 @@ def messages_to_oci_params(
363364
)
364365
)
365366

366-
# Process current turn messages in reverse order until a HumanMessage is encountered
367+
# Process current turn messages in reverse order until a HumanMessage
367368
current_turn = []
368369
for message in reversed(messages):
369370
current_turn.append(message)
@@ -412,7 +413,9 @@ def convert_to_oci_tool(
412413
"""
413414
Convert a tool definition to an OCI tool for Cohere.
414415
415-
Supports BaseTool instances, JSON schema dictionaries, or Pydantic models/callables.
416+
Supports BaseTool instances, JSON schema dictionaries,
417+
418+
or Pydantic models/callables.
416419
"""
417420
if isinstance(tool, BaseTool):
418421
return self.oci_tool(
@@ -684,16 +687,20 @@ def messages_to_oci_params(
684687
role = self.get_role(message)
685688
if isinstance(message, ToolMessage):
686689
# For tool messages, wrap the content in a text content object.
687-
tool_content = [self.oci_chat_message_text_content(text=str(message.content))]
690+
tool_content = [
691+
self.oci_chat_message_text_content(text=str(message.content))
692+
]
688693
if message.tool_call_id:
689694
oci_message = self.oci_chat_message[role](
690695
content=tool_content,
691696
tool_call_id=message.tool_call_id,
692697
)
693698
else:
694699
oci_message = self.oci_chat_message[role](content=tool_content)
695-
elif isinstance(message, AIMessage) and message.additional_kwargs.get("tool_calls"):
696-
# For assistant messages with tool calls, process content and tool calls.
700+
elif isinstance(message, AIMessage) and message.additional_kwargs.get(
701+
"tool_calls"
702+
):
703+
# Process content and tool calls for assistant messages
697704
content = self._process_message_content(message.content)
698705
tool_calls = []
699706
for tool_call in message.tool_calls:
@@ -748,15 +755,21 @@ def _process_message_content(
748755
if item["type"] == "image_url":
749756
processed_content.append(
750757
self.oci_chat_message_image_content(
751-
image_url=self.oci_chat_message_image_url(url=item["image_url"]["url"])
758+
image_url=self.oci_chat_message_image_url(
759+
url=item["image_url"]["url"]
760+
)
752761
)
753762
)
754763
elif item["type"] == "text":
755-
processed_content.append(self.oci_chat_message_text_content(text=item["text"]))
764+
processed_content.append(
765+
self.oci_chat_message_text_content(text=item["text"])
766+
)
756767
else:
757768
raise ValueError(f"Unsupported content type: {item['type']}")
758769
else:
759-
raise ValueError(f"Content items must be str or dict, got: {type(item)}")
770+
raise ValueError(
771+
f"Content items must be str or dict, got: {type(item)}"
772+
)
760773
return processed_content
761774

762775
def convert_to_oci_tool(

0 commit comments

Comments
 (0)