webscout 8.3.2__py3-none-any.whl → 8.3.4__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.

Files changed (117) hide show
  1. webscout/AIutel.py +367 -41
  2. webscout/Bard.py +2 -22
  3. webscout/Bing_search.py +1 -2
  4. webscout/Provider/AISEARCH/__init__.py +1 -0
  5. webscout/Provider/AISEARCH/scira_search.py +24 -11
  6. webscout/Provider/AISEARCH/stellar_search.py +132 -0
  7. webscout/Provider/Deepinfra.py +75 -57
  8. webscout/Provider/ExaChat.py +93 -63
  9. webscout/Provider/Flowith.py +1 -1
  10. webscout/Provider/FreeGemini.py +2 -2
  11. webscout/Provider/Gemini.py +3 -10
  12. webscout/Provider/GeminiProxy.py +31 -5
  13. webscout/Provider/HeckAI.py +85 -80
  14. webscout/Provider/Jadve.py +56 -50
  15. webscout/Provider/LambdaChat.py +39 -31
  16. webscout/Provider/MiniMax.py +207 -0
  17. webscout/Provider/Nemotron.py +41 -13
  18. webscout/Provider/Netwrck.py +39 -59
  19. webscout/Provider/OLLAMA.py +8 -9
  20. webscout/Provider/OPENAI/BLACKBOXAI.py +0 -1
  21. webscout/Provider/OPENAI/MiniMax.py +298 -0
  22. webscout/Provider/OPENAI/README.md +31 -30
  23. webscout/Provider/OPENAI/TogetherAI.py +4 -17
  24. webscout/Provider/OPENAI/__init__.py +4 -2
  25. webscout/Provider/OPENAI/autoproxy.py +753 -18
  26. webscout/Provider/OPENAI/base.py +7 -76
  27. webscout/Provider/OPENAI/copilot.py +73 -26
  28. webscout/Provider/OPENAI/deepinfra.py +96 -132
  29. webscout/Provider/OPENAI/exachat.py +9 -5
  30. webscout/Provider/OPENAI/flowith.py +179 -166
  31. webscout/Provider/OPENAI/friendli.py +233 -0
  32. webscout/Provider/OPENAI/monochat.py +329 -0
  33. webscout/Provider/OPENAI/netwrck.py +4 -7
  34. webscout/Provider/OPENAI/pydantic_imports.py +1 -172
  35. webscout/Provider/OPENAI/qodo.py +630 -0
  36. webscout/Provider/OPENAI/scirachat.py +82 -49
  37. webscout/Provider/OPENAI/textpollinations.py +13 -12
  38. webscout/Provider/OPENAI/toolbaz.py +1 -0
  39. webscout/Provider/OPENAI/typegpt.py +4 -4
  40. webscout/Provider/OPENAI/utils.py +19 -42
  41. webscout/Provider/OPENAI/x0gpt.py +14 -2
  42. webscout/Provider/OpenGPT.py +54 -32
  43. webscout/Provider/PI.py +58 -84
  44. webscout/Provider/Qodo.py +454 -0
  45. webscout/Provider/StandardInput.py +32 -13
  46. webscout/Provider/TTI/README.md +9 -9
  47. webscout/Provider/TTI/__init__.py +2 -1
  48. webscout/Provider/TTI/aiarta.py +92 -78
  49. webscout/Provider/TTI/infip.py +212 -0
  50. webscout/Provider/TTI/monochat.py +220 -0
  51. webscout/Provider/TeachAnything.py +11 -3
  52. webscout/Provider/TextPollinationsAI.py +91 -82
  53. webscout/Provider/TogetherAI.py +32 -48
  54. webscout/Provider/Venice.py +37 -46
  55. webscout/Provider/VercelAI.py +27 -24
  56. webscout/Provider/WiseCat.py +35 -35
  57. webscout/Provider/WrDoChat.py +22 -26
  58. webscout/Provider/WritingMate.py +26 -22
  59. webscout/Provider/__init__.py +6 -6
  60. webscout/Provider/copilot.py +58 -61
  61. webscout/Provider/freeaichat.py +64 -55
  62. webscout/Provider/granite.py +48 -57
  63. webscout/Provider/koala.py +51 -39
  64. webscout/Provider/learnfastai.py +49 -64
  65. webscout/Provider/llmchat.py +79 -93
  66. webscout/Provider/llmchatco.py +63 -78
  67. webscout/Provider/monochat.py +275 -0
  68. webscout/Provider/multichat.py +51 -40
  69. webscout/Provider/oivscode.py +1 -1
  70. webscout/Provider/scira_chat.py +257 -104
  71. webscout/Provider/scnet.py +13 -13
  72. webscout/Provider/searchchat.py +13 -13
  73. webscout/Provider/sonus.py +12 -11
  74. webscout/Provider/toolbaz.py +25 -8
  75. webscout/Provider/turboseek.py +41 -42
  76. webscout/Provider/typefully.py +27 -12
  77. webscout/Provider/typegpt.py +43 -48
  78. webscout/Provider/uncovr.py +55 -90
  79. webscout/Provider/x0gpt.py +325 -299
  80. webscout/Provider/yep.py +79 -96
  81. webscout/__init__.py +7 -2
  82. webscout/auth/__init__.py +12 -1
  83. webscout/auth/providers.py +27 -5
  84. webscout/auth/routes.py +146 -105
  85. webscout/auth/server.py +367 -312
  86. webscout/client.py +121 -116
  87. webscout/litagent/Readme.md +68 -55
  88. webscout/litagent/agent.py +99 -9
  89. webscout/version.py +1 -1
  90. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/METADATA +102 -91
  91. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/RECORD +95 -107
  92. webscout/Provider/AI21.py +0 -177
  93. webscout/Provider/HuggingFaceChat.py +0 -469
  94. webscout/Provider/OPENAI/freeaichat.py +0 -363
  95. webscout/Provider/TTI/fastflux.py +0 -233
  96. webscout/Provider/Writecream.py +0 -246
  97. webscout/auth/static/favicon.svg +0 -11
  98. webscout/auth/swagger_ui.py +0 -203
  99. webscout/auth/templates/components/authentication.html +0 -237
  100. webscout/auth/templates/components/base.html +0 -103
  101. webscout/auth/templates/components/endpoints.html +0 -750
  102. webscout/auth/templates/components/examples.html +0 -491
  103. webscout/auth/templates/components/footer.html +0 -75
  104. webscout/auth/templates/components/header.html +0 -27
  105. webscout/auth/templates/components/models.html +0 -286
  106. webscout/auth/templates/components/navigation.html +0 -70
  107. webscout/auth/templates/static/api.js +0 -455
  108. webscout/auth/templates/static/icons.js +0 -168
  109. webscout/auth/templates/static/main.js +0 -784
  110. webscout/auth/templates/static/particles.js +0 -201
  111. webscout/auth/templates/static/styles.css +0 -3353
  112. webscout/auth/templates/static/ui.js +0 -374
  113. webscout/auth/templates/swagger_ui.html +0 -170
  114. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/WHEEL +0 -0
  115. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/entry_points.txt +0 -0
  116. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/licenses/LICENSE.md +0 -0
  117. {webscout-8.3.2.dist-info → webscout-8.3.4.dist-info}/top_level.txt +0 -0
@@ -1,363 +0,0 @@
1
- import time
2
- import uuid
3
- import requests
4
- import json
5
- from typing import List, Dict, Optional, Union, Generator, Any
6
-
7
- # Import base classes and utility structures
8
- from .base import OpenAICompatibleProvider, BaseChat, BaseCompletions
9
- from .utils import (
10
- ChatCompletionChunk, ChatCompletion, Choice, ChoiceDelta,
11
- ChatCompletionMessage, CompletionUsage, count_tokens
12
- )
13
-
14
- # Attempt to import LitAgent, fallback if not available
15
- try:
16
- from webscout.litagent import LitAgent
17
- except ImportError:
18
- pass
19
-
20
- # --- FreeAIChat Client ---
21
-
22
- class Completions(BaseCompletions):
23
- def __init__(self, client: 'FreeAIChat'):
24
- self._client = client
25
-
26
- def create(
27
- self,
28
- *,
29
- model: str,
30
- messages: List[Dict[str, str]],
31
- max_tokens: Optional[int] = 2049,
32
- stream: bool = False,
33
- temperature: Optional[float] = None,
34
- top_p: Optional[float] = None,
35
- timeout: Optional[int] = None,
36
- proxies: Optional[Dict[str, str]] = None,
37
- **kwargs: Any
38
- ) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
39
- """
40
- Creates a model response for the given chat conversation.
41
- Mimics openai.chat.completions.create
42
- """
43
- payload = {
44
- "model": model,
45
- "messages": messages,
46
- "max_tokens": max_tokens,
47
- "stream": stream,
48
- }
49
- if temperature is not None:
50
- payload["temperature"] = temperature
51
- if top_p is not None:
52
- payload["top_p"] = top_p
53
-
54
- payload.update(kwargs)
55
-
56
- request_id = f"chatcmpl-{uuid.uuid4()}"
57
- created_time = int(time.time())
58
-
59
- if stream:
60
- return self._create_stream(request_id, created_time, model, payload, timeout, proxies)
61
- else:
62
- return self._create_non_stream(request_id, created_time, model, payload, timeout, proxies)
63
-
64
- def _create_stream(
65
- self, request_id: str, created_time: int, model: str, payload: Dict[str, Any], timeout: Optional[int] = None, proxies: Optional[Dict[str, str]] = None
66
- ) -> Generator[ChatCompletionChunk, None, None]:
67
- try:
68
- response = self._client.session.post(
69
- self._client.api_endpoint,
70
- headers=self._client.headers,
71
- json=payload,
72
- stream=True,
73
- timeout=timeout or self._client.timeout,
74
- proxies=proxies or getattr(self._client, "proxies", None)
75
- )
76
-
77
- # Handle non-200 responses
78
- if not response.ok:
79
- raise IOError(
80
- f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
81
- )
82
-
83
- # Track token usage across chunks
84
- prompt_tokens = 0
85
- completion_tokens = 0
86
- total_tokens = 0
87
-
88
- # Estimate prompt tokens based on message length
89
- for msg in payload.get("messages", []):
90
- prompt_tokens += count_tokens(msg.get("content", ""))
91
-
92
- for line in response.iter_lines():
93
- if not line:
94
- continue
95
-
96
- line_str = line.decode('utf-8').strip()
97
-
98
- if line_str.startswith("data: "):
99
- json_str = line_str[6:] # Remove "data: " prefix
100
- if json_str == "[DONE]":
101
- break
102
-
103
- try:
104
- data = json.loads(json_str)
105
- choice_data = data.get('choices', [{}])[0]
106
- delta_data = choice_data.get('delta', {})
107
- finish_reason = choice_data.get('finish_reason')
108
-
109
- # Update token counts if available
110
- usage_data = data.get('usage', {})
111
- if usage_data:
112
- prompt_tokens = usage_data.get('prompt_tokens', prompt_tokens)
113
- completion_tokens = usage_data.get('completion_tokens', completion_tokens)
114
- total_tokens = usage_data.get('total_tokens', total_tokens)
115
-
116
- # Create the delta object
117
- delta = ChoiceDelta(
118
- content=delta_data.get('content'),
119
- role=delta_data.get('role'),
120
- tool_calls=delta_data.get('tool_calls')
121
- )
122
-
123
- # Create the choice object
124
- choice = Choice(
125
- index=choice_data.get('index', 0),
126
- delta=delta,
127
- finish_reason=finish_reason,
128
- logprobs=choice_data.get('logprobs')
129
- )
130
-
131
- # Create the chunk object
132
- chunk = ChatCompletionChunk(
133
- id=request_id,
134
- choices=[choice],
135
- created=created_time,
136
- model=model,
137
- system_fingerprint=data.get('system_fingerprint')
138
- )
139
-
140
- # Return the chunk object
141
- yield chunk
142
- except json.JSONDecodeError:
143
- print(f"Warning: Could not decode JSON line: {json_str}")
144
- continue
145
-
146
- # Final chunk with finish_reason="stop"
147
- delta = ChoiceDelta(
148
- content=None,
149
- role=None,
150
- tool_calls=None
151
- )
152
-
153
- choice = Choice(
154
- index=0,
155
- delta=delta,
156
- finish_reason="stop",
157
- logprobs=None
158
- )
159
-
160
- chunk = ChatCompletionChunk(
161
- id=request_id,
162
- choices=[choice],
163
- created=created_time,
164
- model=model,
165
- system_fingerprint=None
166
- )
167
-
168
- yield chunk
169
-
170
- except Exception as e:
171
- print(f"Error during FreeAIChat stream request: {e}")
172
- raise IOError(f"FreeAIChat request failed: {e}") from e
173
-
174
- def _create_non_stream(
175
- self, request_id: str, created_time: int, model: str, payload: Dict[str, Any], timeout: Optional[int] = None, proxies: Optional[Dict[str, str]] = None
176
- ) -> ChatCompletion:
177
- try:
178
- response = self._client.session.post(
179
- self._client.api_endpoint,
180
- headers=self._client.headers,
181
- json=payload,
182
- timeout=timeout or self._client.timeout,
183
- proxies=proxies or getattr(self._client, "proxies", None)
184
- )
185
-
186
- # Handle non-200 responses
187
- if not response.ok:
188
- raise IOError(
189
- f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
190
- )
191
-
192
- # Parse the response
193
- data = response.json()
194
-
195
- choices_data = data.get('choices', [])
196
- usage_data = data.get('usage', {})
197
-
198
- choices = []
199
- for choice_d in choices_data:
200
- message_d = choice_d.get('message', {})
201
- message = ChatCompletionMessage(
202
- role=message_d.get('role', 'assistant'),
203
- content=message_d.get('content', '')
204
- )
205
- choice = Choice(
206
- index=choice_d.get('index', 0),
207
- message=message,
208
- finish_reason=choice_d.get('finish_reason', 'stop')
209
- )
210
- choices.append(choice)
211
-
212
- usage = CompletionUsage(
213
- prompt_tokens=usage_data.get('prompt_tokens', 0),
214
- completion_tokens=usage_data.get('completion_tokens', 0),
215
- total_tokens=usage_data.get('total_tokens', 0)
216
- )
217
-
218
- completion = ChatCompletion(
219
- id=request_id,
220
- choices=choices,
221
- created=created_time,
222
- model=data.get('model', model),
223
- usage=usage,
224
- )
225
- return completion
226
-
227
- except Exception as e:
228
- print(f"Error during FreeAIChat non-stream request: {e}")
229
- raise IOError(f"FreeAIChat request failed: {e}") from e
230
-
231
- class Chat(BaseChat):
232
- def __init__(self, client: 'FreeAIChat'):
233
- self.completions = Completions(client)
234
-
235
- class FreeAIChat(OpenAICompatibleProvider):
236
- """
237
- OpenAI-compatible client for FreeAIChat API.
238
-
239
- Usage:
240
- client = FreeAIChat()
241
- response = client.chat.completions.create(
242
- model="GPT 4o",
243
- messages=[{"role": "user", "content": "Hello!"}]
244
- )
245
- """
246
-
247
- AVAILABLE_MODELS = [
248
- # OpenAI Models
249
- "GPT 4o",
250
- "GPT 4.5 Preview",
251
- "GPT 4o Latest",
252
- "GPT 4o mini",
253
- "GPT 4o Search Preview",
254
- "O1",
255
- "O1 Mini",
256
- "O3 Mini",
257
- "O3 Mini High",
258
- "O3 Mini Low",
259
-
260
- # Anthropic Models
261
- "Claude 3.5 haiku",
262
- "claude 3.5 sonnet",
263
- "Claude 3.7 Sonnet",
264
- "Claude 3.7 Sonnet (Thinking)",
265
-
266
- # Deepseek Models
267
- "Deepseek R1",
268
- "Deepseek R1 Fast",
269
- "Deepseek V3",
270
- "Deepseek v3 0324",
271
-
272
- # Google Models
273
- "Gemini 1.5 Flash",
274
- "Gemini 1.5 Pro",
275
- "Gemini 2.0 Flash",
276
- "Gemini 2.0 Pro",
277
- "Gemini 2.5 Pro",
278
-
279
- # Llama Models
280
- "Llama 3.1 405B",
281
- "Llama 3.1 70B Fast",
282
- "Llama 3.3 70B",
283
- "Llama 3.2 90B Vision",
284
- "Llama 4 Scout",
285
- "Llama 4 Maverick",
286
-
287
- # Mistral Models
288
- "Mistral Large",
289
- "Mistral Nemo",
290
- "Mixtral 8x22B",
291
-
292
- # Qwen Models
293
- "Qwen Max",
294
- "Qwen Plus",
295
- "Qwen Turbo",
296
- "QwQ 32B",
297
- "QwQ Plus",
298
-
299
- # XAI Models
300
- "Grok 2",
301
- "Grok 3",
302
- ]
303
-
304
- def __init__(
305
- self,
306
- timeout: Optional[int] = None,
307
- browser: str = "chrome"
308
- ):
309
- """
310
- Initialize the FreeAIChat client.
311
-
312
- Args:
313
- timeout: Request timeout in seconds (None for no timeout)
314
- browser: Browser to emulate in user agent
315
- """
316
- self.timeout = timeout
317
- self.api_endpoint = "https://freeaichatplayground.com/api/v1/chat/completions"
318
- self.session = requests.Session()
319
-
320
- # Initialize LitAgent for user agent generation
321
- agent = LitAgent()
322
- self.fingerprint = agent.generate_fingerprint(browser)
323
-
324
- # Initialize headers
325
- self.headers = {
326
- 'User-Agent': self.fingerprint["user_agent"],
327
- 'Accept': '*/*',
328
- 'Content-Type': 'application/json',
329
- 'Origin': 'https://freeaichatplayground.com',
330
- 'Referer': 'https://freeaichatplayground.com/',
331
- 'Sec-Fetch-Mode': 'cors',
332
- 'Sec-Fetch-Site': 'same-origin'
333
- }
334
-
335
- self.session.headers.update(self.headers)
336
-
337
- # Initialize the chat interface
338
- self.chat = Chat(self)
339
-
340
- def convert_model_name(self, model: str) -> str:
341
- """
342
- Convert model names to ones supported by FreeAIChat.
343
-
344
- Args:
345
- model: Model name to convert
346
-
347
- Returns:
348
- FreeAIChat model name
349
- """
350
- # If the model is already a valid FreeAIChat model, return it
351
- if model in self.AVAILABLE_MODELS:
352
- return model
353
-
354
- # Default to GPT 4o if model not found
355
- print(f"Warning: Unknown model '{model}'. Using 'GPT 4o' instead.")
356
- return "GPT 4o"
357
-
358
- @property
359
- def models(self):
360
- class _ModelList:
361
- def list(inner_self):
362
- return type(self).AVAILABLE_MODELS
363
- return _ModelList()
@@ -1,233 +0,0 @@
1
- import requests
2
- import os
3
- import tempfile
4
- import time
5
- import base64
6
- from typing import Optional, List, Dict, Any
7
- from webscout.Provider.TTI.utils import (
8
- ImageData,
9
- ImageResponse
10
- )
11
- from webscout.Provider.TTI.base import TTICompatibleProvider, BaseImages
12
- from io import BytesIO
13
- from webscout.litagent import LitAgent
14
-
15
- try:
16
- from PIL import Image
17
- except ImportError:
18
- Image = None
19
-
20
-
21
- class Images(BaseImages):
22
- def __init__(self, client):
23
- self._client = client
24
-
25
- def create(
26
- self,
27
- model: str = "flux_1_schnell",
28
- prompt: str = None,
29
- n: int = 1,
30
- size: str = "1_1",
31
- response_format: str = "url",
32
- user: Optional[str] = None,
33
- style: str = "none",
34
- aspect_ratio: str = "1:1",
35
- timeout: int = 60,
36
- image_format: str = "png",
37
- is_public: bool = False,
38
- **kwargs,
39
- ) -> ImageResponse:
40
- if not prompt:
41
- raise ValueError("Prompt is required!")
42
- agent = LitAgent()
43
- images = []
44
- urls = []
45
- api_url = self._client.api_endpoint
46
- payload = {
47
- "prompt": prompt,
48
- "model": model,
49
- "size": size,
50
- "isPublic": is_public,
51
- }
52
- for _ in range(n):
53
- resp = self._client.session.post(
54
- api_url,
55
- json=payload,
56
- timeout=timeout,
57
- )
58
- resp.raise_for_status()
59
- result = resp.json()
60
- if result and "result" in result:
61
- image_data = result["result"]
62
- base64_data = image_data.split(",")[1]
63
- img_bytes = base64.b64decode(base64_data)
64
- # Convert to png or jpeg in memory if needed
65
- if Image is not None:
66
- with BytesIO(img_bytes) as input_io:
67
- with Image.open(input_io) as im:
68
- out_io = BytesIO()
69
- if image_format.lower() == "jpeg":
70
- im = im.convert("RGB")
71
- im.save(out_io, format="JPEG")
72
- else:
73
- im.save(out_io, format="PNG")
74
- img_bytes = out_io.getvalue()
75
- images.append(img_bytes)
76
- if response_format == "url":
77
-
78
- def upload_file_with_retry(img_bytes, image_format, max_retries=3):
79
- ext = "jpg" if image_format.lower() == "jpeg" else "png"
80
- for attempt in range(max_retries):
81
- tmp_path = None
82
- try:
83
- with tempfile.NamedTemporaryFile(
84
- suffix=f".{ext}", delete=False
85
- ) as tmp:
86
- tmp.write(img_bytes)
87
- tmp.flush()
88
- tmp_path = tmp.name
89
- with open(tmp_path, "rb") as f:
90
- files = {
91
- "fileToUpload": (
92
- f"image.{ext}",
93
- f,
94
- f"image/{ext}",
95
- )
96
- }
97
- data = {"reqtype": "fileupload", "json": "true"}
98
- headers = {"User-Agent": agent.random()}
99
- if attempt > 0:
100
- headers["Connection"] = "close"
101
- resp = requests.post(
102
- "https://catbox.moe/user/api.php",
103
- files=files,
104
- data=data,
105
- headers=headers,
106
- timeout=timeout,
107
- )
108
- if resp.status_code == 200 and resp.text.strip():
109
- text = resp.text.strip()
110
- if text.startswith("http"):
111
- return text
112
- try:
113
- result = resp.json()
114
- if "url" in result:
115
- return result["url"]
116
- except Exception:
117
- if "http" in text:
118
- return text
119
- except Exception:
120
- if attempt < max_retries - 1:
121
- time.sleep(1 * (attempt + 1))
122
- finally:
123
- if tmp_path and os.path.isfile(tmp_path):
124
- try:
125
- os.remove(tmp_path)
126
- except Exception:
127
- pass
128
- return None
129
-
130
- def upload_file_alternative(img_bytes, image_format):
131
- try:
132
- ext = "jpg" if image_format.lower() == "jpeg" else "png"
133
- with tempfile.NamedTemporaryFile(
134
- suffix=f".{ext}", delete=False
135
- ) as tmp:
136
- tmp.write(img_bytes)
137
- tmp.flush()
138
- tmp_path = tmp.name
139
- try:
140
- if not os.path.isfile(tmp_path):
141
- return None
142
- with open(tmp_path, "rb") as img_file:
143
- files = {"file": img_file}
144
- response = requests.post(
145
- "https://0x0.st", files=files
146
- )
147
- response.raise_for_status()
148
- image_url = response.text.strip()
149
- if not image_url.startswith("http"):
150
- return None
151
- return image_url
152
- except Exception:
153
- return None
154
- finally:
155
- try:
156
- os.remove(tmp_path)
157
- except Exception:
158
- pass
159
- except Exception:
160
- return None
161
-
162
- uploaded_url = upload_file_with_retry(img_bytes, image_format)
163
- if not uploaded_url:
164
- uploaded_url = upload_file_alternative(img_bytes, image_format)
165
- if uploaded_url:
166
- urls.append(uploaded_url)
167
- else:
168
- raise RuntimeError(
169
- "Failed to upload image to catbox.moe using all available methods"
170
- )
171
- else:
172
- raise RuntimeError("No image data received from FastFlux API")
173
- result_data = []
174
- if response_format == "url":
175
- for url in urls:
176
- result_data.append(ImageData(url=url))
177
- elif response_format == "b64_json":
178
- import base64
179
-
180
- for img in images:
181
- b64 = base64.b64encode(img).decode("utf-8")
182
- result_data.append(ImageData(b64_json=b64))
183
- else:
184
- raise ValueError("response_format must be 'url' or 'b64_json'")
185
- from time import time as _time
186
-
187
- return ImageResponse(created=int(_time()), data=result_data)
188
-
189
-
190
- class FastFluxAI(TTICompatibleProvider):
191
- AVAILABLE_MODELS = [
192
- "flux_1_schnell",
193
- ]
194
-
195
- def __init__(self, api_key: str = None):
196
- self.api_endpoint = "https://api.freeflux.ai/v1/images/generate"
197
- self.session = requests.Session()
198
- self.user_agent = LitAgent().random()
199
- self.api_key = api_key
200
- self.headers = {
201
- "accept": "application/json, text/plain, */*",
202
- "accept-language": "en-US,en;q=0.9",
203
- "content-type": "application/json",
204
- "origin": "https://freeflux.ai",
205
- "referer": "https://freeflux.ai/",
206
- "user-agent": self.user_agent,
207
- }
208
- if self.api_key:
209
- self.headers["authorization"] = f"Bearer {self.api_key}"
210
- self.session.headers.update(self.headers)
211
- self.images = Images(self)
212
-
213
- @property
214
- def models(self):
215
- class _ModelList:
216
- def list(inner_self):
217
- return type(self).AVAILABLE_MODELS
218
-
219
- return _ModelList()
220
-
221
-
222
- if __name__ == "__main__":
223
- from rich import print
224
-
225
- client = FastFluxAI()
226
- response = client.images.create(
227
- model="flux_1_schnell",
228
- prompt="A cool cyberpunk city at night",
229
- response_format="url",
230
- n=2,
231
- timeout=30,
232
- )
233
- print(response)