diff --git a/camel/configs/__init__.py b/camel/configs/__init__.py index 3bb65d0555..8a61dc168a 100644 --- a/camel/configs/__init__.py +++ b/camel/configs/__init__.py @@ -22,7 +22,10 @@ from .cometapi_config import COMETAPI_API_PARAMS, CometAPIConfig from .crynux_config import CRYNUX_API_PARAMS, CrynuxConfig from .deepseek_config import DEEPSEEK_API_PARAMS, DeepSeekConfig -from .function_gemma_config import FUNCTION_GEMMA_API_PARAMS, FunctionGemmaConfig +from .function_gemma_config import ( + FUNCTION_GEMMA_API_PARAMS, + FunctionGemmaConfig, +) from .gemini_config import Gemini_API_PARAMS, GeminiConfig from .groq_config import GROQ_API_PARAMS, GroqConfig from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig diff --git a/camel/configs/function_gemma_config.py b/camel/configs/function_gemma_config.py index 786c295d2f..1cba577a59 100644 --- a/camel/configs/function_gemma_config.py +++ b/camel/configs/function_gemma_config.py @@ -1,4 +1,4 @@ -# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. ========= # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -10,7 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. ========= from __future__ import annotations from typing import List, Optional diff --git a/camel/models/function_gemma_model.py b/camel/models/function_gemma_model.py index 3389a03bfc..1e4d331ec9 100644 --- a/camel/models/function_gemma_model.py +++ b/camel/models/function_gemma_model.py @@ -1,4 +1,4 @@ -# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. ========= # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -10,7 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= +# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. ========= import json import os import re @@ -279,25 +279,25 @@ def _format_model_turn(self, message: OpenAIMessage) -> str: str: Formatted model turn. """ content = message.get("content", "") or "" - tool_calls = message.get("tool_calls", []) + tool_calls = message.get("tool_calls") result = f"model\n{content}" - if tool_calls: + if tool_calls and isinstance(tool_calls, list): for tool_call in tool_calls: func = tool_call.get("function", {}) func_name = func.get("name", "") - args = func.get("arguments", "{}") - if isinstance(args, str): - args = json.loads(args) + args_raw = func.get("arguments", "{}") + if isinstance(args_raw, str): + args: Dict[str, Any] = json.loads(args_raw) + else: + args = dict(args_raw) if args_raw else {} # format arguments arg_parts = [] for key, value in sorted(args.items()): if isinstance(value, str): - arg_parts.append( - f"{key}:{self._escape_string(value)}" - ) + arg_parts.append(f"{key}:{self._escape_string(value)}") else: arg_parts.append(f"{key}:{json.dumps(value)}") @@ -324,6 +324,8 @@ def _format_tool_response(self, message: OpenAIMessage) -> str: # try to parse content as json for structured response try: + if not isinstance(content, str): + content = str(content) if content else "" result_data = json.loads(content) # check if it's a dict (structured response) if isinstance(result_data, dict): @@ -552,7 +554,7 @@ def _parse_function_args(self, args_str: str) -> Dict[str, Any]: Returns: Dict[str, Any]: Parsed arguments dictionary. """ - args = {} + args: Dict[str, Any] = {} if not args_str: return args @@ -567,7 +569,7 @@ def _parse_function_args(self, args_str: str) -> Dict[str, Any]: char = args_str[i] # check for tag - if args_str[i:i+8] == "": + if args_str[i : i + 8] == "": in_escape = not in_escape i += 8 continue @@ -627,7 +629,7 @@ def _parse_value(self, value: str) -> Any: # return as string return value - def _to_chat_completion( + def _to_chat_completion( # type: ignore[override] self, response_text: str, model: str,