返回提交历史
Modified
g4f/client/__init__.py
+9
-5
Modified
g4f/client/helper.py
+1
-0
Modified
g4f/requests/__init__.py
+1
-1
XFEstudio/gpt4free
Fix issue with new nodriver version Fix issue with stop parameter
4ae536f1
代码差异
3 个文件
+11
-6
@@ -37,11 +37,10 @@ except NameError:
37
37
raise StopIteration
38
38
39
39
def add_chunk(content, chunk):
40
if content == "":
40
if content == "" and isinstance(chunk, (MediaResponse, AudioResponse)):
41
41
content = chunk
42
42
else:
43
chunk = str(chunk)
44
content = str(content) + chunk
43
content = str(content) + str(chunk)
45
44
return content
46
45
47
46
# Synchronous iter_response function
@@ -57,6 +56,7 @@ def iter_response(
57
56
tool_calls = None
58
57
usage = None
59
58
provider: ProviderInfo = None
59
conversation: JsonConversation = None
60
60
completion_id = ''.join(random.choices(string.ascii_letters + string.digits, k=28))
61
61
idx = 0
62
62
@@ -67,6 +67,9 @@ def iter_response(
67
67
if isinstance(chunk, FinishReason):
68
68
finish_reason = chunk.reason
69
69
break
70
elif isinstance(chunk, JsonConversation):
71
conversation = chunk
72
continue
70
73
elif isinstance(chunk, ToolCalls):
71
74
tool_calls = chunk.get_list()
72
75
continue
@@ -124,7 +127,8 @@ def iter_response(
124
127
content = filter_json(content)
125
128
chat_completion = ChatCompletion.model_construct(
126
129
content, finish_reason, completion_id, int(time.time()), usage=usage,
127
**filter_none(tool_calls=[ToolCallModel.model_construct(**tool_call) for tool_call in tool_calls]) if tool_calls is not None else {}
130
**filter_none(tool_calls=[ToolCallModel.model_construct(**tool_call) for tool_call in tool_calls]) if tool_calls is not None else {},
131
conversation=None if conversation is None else conversation.get_dict()
128
132
)
129
133
if provider is not None:
130
134
chat_completion.provider = provider.name
@@ -460,7 +464,7 @@ class Images:
460
464
urls.extend(item.urls)
461
465
if not urls:
462
466
return None
463
return MediaResponse(urls, items[0].alt)
467
return MediaResponse(urls, items[0].alt, items[0].options)
464
468
465
469
def create_variation(
466
470
self,
@@ -37,6 +37,7 @@ def find_stop(stop: Optional[list[str]], content: str, chunk: str = None):
37
37
first = -1
38
38
word = None
39
39
if stop is not None:
40
content = str(content)
40
41
for word in list(stop):
41
42
first = content.find(word)
42
43
if first != -1:
@@ -103,7 +103,7 @@ async def get_args_from_nodriver(
103
103
else:
104
104
await browser.cookies.set_all(get_cookie_params_from_dict(cookies, url=url, domain=domain))
105
105
page = await browser.get(url)
106
user_agent = await page.evaluate("window.navigator.userAgent")
106
user_agent = str(await page.evaluate("window.navigator.userAgent"))
107
107
await page.wait_for("body:not(.no-js)", timeout=timeout)
108
108
if wait_for is not None:
109
109
await page.wait_for(wait_for, timeout=timeout)