Skip to content

Commit

Permalink
chore: openai version update and tool call message content converting (
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Jan 29, 2025
1 parent 1407555 commit fc210e2
Show file tree
Hide file tree
Showing 7 changed files with 563 additions and 469 deletions.
2 changes: 1 addition & 1 deletion camel/messages/func_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def to_openai_tool_message(self) -> OpenAIToolMessageParam:
" due to missing function name."
)

result_content = json.dumps(self.result)
result_content = str(self.result)

return {
"role": "tool",
Expand Down
9 changes: 0 additions & 9 deletions camel/models/openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from camel.messages import OpenAIMessage
from camel.models import BaseModelBackend
from camel.types import (
NOT_GIVEN,
ChatCompletion,
ChatCompletionChunk,
ModelType,
Expand Down Expand Up @@ -148,14 +147,6 @@ def run(

return self._to_chat_completion(response)

# Removing 'strict': True from the dictionary for
# client.chat.completions.create
if self.model_config_dict.get('tools') is not NOT_GIVEN:
for tool in self.model_config_dict.get('tools', []):
function_dict = tool.get('function', {})
if 'strict' in function_dict:
del function_dict['strict']

response = self._client.chat.completions.create(
messages=messages,
model=self.model_type,
Expand Down
11 changes: 5 additions & 6 deletions camel/toolkits/search_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
import xml.etree.ElementTree as ET
from typing import Any, Dict, List, Literal, Optional, Type, TypeAlias, Union
from typing import Any, Dict, List, Literal, Optional, TypeAlias, Union

import requests
from pydantic import BaseModel

from camel.toolkits.base import BaseToolkit
from camel.toolkits.function_tool import FunctionTool
Expand Down Expand Up @@ -77,7 +76,7 @@ def search_linkup(
output_type: Literal[
"searchResults", "sourcedAnswer", "structured"
] = "searchResults",
structured_output_schema: Union[Type[BaseModel], str, None] = None,
structured_output_schema: Optional[str] = None,
) -> Dict[str, Any]:
r"""Search for a query in the Linkup API and return results in various
formats.
Expand All @@ -92,9 +91,9 @@ def search_linkup(
- "searchResults" for raw search results,
- "sourcedAnswer" for an answer with supporting sources,
- "structured" for output based on a provided schema.
structured_output_schema (Union[Type[BaseModel], str, None]): If
`output_type` is "structured",specify the schema of the
output. Can be a Pydantic BaseModel or a JSON schema string.
structured_output_schema (Optional[str]): If `output_type` is
"structured", specify the schema of the output. Must be a
string representing a valid object JSON schema.
Returns:
Dict[str, Any]: A dictionary representing the search result. The
Expand Down
4 changes: 2 additions & 2 deletions examples/toolkits/openbb_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========

from camel.agents import ChatAgent
from camel.toolkits import openbb_toolkit
from camel.toolkits import OpenBBToolkit

# Initialize OpenBB toolkit with proper credentials
toolkit = openbb_toolkit.OpenBBToolkit()
toolkit = OpenBBToolkit()

# Example 1: Stock quotes for multiple companies
print("\nExample 1: Stock quotes for multiple companies")
Expand Down
1,000 changes: 552 additions & 448 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ documentation = "https://docs.camel-ai.org"
# Core dependencies
python = ">=3.10,<3.13"
numpy = "^1"
openai = "^1.58.1"
openai = "^1.59.7"
tiktoken = "^0.7.0"
colorama = "^0"
jsonschema = "^4"
Expand Down
4 changes: 2 additions & 2 deletions test/messages/test_func_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_function_func_message(

msg_dict: Dict[str, str] = {
"role": "tool",
"content": json.dumps(3),
"content": str(3),
"tool_call_id": "null",
}
assert function_result_message.to_openai_tool_message() == msg_dict
Expand All @@ -102,7 +102,7 @@ def test_assistant_func_message_to_openai_tool_message(
):
expected_msg_dict: Dict[str, str] = {
"role": "tool",
"content": json.dumps(None),
"content": str(None),
"tool_call_id": "null",
}

Expand Down

0 comments on commit fc210e2

Please sign in to comment.