Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: New Function Gemma integration PR3605 (#3606)

Wendong-Fan2892d3b47bf3
diff --git a/camel/configs/__init__.py b/camel/configs/__init__.py
index 3bb65d055..8a61dc168 100644
--- a/camel/configs/__init__.py
+++ b/camel/configs/__init__.py
@@ -22,7 +22,10 @@ from .cohere_config import COHERE_API_PARAMS, CohereConfig
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 786c295d2..1cba577a5 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 3389a03bf..1e4d331ec 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 @@ class FunctionGemmaModel(BaseModelBackend):
str: Formatted model turn.
"""
content = message.get("content", "") or ""
- tool_calls = message.get("tool_calls", [])
+ tool_calls = message.get("tool_calls")
result = f"<start_of_turn>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 @@ class FunctionGemmaModel(BaseModelBackend):
# 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 @@ class FunctionGemmaModel(BaseModelBackend):
Returns:
Dict[str, Any]: Parsed arguments dictionary.
"""
- args = {}
+ args: Dict[str, Any] = {}
if not args_str:
return args
@@ -567,7 +569,7 @@ class FunctionGemmaModel(BaseModelBackend):
char = args_str[i]
# check for <escape> tag
- if args_str[i:i+8] == "<escape>":
+ if args_str[i : i + 8] == "<escape>":
in_escape = not in_escape
i += 8
continue
@@ -627,7 +629,7 @@ class FunctionGemmaModel(BaseModelBackend):
# return as string
return value
- def _to_chat_completion(
+ def _to_chat_completion( # type: ignore[override]
self,
response_text: str,
model: str,