返回提交历史
Modified
g4f/Provider/Copilot.py
+47
-47
XFEstudio/gpt4free
Comment out media upload logic in Copilot for debugging purposes
4fddbe70
代码差异
1 个文件
+47
-47
@@ -136,54 +136,54 @@ class Copilot(AsyncAuthedProvider, ProviderModelMixin):
136
136
await asyncio.sleep(3)
137
137
await click_trunstile(page)
138
138
139
uploaded_attachments = []
140
if auth_result.access_token:
141
# Upload regular media (images)
142
for media, _ in merge_media(media, messages):
143
if not isinstance(media, str):
144
data_bytes = to_bytes(media)
145
response_json = await page.evaluate(f'''
146
fetch('https://copilot.microsoft.com/c/api/attachments', {{
147
method: 'POST',
148
headers: {{
149
'content-type': '{is_accepted_format(data_bytes)}',
150
'content-length': '{len(data_bytes)}',
151
"'x-useridentitytype': '{auth_result.useridentitytype}'," if getattr(auth_result, "useridentitytype", None) else ""
152
}},
153
body: new Uint8Array({list(data_bytes)})
154
}}).then(r => r.json())
155
''')
156
media = response_json.get("url")
157
uploaded_attachments.append({{"type":"image", "url": media}})
139
# uploaded_attachments = []
140
# if auth_result.access_token:
141
# # Upload regular media (images)
142
# for media, _ in merge_media(media, messages):
143
# if not isinstance(media, str):
144
# data_bytes = to_bytes(media)
145
# response_json = await page.evaluate(f'''
146
# fetch('https://copilot.microsoft.com/c/api/attachments', {{
147
# method: 'POST',
148
# headers: {{
149
# 'content-type': '{is_accepted_format(data_bytes)}',
150
# 'content-length': '{len(data_bytes)}',
151
# "'x-useridentitytype': '{auth_result.useridentitytype}'," if getattr(auth_result, "useridentitytype", None) else ""
152
# }},
153
# body: new Uint8Array({list(data_bytes)})
154
# }}).then(r => r.json())
155
# ''')
156
# media = response_json.get("url")
157
# uploaded_attachments.append({{"type":"image", "url": media}})
158
158
159
# Upload bucket files
160
bucket_items = extract_bucket_items(messages)
161
for item in bucket_items:
162
try:
163
# Handle plain text content from bucket
164
bucket_path = Path(get_bucket_dir(item["bucket_id"]))
165
for text_chunk in read_bucket(bucket_path):
166
if text_chunk.strip():
167
# Upload plain text as a text file
168
response_json = await page.evaluate(f'''
169
const formData = new FormData();
170
formData.append('file', new Blob(['{text_chunk.replace(chr(39), "\\'").replace(chr(10), "\\n").replace(chr(13), "\\r")}'], {{type: 'text/plain'}}), 'bucket_{item['bucket_id']}.txt');
171
fetch('https://copilot.microsoft.com/c/api/attachments', {{
172
method: 'POST',
173
headers: {{
174
"'x-useridentitytype': '{auth_result.useridentitytype}'," if auth_result.useridentitytype else ""
175
}},
176
body: formData
177
}}).then(r => r.json())
178
''')
179
data = response_json
180
uploaded_attachments.append({{"type": "document", "attachmentId": data.get("id")}})
181
debug.log(f"Copilot: Uploaded bucket text content: {item['bucket_id']}")
182
else:
183
debug.log(f"Copilot: No text content found in bucket: {item['bucket_id']}")
184
except Exception as e:
185
debug.log(f"Copilot: Failed to upload bucket item: {item}")
186
debug.error(e)
159
# # Upload bucket files
160
# bucket_items = extract_bucket_items(messages)
161
# for item in bucket_items:
162
# try:
163
# # Handle plain text content from bucket
164
# bucket_path = Path(get_bucket_dir(item["bucket_id"]))
165
# for text_chunk in read_bucket(bucket_path):
166
# if text_chunk.strip():
167
# # Upload plain text as a text file
168
# response_json = await page.evaluate(f'''
169
# const formData = new FormData();
170
# formData.append('file', new Blob(['{text_chunk.replace(chr(39), "\\'").replace(chr(10), "\\n").replace(chr(13), "\\r")}'], {{type: 'text/plain'}}), 'bucket_{item['bucket_id']}.txt');
171
# fetch('https://copilot.microsoft.com/c/api/attachments', {{
172
# method: 'POST',
173
# headers: {{
174
# "'x-useridentitytype': '{auth_result.useridentitytype}'," if auth_result.useridentitytype else ""
175
# }},
176
# body: formData
177
# }}).then(r => r.json())
178
# ''')
179
# data = response_json
180
# uploaded_attachments.append({{"type": "document", "attachmentId": data.get("id")}})
181
# debug.log(f"Copilot: Uploaded bucket text content: {item['bucket_id']}")
182
# else:
183
# debug.log(f"Copilot: No text content found in bucket: {item['bucket_id']}")
184
# except Exception as e:
185
# debug.log(f"Copilot: Failed to upload bucket item: {item}")
186
# debug.error(e)
187
187
188
188
done = False
189
189
msg = None