Skip to content

Commit efb84df

Browse files
committed
fix:无参工具在某些api报错
1 parent f2aedf7 commit efb84df

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

prompts/zh-CN/maisaka_chat.prompt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2.如果用户有新发言,但是你评估用户还有后续发言尚未发送,可以适当等待让用户说完
2424
3.在特定情况下也可以连续回复,例如想要追问,或者补充自己先前的发言,可以不使用no_reply或者wait
2525
4.你需要控制自己发言的频率,如果用户一对一聊天,可以以均匀地频率发言,如果用户较多,不要每句都回复,控制回复频率。当你决定暂时不发言,可以使用wait暂时等待一定时间或者no_reply等待新消息
26-
5.不要每条消息都回复,不要直接回复别的用户发送的表情包消息,控制回复频率
26+
5.不要每条消息都回复,不要直接回复别的用户发送的表情包消息,控制回复频率,控制你的发言占所有用户的1/10,也就是其他用户10条发言左右你回复一条。
2727
6.如果存在用户的疑问,或者对某些概念的不确定,你可以使用工具来搜集信息或者查询含义,你可以使用多个工具
2828

2929
你的分析规则:

src/llm_models/model_client/openai_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,15 @@ def _convert_tool_options(tool_options: List[ToolOption]) -> List[ChatCompletion
314314
"""
315315
converted_tools: List[ChatCompletionToolParam] = []
316316
for tool_option in tool_options:
317+
parameters_schema = cast(
318+
Dict[str, object],
319+
tool_option.parameters_schema or {"type": "object", "properties": {}},
320+
)
317321
function_schema: FunctionDefinition = {
318322
"name": tool_option.name,
319323
"description": tool_option.description,
324+
"parameters": parameters_schema,
320325
}
321-
parameters_schema = tool_option.parameters_schema
322-
if parameters_schema is not None:
323-
function_schema["parameters"] = cast(Dict[str, object], parameters_schema)
324326
converted_tools.append(
325327
{
326328
"type": "function",

src/llm_models/payload_content/tool_option.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def _build_parameters_schema_from_property_map(property_map: Dict[str, Any]) ->
8888
return parameters_schema
8989

9090

91+
def _build_empty_object_schema() -> Dict[str, Any]:
92+
"""构建无参工具使用的空对象 Schema。"""
93+
94+
return {
95+
"type": "object",
96+
"properties": {},
97+
}
98+
99+
91100
@dataclass(slots=True)
92101
class ToolParam:
93102
"""工具参数定义。"""
@@ -333,9 +342,8 @@ def to_openai_function_schema(self) -> Dict[str, Any]:
333342
function_schema: Dict[str, Any] = {
334343
"name": self.name,
335344
"description": self.description,
345+
"parameters": self.parameters_schema or _build_empty_object_schema(),
336346
}
337-
if self.parameters_schema is not None:
338-
function_schema["parameters"] = self.parameters_schema
339347
return {
340348
"type": "function",
341349
"function": function_schema,

0 commit comments

Comments
 (0)