XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix Qwen provider implementation (#3322)

* Fix Qwen provider implementation - Re-enable cookie generation for authentication - Update User-Agent header to latest version - Fix Authorization header to only be added when token is present - Add X-Requested-With and X-Source headers for proper API communication - Force stream and incremental_output to True for consistent streaming behavior - Set parent_id to None to prevent parent-child relationship issues - Add conditional thinking functionality with proper feature_config when enable_thinking is True - Improve header management for better compatibility with Qwen API Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * Restore parent_id in Qwen provider for conversation support --------- Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

76d8dc20
Moises Tohias <48728934+moisestohias@users.noreply.github.com>
提交于

代码差异

1 个文件 +13 -11
Modified g4f/Provider/Qwen.py +13 -11
@@ -336,7 +336,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
336 336 prompt = get_last_user_message(messages)
337 337 timeout = kwargs.get("timeout") or 5 * 60
338 338 # for _ in range(2):
339 # data = generate_cookies()
339 data = generate_cookies()
340 340 # args,ua = await cls.get_args(proxy, **kwargs)
341 341 headers = {
342 342 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
@@ -349,10 +349,12 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
349 349 'Sec-Fetch-Mode': 'cors',
350 350 'Sec-Fetch-Site': 'same-origin',
351 351 'Connection': 'keep-alive',
352 # 'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
353 'Authorization': f'Bearer {token}' if token else "Bearer",
354 'Source': 'web'
352 'X-Requested-With': 'XMLHttpRequest',
353 'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
354 'X-Source': 'web'
355 355 }
356 if token:
357 headers['Authorization'] = f'Bearer {token}'
356 358
357 359 # try:
358 360 async with StreamSession(headers=headers) as session:
@@ -435,16 +437,16 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
435 437 "output_schema": "phase",
436 438 "thinking_budget": 81920
437 439 },
438 "extra": {
439 "meta": {
440 "subChatType": chat_type
441 }
442 },
443 "sub_chat_type": chat_type,
444 "parent_id": None
440 "sub_chat_type": chat_type
445 441 }
446 442 ]
447 443 }
444 if enable_thinking:
445 msg_payload["messages"][0]["feature_config"] = {
446 "thinking_enabled": True,
447 "output_schema": "phase",
448 "thinking_budget": 81920
449 }
448 450 if aspect_ratio:
449 451 msg_payload["size"] = aspect_ratio
450 452