mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-06 16:16:37 +08:00
if role is tool then set to user
This commit is contained in:
@@ -36,10 +36,17 @@ class OpenAIMessageConverter(MessageConverter):
|
|||||||
converted_messages = []
|
converted_messages = []
|
||||||
system_instruction = None
|
system_instruction = None
|
||||||
|
|
||||||
for msg in messages:
|
for idx, msg in enumerate(messages):
|
||||||
role = msg.get("role", "")
|
role = msg.get("role", "")
|
||||||
if role not in SUPPORTED_ROLES:
|
if role not in SUPPORTED_ROLES:
|
||||||
role = "model"
|
if role == "tool":
|
||||||
|
role = "user"
|
||||||
|
else:
|
||||||
|
# 如果是最后一条消息,则认为是用户消息
|
||||||
|
if idx == len(messages) - 1:
|
||||||
|
role = "user"
|
||||||
|
else:
|
||||||
|
role = "model"
|
||||||
|
|
||||||
parts = []
|
parts = []
|
||||||
if isinstance(msg["content"], str) and msg["content"]:
|
if isinstance(msg["content"], str) and msg["content"]:
|
||||||
|
|||||||
@@ -57,7 +57,14 @@ def _build_tools(
|
|||||||
function_declarations.append(function)
|
function_declarations.append(function)
|
||||||
|
|
||||||
if function_declarations:
|
if function_declarations:
|
||||||
tools.append({"functionDeclarations": function_declarations})
|
# 按照 function 的 name 去重
|
||||||
|
names, functions = set(), []
|
||||||
|
for item in function_declarations:
|
||||||
|
if item.get("name") not in names:
|
||||||
|
names.add(item.get("name"))
|
||||||
|
functions.append(item)
|
||||||
|
|
||||||
|
tools.append({"functionDeclarations": functions})
|
||||||
|
|
||||||
return tools
|
return tools
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user