Skip to content

Commit

Permalink
fixes issue #1011.
Browse files Browse the repository at this point in the history
  • Loading branch information
liminma committed Feb 21, 2025
1 parent 9c79c45 commit 86c33f9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion autogen/oai/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def create(self, params: dict) -> ChatCompletion:
messages = params.get("messages", [])
stream = params.get("stream", False)
n_response = params.get("n", 1)
system_instruction = params.get("system_instruction")
system_instruction = self._extract_system_instruction(messages)
response_validation = params.get("response_validation", True)
tools = self._tools_to_gemini_tools(params["tools"]) if "tools" in params else None

Expand Down Expand Up @@ -375,6 +375,16 @@ def create(self, params: dict) -> ChatCompletion:

return response_oai

def _extract_system_instruction(self, messages: list[dict]) -> str | None:
"""Extract system instruction if provided."""
if messages is None or len(messages) == 0 or messages[0]["role"] != "system":
return None

message = messages.pop(0)
content = message["content"].strip()
content = content if len(content) > 0 else None
return content

def _oai_content_to_gemini_content(self, message: dict[str, Any]) -> tuple[list[Any], str]:
"""Convert AG2 content to Gemini parts, catering for text and tool calls"""
rst = []
Expand Down

0 comments on commit 86c33f9

Please sign in to comment.