webscout 8.2.8__py3-none-any.whl → 8.2.9__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.
- webscout/AIauto.py +32 -14
- 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 +153 -35
- 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 +171 -81
- webscout/Provider/OPENAI/BLACKBOXAI.py +766 -735
- webscout/Provider/OPENAI/Cloudflare.py +7 -7
- webscout/Provider/OPENAI/FreeGemini.py +6 -5
- webscout/Provider/OPENAI/NEMOTRON.py +8 -20
- webscout/Provider/OPENAI/Qwen3.py +283 -0
- webscout/Provider/OPENAI/README.md +952 -1253
- webscout/Provider/OPENAI/TwoAI.py +357 -0
- webscout/Provider/OPENAI/__init__.py +5 -1
- webscout/Provider/OPENAI/ai4chat.py +40 -40
- webscout/Provider/OPENAI/api.py +808 -649
- webscout/Provider/OPENAI/c4ai.py +3 -3
- webscout/Provider/OPENAI/chatgpt.py +555 -555
- webscout/Provider/OPENAI/chatgptclone.py +493 -487
- webscout/Provider/OPENAI/chatsandbox.py +4 -3
- webscout/Provider/OPENAI/copilot.py +242 -0
- webscout/Provider/OPENAI/deepinfra.py +5 -2
- webscout/Provider/OPENAI/e2b.py +63 -5
- webscout/Provider/OPENAI/exaai.py +416 -410
- webscout/Provider/OPENAI/exachat.py +444 -443
- webscout/Provider/OPENAI/freeaichat.py +2 -2
- webscout/Provider/OPENAI/glider.py +5 -2
- webscout/Provider/OPENAI/groq.py +5 -2
- webscout/Provider/OPENAI/heckai.py +308 -307
- webscout/Provider/OPENAI/mcpcore.py +8 -2
- webscout/Provider/OPENAI/multichat.py +4 -4
- webscout/Provider/OPENAI/netwrck.py +6 -5
- webscout/Provider/OPENAI/oivscode.py +287 -0
- webscout/Provider/OPENAI/opkfc.py +496 -496
- webscout/Provider/OPENAI/pydantic_imports.py +172 -0
- webscout/Provider/OPENAI/scirachat.py +15 -9
- webscout/Provider/OPENAI/sonus.py +304 -303
- webscout/Provider/OPENAI/standardinput.py +433 -433
- webscout/Provider/OPENAI/textpollinations.py +4 -4
- webscout/Provider/OPENAI/toolbaz.py +413 -413
- webscout/Provider/OPENAI/typefully.py +3 -3
- webscout/Provider/OPENAI/typegpt.py +11 -5
- webscout/Provider/OPENAI/uncovrAI.py +463 -462
- webscout/Provider/OPENAI/utils.py +90 -79
- webscout/Provider/OPENAI/venice.py +431 -425
- webscout/Provider/OPENAI/wisecat.py +387 -381
- webscout/Provider/OPENAI/writecream.py +3 -3
- webscout/Provider/OPENAI/x0gpt.py +365 -378
- webscout/Provider/OPENAI/yep.py +39 -13
- 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 -0
- webscout/Provider/ai4chat.py +33 -8
- webscout/Provider/koala.py +169 -169
- webscout/Provider/oivscode.py +309 -0
- webscout/Provider/samurai.py +3 -2
- 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.2.9.dist-info}/METADATA +159 -35
- {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/RECORD +116 -161
- {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/WHEEL +1 -1
- {webscout-8.2.8.dist-info → webscout-8.2.9.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/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 → webscout-8.2.9.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/top_level.txt +0 -0
|
@@ -9,7 +9,7 @@ from .base import OpenAICompatibleProvider, BaseChat, BaseCompletions
|
|
|
9
9
|
from .utils import (
|
|
10
10
|
ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
|
|
11
11
|
ChatCompletionMessage, CompletionUsage,
|
|
12
|
-
format_prompt
|
|
12
|
+
format_prompt, count_tokens
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
# Import curl_cffi for Cloudflare bypass
|
|
@@ -154,9 +154,9 @@ class Completions(BaseCompletions):
|
|
|
154
154
|
message = ChatCompletionMessage(role="assistant", content=response_text)
|
|
155
155
|
choice = Choice(index=0, message=message, finish_reason="stop")
|
|
156
156
|
|
|
157
|
-
# Estimate token usage
|
|
158
|
-
prompt_tokens =
|
|
159
|
-
completion_tokens =
|
|
157
|
+
# Estimate token usage using count_tokens
|
|
158
|
+
prompt_tokens = count_tokens(user_message)
|
|
159
|
+
completion_tokens = count_tokens(response_text)
|
|
160
160
|
total_tokens = prompt_tokens + completion_tokens
|
|
161
161
|
|
|
162
162
|
usage = CompletionUsage(
|
|
@@ -15,7 +15,8 @@ from .utils import (
|
|
|
15
15
|
ChoiceDelta,
|
|
16
16
|
CompletionUsage,
|
|
17
17
|
format_prompt,
|
|
18
|
-
get_system_prompt
|
|
18
|
+
get_system_prompt,
|
|
19
|
+
count_tokens
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
# ANSI escape codes for formatting
|
|
@@ -91,7 +92,7 @@ class Completions(BaseCompletions):
|
|
|
91
92
|
# Format the decoded line using the client's formatter
|
|
92
93
|
formatted_content = self._client.format_text(decoded_line)
|
|
93
94
|
streaming_text += formatted_content
|
|
94
|
-
completion_tokens +=
|
|
95
|
+
completion_tokens += count_tokens(formatted_content)
|
|
95
96
|
|
|
96
97
|
# Create a delta object for this chunk
|
|
97
98
|
delta = ChoiceDelta(content=formatted_content)
|
|
@@ -142,9 +143,9 @@ class Completions(BaseCompletions):
|
|
|
142
143
|
# Format the full response using the client's formatter
|
|
143
144
|
full_response = self._client.format_text(raw_response)
|
|
144
145
|
|
|
145
|
-
# Create usage statistics
|
|
146
|
-
prompt_tokens =
|
|
147
|
-
completion_tokens =
|
|
146
|
+
# Create usage statistics using count_tokens
|
|
147
|
+
prompt_tokens = count_tokens(payload.get("query", ""))
|
|
148
|
+
completion_tokens = count_tokens(full_response)
|
|
148
149
|
total_tokens = prompt_tokens + completion_tokens
|
|
149
150
|
|
|
150
151
|
usage = CompletionUsage(
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import secrets
|
|
3
|
+
import requests
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
import uuid
|
|
7
|
+
import string
|
|
8
|
+
from typing import List, Dict, Optional, Union, Generator, Any
|
|
9
|
+
|
|
10
|
+
# Import base classes and utility structures
|
|
11
|
+
from webscout.Provider.OPENAI.base import OpenAICompatibleProvider, BaseChat, BaseCompletions
|
|
12
|
+
from webscout.Provider.OPENAI.utils import (
|
|
13
|
+
ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
|
|
14
|
+
ChatCompletionMessage, CompletionUsage
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
# --- oivscode Client ---
|
|
18
|
+
|
|
19
|
+
class Completions(BaseCompletions):
|
|
20
|
+
def __init__(self, client: 'oivscode'):
|
|
21
|
+
self._client = client
|
|
22
|
+
|
|
23
|
+
def create(
|
|
24
|
+
self,
|
|
25
|
+
*,
|
|
26
|
+
model: str,
|
|
27
|
+
messages: List[Dict[str, str]],
|
|
28
|
+
max_tokens: Optional[int] = 2049,
|
|
29
|
+
stream: bool = False,
|
|
30
|
+
temperature: Optional[float] = None,
|
|
31
|
+
top_p: Optional[float] = None,
|
|
32
|
+
**kwargs: Any
|
|
33
|
+
) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
|
|
34
|
+
"""
|
|
35
|
+
Creates a model response for the given chat conversation.
|
|
36
|
+
Mimics openai.chat.completions.create
|
|
37
|
+
"""
|
|
38
|
+
payload = {
|
|
39
|
+
"model": model,
|
|
40
|
+
"messages": messages,
|
|
41
|
+
"max_tokens": max_tokens,
|
|
42
|
+
"stream": stream,
|
|
43
|
+
}
|
|
44
|
+
if temperature is not None:
|
|
45
|
+
payload["temperature"] = temperature
|
|
46
|
+
if top_p is not None:
|
|
47
|
+
payload["top_p"] = top_p
|
|
48
|
+
|
|
49
|
+
payload.update(kwargs)
|
|
50
|
+
|
|
51
|
+
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
52
|
+
created_time = int(time.time())
|
|
53
|
+
|
|
54
|
+
if stream:
|
|
55
|
+
return self._create_stream(request_id, created_time, model, payload)
|
|
56
|
+
else:
|
|
57
|
+
return self._create_non_stream(request_id, created_time, model, payload)
|
|
58
|
+
|
|
59
|
+
def _post_with_retry(self, payload, stream=False):
|
|
60
|
+
"""
|
|
61
|
+
Try all endpoints until one succeeds or all fail.
|
|
62
|
+
"""
|
|
63
|
+
last_exception = None
|
|
64
|
+
for endpoint in self._client.api_endpoints:
|
|
65
|
+
try:
|
|
66
|
+
response = self._client.session.post(
|
|
67
|
+
endpoint,
|
|
68
|
+
headers=self._client.headers,
|
|
69
|
+
json=payload,
|
|
70
|
+
stream=stream,
|
|
71
|
+
timeout=self._client.timeout
|
|
72
|
+
)
|
|
73
|
+
response.raise_for_status()
|
|
74
|
+
self._client.base_url = endpoint # Update to working endpoint
|
|
75
|
+
return response
|
|
76
|
+
except requests.exceptions.RequestException as e:
|
|
77
|
+
last_exception = e
|
|
78
|
+
continue
|
|
79
|
+
raise IOError(f"All oivscode endpoints failed: {last_exception}") from last_exception
|
|
80
|
+
|
|
81
|
+
def _create_stream(
|
|
82
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any]
|
|
83
|
+
) -> Generator[ChatCompletionChunk, None, None]:
|
|
84
|
+
try:
|
|
85
|
+
response = self._post_with_retry(payload, stream=True)
|
|
86
|
+
prompt_tokens = 0
|
|
87
|
+
completion_tokens = 0
|
|
88
|
+
total_tokens = 0
|
|
89
|
+
|
|
90
|
+
for line in response.iter_lines():
|
|
91
|
+
if line:
|
|
92
|
+
decoded_line = line.decode('utf-8').strip()
|
|
93
|
+
|
|
94
|
+
if decoded_line.startswith("data: "):
|
|
95
|
+
json_str = decoded_line[6:]
|
|
96
|
+
if json_str == "[DONE]":
|
|
97
|
+
break
|
|
98
|
+
try:
|
|
99
|
+
data = json.loads(json_str)
|
|
100
|
+
choice_data = data.get('choices', [{}])[0]
|
|
101
|
+
delta_data = choice_data.get('delta', {})
|
|
102
|
+
finish_reason = choice_data.get('finish_reason')
|
|
103
|
+
|
|
104
|
+
usage_data = data.get('usage', {})
|
|
105
|
+
if usage_data:
|
|
106
|
+
prompt_tokens = usage_data.get('prompt_tokens', prompt_tokens)
|
|
107
|
+
completion_tokens = usage_data.get('completion_tokens', completion_tokens)
|
|
108
|
+
total_tokens = usage_data.get('total_tokens', total_tokens)
|
|
109
|
+
|
|
110
|
+
delta = ChoiceDelta(
|
|
111
|
+
content=delta_data.get('content'),
|
|
112
|
+
role=delta_data.get('role'),
|
|
113
|
+
tool_calls=delta_data.get('tool_calls')
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
choice = Choice(
|
|
117
|
+
index=choice_data.get('index', 0),
|
|
118
|
+
delta=delta,
|
|
119
|
+
finish_reason=finish_reason,
|
|
120
|
+
logprobs=choice_data.get('logprobs')
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
chunk = ChatCompletionChunk(
|
|
124
|
+
id=request_id,
|
|
125
|
+
choices=[choice],
|
|
126
|
+
created=created_time,
|
|
127
|
+
model=model,
|
|
128
|
+
system_fingerprint=data.get('system_fingerprint')
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
if hasattr(chunk, "model_dump"):
|
|
132
|
+
chunk_dict = chunk.model_dump(exclude_none=True)
|
|
133
|
+
else:
|
|
134
|
+
chunk_dict = chunk.dict(exclude_none=True)
|
|
135
|
+
|
|
136
|
+
usage_dict = {
|
|
137
|
+
"prompt_tokens": prompt_tokens or 10,
|
|
138
|
+
"completion_tokens": completion_tokens or (len(delta_data.get('content', '')) if delta_data.get('content') else 0),
|
|
139
|
+
"total_tokens": total_tokens or (10 + (len(delta_data.get('content', '')) if delta_data.get('content') else 0)),
|
|
140
|
+
"estimated_cost": None
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if delta_data.get('content'):
|
|
144
|
+
completion_tokens += 1
|
|
145
|
+
total_tokens = prompt_tokens + completion_tokens
|
|
146
|
+
usage_dict["completion_tokens"] = completion_tokens
|
|
147
|
+
usage_dict["total_tokens"] = total_tokens
|
|
148
|
+
|
|
149
|
+
chunk_dict["usage"] = usage_dict
|
|
150
|
+
|
|
151
|
+
yield chunk
|
|
152
|
+
except json.JSONDecodeError:
|
|
153
|
+
print(f"Warning: Could not decode JSON line: {json_str}")
|
|
154
|
+
continue
|
|
155
|
+
except requests.exceptions.RequestException as e:
|
|
156
|
+
print(f"Error during oivscode stream request: {e}")
|
|
157
|
+
raise IOError(f"oivscode request failed: {e}") from e
|
|
158
|
+
except Exception as e:
|
|
159
|
+
print(f"Error processing oivscode stream: {e}")
|
|
160
|
+
raise
|
|
161
|
+
|
|
162
|
+
def _create_non_stream(
|
|
163
|
+
self, request_id: str, created_time: int, model: str, payload: Dict[str, Any]
|
|
164
|
+
) -> ChatCompletion:
|
|
165
|
+
try:
|
|
166
|
+
response = self._post_with_retry(payload, stream=False)
|
|
167
|
+
data = response.json()
|
|
168
|
+
|
|
169
|
+
choices_data = data.get('choices', [])
|
|
170
|
+
usage_data = data.get('usage', {})
|
|
171
|
+
|
|
172
|
+
choices = []
|
|
173
|
+
for choice_d in choices_data:
|
|
174
|
+
message_d = choice_d.get('message', {})
|
|
175
|
+
message = ChatCompletionMessage(
|
|
176
|
+
role=message_d.get('role', 'assistant'),
|
|
177
|
+
content=message_d.get('content', '')
|
|
178
|
+
)
|
|
179
|
+
choice = Choice(
|
|
180
|
+
index=choice_d.get('index', 0),
|
|
181
|
+
message=message,
|
|
182
|
+
finish_reason=choice_d.get('finish_reason', 'stop')
|
|
183
|
+
)
|
|
184
|
+
choices.append(choice)
|
|
185
|
+
|
|
186
|
+
usage = CompletionUsage(
|
|
187
|
+
prompt_tokens=usage_data.get('prompt_tokens', 0),
|
|
188
|
+
completion_tokens=usage_data.get('completion_tokens', 0),
|
|
189
|
+
total_tokens=usage_data.get('total_tokens', 0)
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
completion = ChatCompletion(
|
|
193
|
+
id=request_id,
|
|
194
|
+
choices=choices,
|
|
195
|
+
created=created_time,
|
|
196
|
+
model=data.get('model', model),
|
|
197
|
+
usage=usage,
|
|
198
|
+
)
|
|
199
|
+
return completion
|
|
200
|
+
|
|
201
|
+
except requests.exceptions.RequestException as e:
|
|
202
|
+
print(f"Error during oivscode non-stream request: {e}")
|
|
203
|
+
raise IOError(f"oivscode request failed: {e}") from e
|
|
204
|
+
except Exception as e:
|
|
205
|
+
print(f"Error processing oivscode response: {e}")
|
|
206
|
+
raise
|
|
207
|
+
|
|
208
|
+
class Chat(BaseChat):
|
|
209
|
+
def __init__(self, client: 'oivscode'):
|
|
210
|
+
self.completions = Completions(client)
|
|
211
|
+
|
|
212
|
+
class oivscode(OpenAICompatibleProvider):
|
|
213
|
+
|
|
214
|
+
AVAILABLE_MODELS = [
|
|
215
|
+
"*",
|
|
216
|
+
"Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
217
|
+
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
218
|
+
"claude-3-5-sonnet-20240620",
|
|
219
|
+
"claude-3-5-sonnet-20241022",
|
|
220
|
+
"claude-3-7-sonnet-20250219",
|
|
221
|
+
"custom/blackbox-base",
|
|
222
|
+
"custom/blackbox-pro",
|
|
223
|
+
"custom/blackbox-pro-designer",
|
|
224
|
+
"custom/blackbox-pro-plus",
|
|
225
|
+
"deepseek-r1",
|
|
226
|
+
"deepseek-v3",
|
|
227
|
+
"deepseek/deepseek-chat",
|
|
228
|
+
"gemini-2.5-pro-preview-03-25",
|
|
229
|
+
"gpt-4o-mini",
|
|
230
|
+
"grok-3-beta",
|
|
231
|
+
"image-gen",
|
|
232
|
+
"llama-4-maverick-17b-128e-instruct-fp8",
|
|
233
|
+
"o1",
|
|
234
|
+
"o3-mini",
|
|
235
|
+
"o4-mini",
|
|
236
|
+
"transcribe",
|
|
237
|
+
"anthropic/claude-sonnet-4"
|
|
238
|
+
]
|
|
239
|
+
|
|
240
|
+
def __init__(self, timeout: Optional[int] = None):
|
|
241
|
+
self.timeout = timeout
|
|
242
|
+
self.api_endpoints = [
|
|
243
|
+
"https://oi-vscode-server.onrender.com/v1/chat/completions",
|
|
244
|
+
"https://oi-vscode-server-2.onrender.com/v1/chat/completions",
|
|
245
|
+
"https://oi-vscode-server-5.onrender.com/v1/chat/completions",
|
|
246
|
+
"https://oi-vscode-server-0501.onrender.com/v1/chat/completions"
|
|
247
|
+
]
|
|
248
|
+
self.api_endpoint = random.choice(self.api_endpoints)
|
|
249
|
+
self.base_url = self.api_endpoint
|
|
250
|
+
self.session = requests.Session()
|
|
251
|
+
self.headers = {
|
|
252
|
+
"accept": "*/*",
|
|
253
|
+
"accept-language": "en-US,en;q=0.9,en-GB;q=0.8,en-IN;q=0.7",
|
|
254
|
+
"cache-control": "no-cache",
|
|
255
|
+
"content-type": "application/json",
|
|
256
|
+
"pragma": "no-cache",
|
|
257
|
+
"priority": "u=1, i",
|
|
258
|
+
"sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"',
|
|
259
|
+
"sec-ch-ua-mobile": "?0",
|
|
260
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
261
|
+
"sec-fetch-dest": "empty",
|
|
262
|
+
"sec-fetch-mode": "cors",
|
|
263
|
+
"sec-fetch-site": "same-site",
|
|
264
|
+
}
|
|
265
|
+
self.userid = ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(21))
|
|
266
|
+
self.headers["userid"] = self.userid
|
|
267
|
+
self.session.headers.update(self.headers)
|
|
268
|
+
self.chat = Chat(self)
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def models(self):
|
|
272
|
+
class _ModelList:
|
|
273
|
+
def list(inner_self):
|
|
274
|
+
return type(self).AVAILABLE_MODELS
|
|
275
|
+
return _ModelList()
|
|
276
|
+
|
|
277
|
+
if __name__ == "__main__":
|
|
278
|
+
# Example usage
|
|
279
|
+
client = oivscode()
|
|
280
|
+
chat = client.chat
|
|
281
|
+
response = chat.completions.create(
|
|
282
|
+
model="Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
283
|
+
messages=[{"role": "user", "content": "Hello, how are you?"}],
|
|
284
|
+
max_tokens=50,
|
|
285
|
+
stream=False
|
|
286
|
+
)
|
|
287
|
+
print(response)
|