返回提交历史
Modified
g4f/client/__init__.py
+2
-2
Modified
g4f/tools/run_tools.py
+6
-5
XFEstudio/gpt4free
Fix unittests
c9d4c428
代码差异
2 个文件
+8
-7
@@ -41,7 +41,7 @@ def add_chunk(content, chunk):
41
41
content = chunk
42
42
else:
43
43
chunk = str(chunk)
44
content += chunk
44
content = str(content) + chunk
45
45
return content
46
46
47
47
# Synchronous iter_response function
@@ -89,7 +89,7 @@ def iter_response(
89
89
continue
90
90
idx += 1
91
91
92
if max_tokens is not None and idx + 1 >= max_tokens:
92
if max_tokens is not None and idx >= max_tokens:
93
93
finish_reason = "length"
94
94
95
95
first, content, chunk = find_stop(stop, content, chunk if stream else None)
@@ -49,11 +49,11 @@ class ToolHandler:
49
49
"""Process search tool requests"""
50
50
messages = messages.copy()
51
51
args = ToolHandler.validate_arguments(tool["function"])
52
messages[-1]["content"] = await do_search(
52
messages[-1]["content"], sources = await do_search(
53
53
messages[-1]["content"],
54
54
**args
55
55
)
56
return messages
56
return messages, sources
57
57
58
58
@staticmethod
59
59
def process_continue_tool(messages: Messages, tool: dict, provider: Any) -> Tuple[Messages, Dict[str, Any]]:
@@ -100,6 +100,7 @@ class ToolHandler:
100
100
101
101
extra_kwargs = {}
102
102
messages = messages.copy()
103
sources = None
103
104
104
105
for tool in tool_calls:
105
106
if tool.get("type") != "function":
@@ -108,7 +109,7 @@ class ToolHandler:
108
109
function_name = tool.get("function", {}).get("name")
109
110
110
111
if function_name == TOOL_NAMES["SEARCH"]:
111
messages = await ToolHandler.process_search_tool(messages, tool)
112
messages, sources = await ToolHandler.process_search_tool(messages, tool)
112
113
113
114
elif function_name == TOOL_NAMES["CONTINUE"]:
114
115
messages, kwargs = ToolHandler.process_continue_tool(messages, tool, provider)
@@ -117,7 +118,7 @@ class ToolHandler:
117
118
elif function_name == TOOL_NAMES["BUCKET"]:
118
119
messages = ToolHandler.process_bucket_tool(messages, tool)
119
120
120
return messages, extra_kwargs
121
return messages, sources, extra_kwargs
121
122
122
123
123
124
class AuthManager:
@@ -242,7 +243,7 @@ async def async_iter_run_tools(
242
243
243
244
# Process tool calls
244
245
if tool_calls:
245
messages, extra_kwargs = await ToolHandler.process_tools(messages, tool_calls, provider)
246
messages, sources, extra_kwargs = await ToolHandler.process_tools(messages, tool_calls, provider)
246
247
kwargs.update(extra_kwargs)
247
248
248
249
# Generate response