mirror of
https://github.com/xtekky/gpt4free.git
synced 2026-01-20 19:41:22 -08:00
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>
This commit is contained in:
parent
10a24f5de9
commit
76d8dc20e5
1 changed files with 13 additions and 11 deletions
|
|
@ -336,7 +336,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
prompt = get_last_user_message(messages)
|
||||
timeout = kwargs.get("timeout") or 5 * 60
|
||||
# for _ in range(2):
|
||||
# data = generate_cookies()
|
||||
data = generate_cookies()
|
||||
# args,ua = await cls.get_args(proxy, **kwargs)
|
||||
headers = {
|
||||
'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):
|
|||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Connection': 'keep-alive',
|
||||
# 'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
|
||||
'Authorization': f'Bearer {token}' if token else "Bearer",
|
||||
'Source': 'web'
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
|
||||
'X-Source': 'web'
|
||||
}
|
||||
if token:
|
||||
headers['Authorization'] = f'Bearer {token}'
|
||||
|
||||
# try:
|
||||
async with StreamSession(headers=headers) as session:
|
||||
|
|
@ -435,16 +437,16 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
"output_schema": "phase",
|
||||
"thinking_budget": 81920
|
||||
},
|
||||
"extra": {
|
||||
"meta": {
|
||||
"subChatType": chat_type
|
||||
}
|
||||
},
|
||||
"sub_chat_type": chat_type,
|
||||
"parent_id": None
|
||||
"sub_chat_type": chat_type
|
||||
}
|
||||
]
|
||||
}
|
||||
if enable_thinking:
|
||||
msg_payload["messages"][0]["feature_config"] = {
|
||||
"thinking_enabled": True,
|
||||
"output_schema": "phase",
|
||||
"thinking_budget": 81920
|
||||
}
|
||||
if aspect_ratio:
|
||||
msg_payload["size"] = aspect_ratio
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue