Skip to content

Commit 2892d3b

Browse files
authored
fix: New Function Gemma integration PR3605 (#3606)
1 parent 8c64c12 commit 2892d3b

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

camel/configs/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
from .cometapi_config import COMETAPI_API_PARAMS, CometAPIConfig
2323
from .crynux_config import CRYNUX_API_PARAMS, CrynuxConfig
2424
from .deepseek_config import DEEPSEEK_API_PARAMS, DeepSeekConfig
25-
from .function_gemma_config import FUNCTION_GEMMA_API_PARAMS, FunctionGemmaConfig
25+
from .function_gemma_config import (
26+
FUNCTION_GEMMA_API_PARAMS,
27+
FunctionGemmaConfig,
28+
)
2629
from .gemini_config import Gemini_API_PARAMS, GeminiConfig
2730
from .groq_config import GROQ_API_PARAMS, GroqConfig
2831
from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig

camel/configs/function_gemma_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1+
# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. =========
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -10,7 +10,7 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
13-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
13+
# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. =========
1414
from __future__ import annotations
1515

1616
from typing import List, Optional

camel/models/function_gemma_model.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1+
# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. =========
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -10,7 +10,7 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
13-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
13+
# ========= Copyright 2023-2025 @ CAMEL-AI.org. All Rights Reserved. =========
1414
import json
1515
import os
1616
import re
@@ -279,25 +279,25 @@ def _format_model_turn(self, message: OpenAIMessage) -> str:
279279
str: Formatted model turn.
280280
"""
281281
content = message.get("content", "") or ""
282-
tool_calls = message.get("tool_calls", [])
282+
tool_calls = message.get("tool_calls")
283283

284284
result = f"<start_of_turn>model\n{content}"
285285

286-
if tool_calls:
286+
if tool_calls and isinstance(tool_calls, list):
287287
for tool_call in tool_calls:
288288
func = tool_call.get("function", {})
289289
func_name = func.get("name", "")
290-
args = func.get("arguments", "{}")
291-
if isinstance(args, str):
292-
args = json.loads(args)
290+
args_raw = func.get("arguments", "{}")
291+
if isinstance(args_raw, str):
292+
args: Dict[str, Any] = json.loads(args_raw)
293+
else:
294+
args = dict(args_raw) if args_raw else {}
293295

294296
# format arguments
295297
arg_parts = []
296298
for key, value in sorted(args.items()):
297299
if isinstance(value, str):
298-
arg_parts.append(
299-
f"{key}:{self._escape_string(value)}"
300-
)
300+
arg_parts.append(f"{key}:{self._escape_string(value)}")
301301
else:
302302
arg_parts.append(f"{key}:{json.dumps(value)}")
303303

@@ -324,6 +324,8 @@ def _format_tool_response(self, message: OpenAIMessage) -> str:
324324

325325
# try to parse content as json for structured response
326326
try:
327+
if not isinstance(content, str):
328+
content = str(content) if content else ""
327329
result_data = json.loads(content)
328330
# check if it's a dict (structured response)
329331
if isinstance(result_data, dict):
@@ -552,7 +554,7 @@ def _parse_function_args(self, args_str: str) -> Dict[str, Any]:
552554
Returns:
553555
Dict[str, Any]: Parsed arguments dictionary.
554556
"""
555-
args = {}
557+
args: Dict[str, Any] = {}
556558
if not args_str:
557559
return args
558560

@@ -567,7 +569,7 @@ def _parse_function_args(self, args_str: str) -> Dict[str, Any]:
567569
char = args_str[i]
568570

569571
# check for <escape> tag
570-
if args_str[i:i+8] == "<escape>":
572+
if args_str[i : i + 8] == "<escape>":
571573
in_escape = not in_escape
572574
i += 8
573575
continue
@@ -627,7 +629,7 @@ def _parse_value(self, value: str) -> Any:
627629
# return as string
628630
return value
629631

630-
def _to_chat_completion(
632+
def _to_chat_completion( # type: ignore[override]
631633
self,
632634
response_text: str,
633635
model: str,

0 commit comments

Comments
 (0)