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

XFEstudio/gpt4free

Update Qwen_Qwen_3.py

This PR addresses an issue where some text type updates from the process_generating stream were not being yielded, resulting in missing output content. Root Cause update[2] blocks with type: "text" were not handled unless embedded in certain paths. As a result, standalone or final text entries were silently ignored during streaming. Solution Added explicit handling for type: "text" updates.

376c0fdb
Sreejith BR <164229190+SreejiBR@users.noreply.github.com>
提交于

代码差异

1 个文件 +20 -13
Modified g4f/Provider/hf_space/Qwen_Qwen_3.py +20 -13
@@ -10,11 +10,12 @@ from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
10 10 from ..helper import get_last_user_message
11 11 from ... import debug
12 12
13
13 14 class Qwen_Qwen_3(AsyncGeneratorProvider, ProviderModelMixin):
14 15 label = "Qwen Qwen-3"
15 16 url = "https://qwen-qwen3-demo.hf.space"
16 17 api_endpoint = "https://qwen-qwen3-demo.hf.space/gradio_api/queue/join?__theme=system"
17
18
18 19 working = True
19 20 supports_stream = True
20 21 supports_system_message = True
@@ -34,13 +35,13 @@ class Qwen_Qwen_3(AsyncGeneratorProvider, ProviderModelMixin):
34 35
35 36 @classmethod
36 37 async def create_async_generator(
37 cls,
38 model: str,
39 messages: Messages,
40 proxy: str = None,
41 conversation: JsonConversation = None,
42 thinking_budget: int = 38,
43 **kwargs
38 cls,
39 model: str,
40 messages: Messages,
41 proxy: str = None,
42 conversation: JsonConversation = None,
43 thinking_budget: int = 38,
44 **kwargs
44 45 ) -> AsyncResult:
45 46 if conversation is None:
46 47 conversation = JsonConversation(session_hash=str(uuid.uuid4()).replace('-', ''))
@@ -64,10 +65,10 @@ class Qwen_Qwen_3(AsyncGeneratorProvider, ProviderModelMixin):
64 65 sys_prompt = "\n".join([message['content'] for message in messages if message['role'] == 'system'])
65 66 sys_prompt = sys_prompt if sys_prompt else "You are a helpful and harmless assistant."
66 67
67 payload_join = {"data":[
68 payload_join = {"data": [
68 69 get_last_user_message(messages),
69 70 {"thinking_budget": thinking_budget, "model": cls.get_model(model), "sys_prompt": sys_prompt}, None, None],
70 "event_data":None,"fn_index":13,"trigger_id":31,"session_hash":conversation.session_hash
71 "event_data": None, "fn_index": 13, "trigger_id": 31, "session_hash": conversation.session_hash
71 72 }
72 73
73 74 async with aiohttp.ClientSession() as session:
@@ -100,14 +101,20 @@ class Qwen_Qwen_3(AsyncGeneratorProvider, ProviderModelMixin):
100 101
101 102 # Look for generation stages
102 103 if json_data.get('msg') == 'process_generating':
103 if 'output' in json_data and 'data' in json_data['output'] and len(json_data['output']['data']) > 5:
104 if 'output' in json_data and 'data' in json_data['output'] and len(
105 json_data['output']['data']) > 5:
104 106 updates = json_data['output']['data'][5]
105 107 for update in updates:
106 108 if isinstance(update[2], dict):
107 109 if update[2].get('type') == 'tool':
108 yield Reasoning(update[2].get('content'), status=update[2].get('options', {}).get('title'))
110 yield Reasoning(update[2].get('content'),
111 status=update[2].get('options', {}).get('title'))
109 112 is_thinking = True
110 elif isinstance(update, list) and isinstance(update[1], list) and len(update[1]) > 4:
113 elif update[2].get('type') == 'text':
114 yield Reasoning(update[2].get('content'))
115 is_thinking = False
116 elif isinstance(update, list) and isinstance(update[1], list) and len(
117 update[1]) > 4:
111 118 if update[1][4] == "content":
112 119 yield Reasoning(update[2]) if is_thinking else update[2]
113 120 elif update[1][4] == "options":