webscout 8.2.8__py3-none-any.whl → 8.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webscout might be problematic. Click here for more details.
- webscout/AIauto.py +34 -16
- webscout/AIbase.py +96 -37
- webscout/AIutel.py +491 -87
- webscout/Bard.py +441 -323
- webscout/Extra/GitToolkit/__init__.py +10 -10
- webscout/Extra/YTToolkit/ytapi/video.py +232 -232
- webscout/Litlogger/README.md +10 -0
- webscout/Litlogger/__init__.py +7 -59
- webscout/Litlogger/formats.py +4 -0
- webscout/Litlogger/handlers.py +103 -0
- webscout/Litlogger/levels.py +13 -0
- webscout/Litlogger/logger.py +92 -0
- webscout/Provider/AISEARCH/Perplexity.py +332 -358
- webscout/Provider/AISEARCH/felo_search.py +9 -35
- webscout/Provider/AISEARCH/genspark_search.py +30 -56
- webscout/Provider/AISEARCH/hika_search.py +4 -16
- webscout/Provider/AISEARCH/iask_search.py +410 -436
- webscout/Provider/AISEARCH/monica_search.py +4 -30
- webscout/Provider/AISEARCH/scira_search.py +6 -32
- webscout/Provider/AISEARCH/webpilotai_search.py +38 -64
- webscout/Provider/Blackboxai.py +155 -35
- webscout/Provider/ChatSandbox.py +2 -1
- webscout/Provider/Deepinfra.py +339 -339
- webscout/Provider/ExaChat.py +358 -358
- webscout/Provider/Gemini.py +169 -169
- webscout/Provider/GithubChat.py +1 -2
- webscout/Provider/Glider.py +3 -3
- webscout/Provider/HeckAI.py +172 -82
- webscout/Provider/LambdaChat.py +1 -0
- webscout/Provider/MCPCore.py +7 -3
- webscout/Provider/OPENAI/BLACKBOXAI.py +421 -139
- webscout/Provider/OPENAI/Cloudflare.py +38 -21
- webscout/Provider/OPENAI/FalconH1.py +457 -0
- webscout/Provider/OPENAI/FreeGemini.py +35 -18
- webscout/Provider/OPENAI/NEMOTRON.py +34 -34
- webscout/Provider/OPENAI/PI.py +427 -0
- webscout/Provider/OPENAI/Qwen3.py +304 -0
- webscout/Provider/OPENAI/README.md +952 -1253
- webscout/Provider/OPENAI/TwoAI.py +374 -0
- webscout/Provider/OPENAI/__init__.py +7 -1
- webscout/Provider/OPENAI/ai4chat.py +73 -63
- webscout/Provider/OPENAI/api.py +869 -644
- webscout/Provider/OPENAI/base.py +2 -0
- webscout/Provider/OPENAI/c4ai.py +34 -13
- webscout/Provider/OPENAI/chatgpt.py +575 -556
- webscout/Provider/OPENAI/chatgptclone.py +512 -487
- webscout/Provider/OPENAI/chatsandbox.py +11 -6
- webscout/Provider/OPENAI/copilot.py +258 -0
- webscout/Provider/OPENAI/deepinfra.py +327 -318
- webscout/Provider/OPENAI/e2b.py +140 -104
- webscout/Provider/OPENAI/exaai.py +420 -411
- webscout/Provider/OPENAI/exachat.py +448 -443
- webscout/Provider/OPENAI/flowith.py +7 -3
- webscout/Provider/OPENAI/freeaichat.py +12 -8
- webscout/Provider/OPENAI/glider.py +15 -8
- webscout/Provider/OPENAI/groq.py +5 -2
- webscout/Provider/OPENAI/heckai.py +311 -307
- webscout/Provider/OPENAI/llmchatco.py +9 -7
- webscout/Provider/OPENAI/mcpcore.py +18 -9
- webscout/Provider/OPENAI/multichat.py +7 -5
- webscout/Provider/OPENAI/netwrck.py +16 -11
- webscout/Provider/OPENAI/oivscode.py +290 -0
- webscout/Provider/OPENAI/opkfc.py +507 -496
- webscout/Provider/OPENAI/pydantic_imports.py +172 -0
- webscout/Provider/OPENAI/scirachat.py +29 -17
- webscout/Provider/OPENAI/sonus.py +308 -303
- webscout/Provider/OPENAI/standardinput.py +442 -433
- webscout/Provider/OPENAI/textpollinations.py +18 -11
- webscout/Provider/OPENAI/toolbaz.py +419 -413
- webscout/Provider/OPENAI/typefully.py +17 -10
- webscout/Provider/OPENAI/typegpt.py +21 -11
- webscout/Provider/OPENAI/uncovrAI.py +477 -462
- webscout/Provider/OPENAI/utils.py +90 -79
- webscout/Provider/OPENAI/venice.py +435 -425
- webscout/Provider/OPENAI/wisecat.py +387 -381
- webscout/Provider/OPENAI/writecream.py +166 -163
- webscout/Provider/OPENAI/x0gpt.py +26 -37
- webscout/Provider/OPENAI/yep.py +384 -356
- webscout/Provider/PI.py +2 -1
- webscout/Provider/TTI/README.md +55 -101
- webscout/Provider/TTI/__init__.py +4 -9
- webscout/Provider/TTI/aiarta.py +365 -0
- webscout/Provider/TTI/artbit.py +0 -0
- webscout/Provider/TTI/base.py +64 -0
- webscout/Provider/TTI/fastflux.py +200 -0
- webscout/Provider/TTI/magicstudio.py +201 -0
- webscout/Provider/TTI/piclumen.py +203 -0
- webscout/Provider/TTI/pixelmuse.py +225 -0
- webscout/Provider/TTI/pollinations.py +221 -0
- webscout/Provider/TTI/utils.py +11 -0
- webscout/Provider/TTS/__init__.py +2 -1
- webscout/Provider/TTS/base.py +159 -159
- webscout/Provider/TTS/openai_fm.py +129 -0
- webscout/Provider/TextPollinationsAI.py +308 -308
- webscout/Provider/TwoAI.py +239 -44
- webscout/Provider/UNFINISHED/Youchat.py +330 -330
- webscout/Provider/UNFINISHED/puterjs.py +635 -0
- webscout/Provider/UNFINISHED/test_lmarena.py +119 -119
- webscout/Provider/Writecream.py +246 -246
- webscout/Provider/__init__.py +2 -2
- webscout/Provider/ai4chat.py +33 -8
- webscout/Provider/granite.py +41 -6
- webscout/Provider/koala.py +169 -169
- webscout/Provider/oivscode.py +309 -0
- webscout/Provider/samurai.py +3 -2
- webscout/Provider/scnet.py +1 -0
- webscout/Provider/typegpt.py +3 -3
- webscout/Provider/uncovr.py +368 -368
- webscout/client.py +70 -0
- webscout/litprinter/__init__.py +58 -58
- webscout/optimizers.py +419 -419
- webscout/scout/README.md +3 -1
- webscout/scout/core/crawler.py +134 -64
- webscout/scout/core/scout.py +148 -109
- webscout/scout/element.py +106 -88
- webscout/swiftcli/Readme.md +323 -323
- webscout/swiftcli/plugins/manager.py +9 -2
- webscout/version.py +1 -1
- webscout/zeroart/__init__.py +134 -134
- webscout/zeroart/effects.py +100 -100
- webscout/zeroart/fonts.py +1238 -1238
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/METADATA +160 -35
- webscout-8.3.dist-info/RECORD +290 -0
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/WHEEL +1 -1
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/entry_points.txt +1 -0
- webscout/Litlogger/Readme.md +0 -175
- webscout/Litlogger/core/__init__.py +0 -6
- webscout/Litlogger/core/level.py +0 -23
- webscout/Litlogger/core/logger.py +0 -165
- webscout/Litlogger/handlers/__init__.py +0 -12
- webscout/Litlogger/handlers/console.py +0 -33
- webscout/Litlogger/handlers/file.py +0 -143
- webscout/Litlogger/handlers/network.py +0 -173
- webscout/Litlogger/styles/__init__.py +0 -7
- webscout/Litlogger/styles/colors.py +0 -249
- webscout/Litlogger/styles/formats.py +0 -458
- webscout/Litlogger/styles/text.py +0 -87
- webscout/Litlogger/utils/__init__.py +0 -6
- webscout/Litlogger/utils/detectors.py +0 -153
- webscout/Litlogger/utils/formatters.py +0 -200
- webscout/Provider/ChatGPTGratis.py +0 -194
- webscout/Provider/TTI/AiForce/README.md +0 -159
- webscout/Provider/TTI/AiForce/__init__.py +0 -22
- webscout/Provider/TTI/AiForce/async_aiforce.py +0 -224
- webscout/Provider/TTI/AiForce/sync_aiforce.py +0 -245
- webscout/Provider/TTI/FreeAIPlayground/README.md +0 -99
- webscout/Provider/TTI/FreeAIPlayground/__init__.py +0 -9
- webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +0 -181
- webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +0 -180
- webscout/Provider/TTI/ImgSys/README.md +0 -174
- webscout/Provider/TTI/ImgSys/__init__.py +0 -23
- webscout/Provider/TTI/ImgSys/async_imgsys.py +0 -202
- webscout/Provider/TTI/ImgSys/sync_imgsys.py +0 -195
- webscout/Provider/TTI/MagicStudio/README.md +0 -101
- webscout/Provider/TTI/MagicStudio/__init__.py +0 -2
- webscout/Provider/TTI/MagicStudio/async_magicstudio.py +0 -111
- webscout/Provider/TTI/MagicStudio/sync_magicstudio.py +0 -109
- webscout/Provider/TTI/Nexra/README.md +0 -155
- webscout/Provider/TTI/Nexra/__init__.py +0 -22
- webscout/Provider/TTI/Nexra/async_nexra.py +0 -286
- webscout/Provider/TTI/Nexra/sync_nexra.py +0 -258
- webscout/Provider/TTI/PollinationsAI/README.md +0 -146
- webscout/Provider/TTI/PollinationsAI/__init__.py +0 -23
- webscout/Provider/TTI/PollinationsAI/async_pollinations.py +0 -311
- webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +0 -265
- webscout/Provider/TTI/aiarta/README.md +0 -134
- webscout/Provider/TTI/aiarta/__init__.py +0 -2
- webscout/Provider/TTI/aiarta/async_aiarta.py +0 -482
- webscout/Provider/TTI/aiarta/sync_aiarta.py +0 -440
- webscout/Provider/TTI/artbit/README.md +0 -100
- webscout/Provider/TTI/artbit/__init__.py +0 -22
- webscout/Provider/TTI/artbit/async_artbit.py +0 -155
- webscout/Provider/TTI/artbit/sync_artbit.py +0 -148
- webscout/Provider/TTI/fastflux/README.md +0 -129
- webscout/Provider/TTI/fastflux/__init__.py +0 -22
- webscout/Provider/TTI/fastflux/async_fastflux.py +0 -261
- webscout/Provider/TTI/fastflux/sync_fastflux.py +0 -252
- webscout/Provider/TTI/huggingface/README.md +0 -114
- webscout/Provider/TTI/huggingface/__init__.py +0 -22
- webscout/Provider/TTI/huggingface/async_huggingface.py +0 -199
- webscout/Provider/TTI/huggingface/sync_huggingface.py +0 -195
- webscout/Provider/TTI/piclumen/README.md +0 -161
- webscout/Provider/TTI/piclumen/__init__.py +0 -23
- webscout/Provider/TTI/piclumen/async_piclumen.py +0 -268
- webscout/Provider/TTI/piclumen/sync_piclumen.py +0 -233
- webscout/Provider/TTI/pixelmuse/README.md +0 -79
- webscout/Provider/TTI/pixelmuse/__init__.py +0 -4
- webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +0 -249
- webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +0 -182
- webscout/Provider/TTI/talkai/README.md +0 -139
- webscout/Provider/TTI/talkai/__init__.py +0 -4
- webscout/Provider/TTI/talkai/async_talkai.py +0 -229
- webscout/Provider/TTI/talkai/sync_talkai.py +0 -207
- webscout/Provider/UNFINISHED/oivscode.py +0 -351
- webscout-8.2.8.dist-info/RECORD +0 -334
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.2.8.dist-info → webscout-8.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
import uuid
|
|
5
|
+
from typing import List, Dict, Optional, Union, Generator, Any
|
|
6
|
+
|
|
7
|
+
from webscout.Provider.OPENAI.base import OpenAICompatibleProvider, BaseChat, BaseCompletions
|
|
8
|
+
from webscout.Provider.OPENAI.utils import (
|
|
9
|
+
ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
|
|
10
|
+
ChatCompletionMessage, CompletionUsage,
|
|
11
|
+
get_last_user_message, get_system_prompt,
|
|
12
|
+
count_tokens
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
class Completions(BaseCompletions):
|
|
16
|
+
def __init__(self, client: 'Qwen3'):
|
|
17
|
+
self._client = client
|
|
18
|
+
|
|
19
|
+
def create(
|
|
20
|
+
self,
|
|
21
|
+
*,
|
|
22
|
+
model: str,
|
|
23
|
+
messages: List[Dict[str, str]],
|
|
24
|
+
max_tokens: Optional[int] = 2048,
|
|
25
|
+
stream: bool = False,
|
|
26
|
+
temperature: Optional[float] = None,
|
|
27
|
+
top_p: Optional[float] = None,
|
|
28
|
+
timeout: Optional[int] = None,
|
|
29
|
+
proxies: Optional[dict] = None,
|
|
30
|
+
**kwargs: Any
|
|
31
|
+
) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
|
|
32
|
+
payload = {
|
|
33
|
+
"data": [
|
|
34
|
+
get_last_user_message(messages),
|
|
35
|
+
{
|
|
36
|
+
"thinking_budget": kwargs.get("thinking_budget", 38),
|
|
37
|
+
"model": self._client.get_model(model),
|
|
38
|
+
"sys_prompt": get_system_prompt(messages)
|
|
39
|
+
},
|
|
40
|
+
None, None
|
|
41
|
+
],
|
|
42
|
+
"event_data": None,
|
|
43
|
+
"fn_index": 13,
|
|
44
|
+
"trigger_id": 31,
|
|
45
|
+
"session_hash": str(uuid.uuid4()).replace('-', '')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
49
|
+
created_time = int(time.time())
|
|
50
|
+
|
|
51
|
+
if stream:
|
|
52
|
+
return self._create_stream(request_id, created_time, model, payload, timeout=timeout, proxies=proxies)
|
|
53
|
+
else:
|
|
54
|
+
return self._create_non_stream(request_id, created_time, model, payload, timeout=timeout, proxies=proxies)
|
|
55
|
+
|
|
56
|
+
def _create_stream(
|
|
57
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any],
|
|
58
|
+
timeout: Optional[int] = None, proxies: Optional[dict] = None
|
|
59
|
+
) -> Generator[ChatCompletionChunk, None, None]:
|
|
60
|
+
original_proxies = self._client.session.proxies.copy()
|
|
61
|
+
if proxies is not None:
|
|
62
|
+
self._client.session.proxies = proxies
|
|
63
|
+
else:
|
|
64
|
+
self._client.session.proxies = {}
|
|
65
|
+
try:
|
|
66
|
+
session = self._client.session
|
|
67
|
+
headers = self._client.headers
|
|
68
|
+
# Step 1: Join the queue
|
|
69
|
+
join_resp = session.post(self._client.api_endpoint, headers=headers, json=payload, timeout=timeout if timeout is not None else self._client.timeout)
|
|
70
|
+
join_resp.raise_for_status()
|
|
71
|
+
event_id = join_resp.json().get('event_id')
|
|
72
|
+
session_hash = payload["session_hash"]
|
|
73
|
+
|
|
74
|
+
# Step 2: Stream data
|
|
75
|
+
params = {'session_hash': session_hash}
|
|
76
|
+
stream_resp = session.get(self._client.url + "/gradio_api/queue/data", headers=self._client.stream_headers, params=params, stream=True, timeout=timeout if timeout is not None else self._client.timeout)
|
|
77
|
+
stream_resp.raise_for_status()
|
|
78
|
+
|
|
79
|
+
# --- New logic to yield all content, tool reasoning, and status, similar to Reasoning class ---
|
|
80
|
+
is_thinking_tag_open = False # True if <think> has been yielded and not yet </think>
|
|
81
|
+
|
|
82
|
+
for line in stream_resp.iter_lines():
|
|
83
|
+
if line:
|
|
84
|
+
decoded_line = line.decode('utf-8')
|
|
85
|
+
if decoded_line.startswith('data: '):
|
|
86
|
+
try:
|
|
87
|
+
json_data = json.loads(decoded_line[6:])
|
|
88
|
+
if json_data.get('msg') == 'process_generating':
|
|
89
|
+
if 'output' in json_data and 'data' in json_data['output'] and len(json_data['output']['data']) > 5:
|
|
90
|
+
updates_list = json_data['output']['data'][5] # This is a list of operations
|
|
91
|
+
for op_details in updates_list:
|
|
92
|
+
action = op_details[0]
|
|
93
|
+
path = op_details[1]
|
|
94
|
+
value = op_details[2]
|
|
95
|
+
|
|
96
|
+
content_to_yield = None
|
|
97
|
+
is_current_op_tool = False
|
|
98
|
+
is_current_op_text = False
|
|
99
|
+
|
|
100
|
+
# Case 1: Adding a new content block (tool or text object)
|
|
101
|
+
if action == "add" and isinstance(value, dict) and "type" in value:
|
|
102
|
+
if len(path) == 4 and path[0] == "value" and path[2] == "content":
|
|
103
|
+
block_type = value.get("type")
|
|
104
|
+
content_to_yield = value.get("content")
|
|
105
|
+
if block_type == "tool":
|
|
106
|
+
is_current_op_tool = True
|
|
107
|
+
elif block_type == "text":
|
|
108
|
+
is_current_op_text = True
|
|
109
|
+
|
|
110
|
+
# Case 2: Appending content string to an existing block
|
|
111
|
+
elif action == "append" and isinstance(value, str):
|
|
112
|
+
if len(path) == 5 and path[0] == "value" and path[2] == "content" and path[4] == "content":
|
|
113
|
+
block_index = path[3] # 0 for tool's content, 1 for text's content
|
|
114
|
+
content_to_yield = value
|
|
115
|
+
if block_index == 0: # Appending to tool's content
|
|
116
|
+
is_current_op_tool = True
|
|
117
|
+
elif block_index == 1: # Appending to text's content
|
|
118
|
+
is_current_op_text = True
|
|
119
|
+
|
|
120
|
+
# Case 3: Tool status update (e.g., "End of Thought")
|
|
121
|
+
elif action == "replace" and len(path) == 6 and \
|
|
122
|
+
path[0] == "value" and path[2] == "content" and \
|
|
123
|
+
path[3] == 0 and path[4] == "options" and path[5] == "status": # path[3]==0 ensures it's the tool block
|
|
124
|
+
if value == "done": # Tool block processing is complete
|
|
125
|
+
if is_thinking_tag_open:
|
|
126
|
+
delta = ChoiceDelta(content="</think>\n\n", role="assistant")
|
|
127
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
128
|
+
is_thinking_tag_open = False
|
|
129
|
+
continue # This operation itself doesn't yield visible content
|
|
130
|
+
|
|
131
|
+
# Yielding logic
|
|
132
|
+
if is_current_op_tool and content_to_yield:
|
|
133
|
+
if not is_thinking_tag_open:
|
|
134
|
+
delta = ChoiceDelta(content="<think>", role="assistant")
|
|
135
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
136
|
+
is_thinking_tag_open = True
|
|
137
|
+
|
|
138
|
+
delta = ChoiceDelta(content=content_to_yield, role="assistant")
|
|
139
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
140
|
+
|
|
141
|
+
elif is_current_op_text and content_to_yield:
|
|
142
|
+
if is_thinking_tag_open: # If text starts, close any open thinking tag
|
|
143
|
+
delta = ChoiceDelta(content="</think>", role="assistant")
|
|
144
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
145
|
+
is_thinking_tag_open = False
|
|
146
|
+
|
|
147
|
+
delta = ChoiceDelta(content=content_to_yield, role="assistant")
|
|
148
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
149
|
+
|
|
150
|
+
if json_data.get('msg') == 'process_completed':
|
|
151
|
+
if is_thinking_tag_open: # Ensure </think> is yielded if process completes mid-thought
|
|
152
|
+
delta = ChoiceDelta(content="</think>", role="assistant")
|
|
153
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
154
|
+
is_thinking_tag_open = False
|
|
155
|
+
break
|
|
156
|
+
except json.JSONDecodeError:
|
|
157
|
+
continue
|
|
158
|
+
except Exception as e:
|
|
159
|
+
# Log or handle other potential exceptions
|
|
160
|
+
continue
|
|
161
|
+
|
|
162
|
+
# After the loop, ensure the tag is closed if the stream broke for reasons other than 'process_completed'
|
|
163
|
+
if is_thinking_tag_open:
|
|
164
|
+
delta = ChoiceDelta(content="</think>", role="assistant")
|
|
165
|
+
yield ChatCompletionChunk(id=request_id, choices=[Choice(index=0, delta=delta)], created=created_time, model=model)
|
|
166
|
+
finally:
|
|
167
|
+
self._client.session.proxies = original_proxies
|
|
168
|
+
|
|
169
|
+
def _create_non_stream(
|
|
170
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any],
|
|
171
|
+
timeout: Optional[int] = None, proxies: Optional[dict] = None
|
|
172
|
+
) -> ChatCompletion:
|
|
173
|
+
original_proxies = self._client.session.proxies.copy()
|
|
174
|
+
if proxies is not None:
|
|
175
|
+
self._client.session.proxies = proxies
|
|
176
|
+
else:
|
|
177
|
+
self._client.session.proxies = {}
|
|
178
|
+
try:
|
|
179
|
+
# For non-streaming, just call the join endpoint and parse the result
|
|
180
|
+
session = self._client.session
|
|
181
|
+
headers = self._client.headers
|
|
182
|
+
resp = session.post(self._client.api_endpoint, headers=headers, json=payload, timeout=timeout if timeout is not None else self._client.timeout)
|
|
183
|
+
resp.raise_for_status()
|
|
184
|
+
data = resp.json()
|
|
185
|
+
# Return the full content as a single message, including all tool and text reasoning if present
|
|
186
|
+
output = ""
|
|
187
|
+
if 'output' in data and 'data' in data['output'] and len(data['output']['data']) > 5:
|
|
188
|
+
updates = data['output']['data'][5]
|
|
189
|
+
parts = []
|
|
190
|
+
for update in updates:
|
|
191
|
+
if isinstance(update, list) and len(update) > 2 and isinstance(update[2], str):
|
|
192
|
+
parts.append(update[2])
|
|
193
|
+
elif isinstance(update, list) and isinstance(update[1], list) and len(update[1]) > 4:
|
|
194
|
+
if update[1][4] == "content":
|
|
195
|
+
parts.append(update[2])
|
|
196
|
+
elif update[1][4] == "options" and update[2] != "done":
|
|
197
|
+
parts.append(str(update[2]))
|
|
198
|
+
elif isinstance(update, dict):
|
|
199
|
+
if update.get('type') == 'tool':
|
|
200
|
+
parts.append(update.get('content', ''))
|
|
201
|
+
elif update.get('type') == 'text':
|
|
202
|
+
parts.append(update.get('content', ''))
|
|
203
|
+
output = "\n".join([str(p) for p in parts if p])
|
|
204
|
+
else:
|
|
205
|
+
output = data.get('output', {}).get('data', ["", "", "", "", "", [["", "", ""]]])[5][0][2]
|
|
206
|
+
message = ChatCompletionMessage(role="assistant", content=output)
|
|
207
|
+
choice = Choice(index=0, message=message, finish_reason="stop")
|
|
208
|
+
# Use count_tokens to compute usage
|
|
209
|
+
prompt_tokens = count_tokens([m.get('content', '') for m in payload['data'] if isinstance(m, dict) and 'content' in m or isinstance(m, str)])
|
|
210
|
+
completion_tokens = count_tokens(output)
|
|
211
|
+
usage = CompletionUsage(
|
|
212
|
+
prompt_tokens=prompt_tokens,
|
|
213
|
+
completion_tokens=completion_tokens,
|
|
214
|
+
total_tokens=prompt_tokens + completion_tokens
|
|
215
|
+
)
|
|
216
|
+
completion = ChatCompletion(
|
|
217
|
+
id=request_id,
|
|
218
|
+
choices=[choice],
|
|
219
|
+
created=created_time,
|
|
220
|
+
model=model,
|
|
221
|
+
usage=usage,
|
|
222
|
+
)
|
|
223
|
+
return completion
|
|
224
|
+
finally:
|
|
225
|
+
self._client.session.proxies = original_proxies
|
|
226
|
+
|
|
227
|
+
class Chat(BaseChat):
|
|
228
|
+
def __init__(self, client: 'Qwen3'):
|
|
229
|
+
self.completions = Completions(client)
|
|
230
|
+
|
|
231
|
+
class Qwen3(OpenAICompatibleProvider):
|
|
232
|
+
url = "https://qwen-qwen3-demo.hf.space"
|
|
233
|
+
api_endpoint = "https://qwen-qwen3-demo.hf.space/gradio_api/queue/join?__theme=system"
|
|
234
|
+
AVAILABLE_MODELS = [
|
|
235
|
+
"qwen3-235b-a22b",
|
|
236
|
+
"qwen3-32b",
|
|
237
|
+
"qwen3-30b-a3b",
|
|
238
|
+
"qwen3-14b",
|
|
239
|
+
"qwen3-8b",
|
|
240
|
+
"qwen3-4b",
|
|
241
|
+
"qwen3-1.7b",
|
|
242
|
+
"qwen3-0.6b",
|
|
243
|
+
]
|
|
244
|
+
MODEL_ALIASES = {
|
|
245
|
+
"qwen-3-235b": "qwen3-235b-a22b",
|
|
246
|
+
"qwen-3-30b": "qwen3-30b-a3b",
|
|
247
|
+
"qwen-3-32b": "qwen3-32b",
|
|
248
|
+
"qwen-3-14b": "qwen3-14b",
|
|
249
|
+
"qwen-3-4b": "qwen3-4b",
|
|
250
|
+
"qwen-3-1.7b": "qwen3-1.7b",
|
|
251
|
+
"qwen-3-0.6b": "qwen3-0.6b"
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
def __init__(self):
|
|
255
|
+
self.timeout = 30
|
|
256
|
+
self.session = requests.Session()
|
|
257
|
+
self.session.proxies = {}
|
|
258
|
+
self.headers = {
|
|
259
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0',
|
|
260
|
+
'Accept': '*/*',
|
|
261
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
262
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
263
|
+
'Referer': f'{self.url}/?__theme=system',
|
|
264
|
+
'content-type': 'application/json',
|
|
265
|
+
'Origin': self.url,
|
|
266
|
+
'Connection': 'keep-alive',
|
|
267
|
+
'Sec-Fetch-Dest': 'empty',
|
|
268
|
+
'Sec-Fetch-Mode': 'cors',
|
|
269
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
270
|
+
'Pragma': 'no-cache',
|
|
271
|
+
'Cache-Control': 'no-cache',
|
|
272
|
+
}
|
|
273
|
+
self.stream_headers = {
|
|
274
|
+
'Accept': 'text/event-stream',
|
|
275
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
276
|
+
'Referer': f'{self.url}/?__theme=system',
|
|
277
|
+
'User-Agent': self.headers['User-Agent'],
|
|
278
|
+
}
|
|
279
|
+
self.session.headers.update(self.headers)
|
|
280
|
+
self.chat = Chat(self)
|
|
281
|
+
|
|
282
|
+
def get_model(self, model):
|
|
283
|
+
return self.MODEL_ALIASES.get(model, model)
|
|
284
|
+
|
|
285
|
+
@property
|
|
286
|
+
def models(self):
|
|
287
|
+
class _ModelList:
|
|
288
|
+
def list(inner_self):
|
|
289
|
+
return type(self).AVAILABLE_MODELS
|
|
290
|
+
return _ModelList()
|
|
291
|
+
|
|
292
|
+
if __name__ == "__main__":
|
|
293
|
+
client = Qwen3()
|
|
294
|
+
from rich import print
|
|
295
|
+
resp = client.chat.completions.create(
|
|
296
|
+
model="qwen3-14b",
|
|
297
|
+
messages=[
|
|
298
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
299
|
+
{"role": "user", "content": "Hello "}
|
|
300
|
+
],
|
|
301
|
+
stream=True
|
|
302
|
+
)
|
|
303
|
+
for chunk in resp:
|
|
304
|
+
print(chunk, end="", flush=True)
|