mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-07-21 04:22:16 +08:00
if role is tool then set to user
This commit is contained in:
@@ -36,10 +36,17 @@ class OpenAIMessageConverter(MessageConverter):
|
||||
converted_messages = []
|
||||
system_instruction = None
|
||||
|
||||
for msg in messages:
|
||||
for idx, msg in enumerate(messages):
|
||||
role = msg.get("role", "")
|
||||
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 = []
|
||||
if isinstance(msg["content"], str) and msg["content"]:
|
||||
|
||||
@@ -57,7 +57,14 @@ def _build_tools(
|
||||
function_declarations.append(function)
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user