fix:无参工具在某些api报错
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
2.如果用户有新发言,但是你评估用户还有后续发言尚未发送,可以适当等待让用户说完
|
||||
3.在特定情况下也可以连续回复,例如想要追问,或者补充自己先前的发言,可以不使用no_reply或者wait
|
||||
4.你需要控制自己发言的频率,如果用户一对一聊天,可以以均匀地频率发言,如果用户较多,不要每句都回复,控制回复频率。当你决定暂时不发言,可以使用wait暂时等待一定时间或者no_reply等待新消息
|
||||
5.不要每条消息都回复,不要直接回复别的用户发送的表情包消息,控制回复频率
|
||||
5.不要每条消息都回复,不要直接回复别的用户发送的表情包消息,控制回复频率,控制你的发言占所有用户的1/10,也就是其他用户10条发言左右你回复一条。
|
||||
6.如果存在用户的疑问,或者对某些概念的不确定,你可以使用工具来搜集信息或者查询含义,你可以使用多个工具
|
||||
|
||||
你的分析规则:
|
||||
|
||||
@@ -314,13 +314,15 @@ def _convert_tool_options(tool_options: List[ToolOption]) -> List[ChatCompletion
|
||||
"""
|
||||
converted_tools: List[ChatCompletionToolParam] = []
|
||||
for tool_option in tool_options:
|
||||
parameters_schema = cast(
|
||||
Dict[str, object],
|
||||
tool_option.parameters_schema or {"type": "object", "properties": {}},
|
||||
)
|
||||
function_schema: FunctionDefinition = {
|
||||
"name": tool_option.name,
|
||||
"description": tool_option.description,
|
||||
"parameters": parameters_schema,
|
||||
}
|
||||
parameters_schema = tool_option.parameters_schema
|
||||
if parameters_schema is not None:
|
||||
function_schema["parameters"] = cast(Dict[str, object], parameters_schema)
|
||||
converted_tools.append(
|
||||
{
|
||||
"type": "function",
|
||||
|
||||
@@ -88,6 +88,15 @@ def _build_parameters_schema_from_property_map(property_map: Dict[str, Any]) ->
|
||||
return parameters_schema
|
||||
|
||||
|
||||
def _build_empty_object_schema() -> Dict[str, Any]:
|
||||
"""构建无参工具使用的空对象 Schema。"""
|
||||
|
||||
return {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
}
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class ToolParam:
|
||||
"""工具参数定义。"""
|
||||
@@ -333,9 +342,8 @@ class ToolOption:
|
||||
function_schema: Dict[str, Any] = {
|
||||
"name": self.name,
|
||||
"description": self.description,
|
||||
"parameters": self.parameters_schema or _build_empty_object_schema(),
|
||||
}
|
||||
if self.parameters_schema is not None:
|
||||
function_schema["parameters"] = self.parameters_schema
|
||||
return {
|
||||
"type": "function",
|
||||
"function": function_schema,
|
||||
|
||||
Reference in New Issue
Block a user