webscout 7.6__py3-none-any.whl → 7.8__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 (124) hide show
  1. webscout/AIutel.py +2 -1
  2. webscout/Bard.py +14 -11
  3. webscout/DWEBS.py +431 -415
  4. webscout/Extra/autocoder/autocoder_utiles.py +183 -47
  5. webscout/Extra/autocoder/rawdog.py +848 -649
  6. webscout/Extra/gguf.py +682 -652
  7. webscout/Provider/AI21.py +1 -1
  8. webscout/Provider/AISEARCH/DeepFind.py +2 -2
  9. webscout/Provider/AISEARCH/ISou.py +2 -23
  10. webscout/Provider/AISEARCH/felo_search.py +6 -6
  11. webscout/Provider/AISEARCH/genspark_search.py +1 -1
  12. webscout/Provider/Aitopia.py +292 -0
  13. webscout/Provider/AllenAI.py +5 -22
  14. webscout/Provider/Andi.py +3 -3
  15. webscout/Provider/C4ai.py +1 -1
  16. webscout/Provider/ChatGPTClone.py +226 -0
  17. webscout/Provider/ChatGPTES.py +3 -5
  18. webscout/Provider/ChatGPTGratis.py +4 -4
  19. webscout/Provider/Chatify.py +2 -2
  20. webscout/Provider/Cloudflare.py +3 -2
  21. webscout/Provider/DARKAI.py +3 -2
  22. webscout/Provider/DeepSeek.py +2 -2
  23. webscout/Provider/Deepinfra.py +1 -1
  24. webscout/Provider/EDITEE.py +1 -1
  25. webscout/Provider/ElectronHub.py +178 -96
  26. webscout/Provider/ExaChat.py +310 -0
  27. webscout/Provider/Free2GPT.py +2 -2
  28. webscout/Provider/Gemini.py +5 -19
  29. webscout/Provider/GithubChat.py +1 -1
  30. webscout/Provider/Glider.py +12 -8
  31. webscout/Provider/Groq.py +3 -3
  32. webscout/Provider/HF_space/qwen_qwen2.py +1 -1
  33. webscout/Provider/HeckAI.py +1 -1
  34. webscout/Provider/HuggingFaceChat.py +1 -1
  35. webscout/Provider/Hunyuan.py +272 -0
  36. webscout/Provider/Jadve.py +3 -3
  37. webscout/Provider/Koboldai.py +3 -3
  38. webscout/Provider/LambdaChat.py +391 -0
  39. webscout/Provider/Llama.py +3 -5
  40. webscout/Provider/Llama3.py +4 -12
  41. webscout/Provider/Marcus.py +3 -3
  42. webscout/Provider/OLLAMA.py +260 -36
  43. webscout/Provider/Openai.py +7 -3
  44. webscout/Provider/PI.py +1 -1
  45. webscout/Provider/Perplexitylabs.py +1 -1
  46. webscout/Provider/Phind.py +1 -1
  47. webscout/Provider/PizzaGPT.py +1 -1
  48. webscout/Provider/QwenLM.py +4 -7
  49. webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +21 -46
  50. webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +37 -49
  51. webscout/Provider/TTI/ImgSys/__init__.py +23 -0
  52. webscout/Provider/TTI/ImgSys/async_imgsys.py +202 -0
  53. webscout/Provider/TTI/ImgSys/sync_imgsys.py +195 -0
  54. webscout/Provider/TTI/__init__.py +3 -1
  55. webscout/Provider/TTI/artbit/async_artbit.py +4 -33
  56. webscout/Provider/TTI/artbit/sync_artbit.py +4 -32
  57. webscout/Provider/TTI/fastflux/async_fastflux.py +6 -2
  58. webscout/Provider/TTI/fastflux/sync_fastflux.py +7 -2
  59. webscout/Provider/TTI/huggingface/async_huggingface.py +1 -1
  60. webscout/Provider/TTI/huggingface/sync_huggingface.py +1 -1
  61. webscout/Provider/TTI/pixelmuse/__init__.py +4 -0
  62. webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +249 -0
  63. webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +182 -0
  64. webscout/Provider/TTI/talkai/sync_talkai.py +1 -1
  65. webscout/Provider/TTS/utils.py +1 -1
  66. webscout/Provider/TeachAnything.py +1 -1
  67. webscout/Provider/TextPollinationsAI.py +4 -4
  68. webscout/Provider/TwoAI.py +1 -2
  69. webscout/Provider/Venice.py +4 -2
  70. webscout/Provider/VercelAI.py +234 -0
  71. webscout/Provider/WebSim.py +228 -0
  72. webscout/Provider/WiseCat.py +10 -12
  73. webscout/Provider/Youchat.py +1 -1
  74. webscout/Provider/__init__.py +22 -1
  75. webscout/Provider/ai4chat.py +1 -1
  76. webscout/Provider/aimathgpt.py +2 -6
  77. webscout/Provider/akashgpt.py +1 -1
  78. webscout/Provider/askmyai.py +4 -4
  79. webscout/Provider/asksteve.py +203 -0
  80. webscout/Provider/bagoodex.py +2 -2
  81. webscout/Provider/cerebras.py +1 -1
  82. webscout/Provider/chatglm.py +4 -4
  83. webscout/Provider/cleeai.py +1 -0
  84. webscout/Provider/copilot.py +427 -415
  85. webscout/Provider/elmo.py +1 -1
  86. webscout/Provider/flowith.py +14 -3
  87. webscout/Provider/freeaichat.py +57 -31
  88. webscout/Provider/gaurish.py +3 -5
  89. webscout/Provider/geminiprorealtime.py +1 -1
  90. webscout/Provider/granite.py +4 -4
  91. webscout/Provider/hermes.py +5 -5
  92. webscout/Provider/julius.py +1 -1
  93. webscout/Provider/koala.py +1 -1
  94. webscout/Provider/labyrinth.py +239 -0
  95. webscout/Provider/learnfastai.py +28 -15
  96. webscout/Provider/lepton.py +1 -1
  97. webscout/Provider/llama3mitril.py +4 -4
  98. webscout/Provider/llamatutor.py +1 -1
  99. webscout/Provider/llmchat.py +3 -3
  100. webscout/Provider/meta.py +1 -1
  101. webscout/Provider/multichat.py +10 -10
  102. webscout/Provider/promptrefine.py +1 -1
  103. webscout/Provider/searchchat.py +293 -0
  104. webscout/Provider/sonus.py +208 -0
  105. webscout/Provider/talkai.py +2 -2
  106. webscout/Provider/turboseek.py +1 -1
  107. webscout/Provider/tutorai.py +1 -1
  108. webscout/Provider/typegpt.py +6 -43
  109. webscout/Provider/uncovr.py +299 -0
  110. webscout/Provider/x0gpt.py +1 -1
  111. webscout/__init__.py +36 -36
  112. webscout/cli.py +293 -283
  113. webscout/litagent/agent.py +14 -9
  114. webscout/tempid.py +11 -11
  115. webscout/utils.py +2 -2
  116. webscout/version.py +1 -1
  117. webscout/webscout_search.py +1282 -1223
  118. webscout/webscout_search_async.py +813 -692
  119. {webscout-7.6.dist-info → webscout-7.8.dist-info}/METADATA +76 -44
  120. {webscout-7.6.dist-info → webscout-7.8.dist-info}/RECORD +124 -106
  121. {webscout-7.6.dist-info → webscout-7.8.dist-info}/LICENSE.md +0 -0
  122. {webscout-7.6.dist-info → webscout-7.8.dist-info}/WHEEL +0 -0
  123. {webscout-7.6.dist-info → webscout-7.8.dist-info}/entry_points.txt +0 -0
  124. {webscout-7.6.dist-info → webscout-7.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,182 @@
1
+ import requests
2
+ import os
3
+ from typing import Union, List
4
+ from string import punctuation
5
+ from random import choice
6
+
7
+ from webscout.AIbase import ImageProvider
8
+ from webscout.litagent import LitAgent
9
+
10
+ class PixelMuseImager(ImageProvider):
11
+ """
12
+ PixelMuse Image Provider - Create stunning AI art with PixelMuse! 🎨
13
+ """
14
+
15
+ AVAILABLE_MODELS = [
16
+ "flux-schnell",
17
+ "imagen-3-fast",
18
+ "imagen-3",
19
+ "recraft-v3"
20
+ ]
21
+
22
+ def __init__(
23
+ self,
24
+ model: str = "flux-schnell",
25
+ timeout: int = 60,
26
+ proxies: dict = {},
27
+ ):
28
+ """Initialize your PixelMuse provider with custom settings! ⚙️
29
+
30
+ Args:
31
+ model (str): Which model to use (default: flux-schnell)
32
+ timeout (int): Request timeout in seconds (default: 60)
33
+ proxies (dict): Proxy settings for requests (default: {})
34
+ logging (bool): Enable fire logging (default: True)
35
+ """
36
+ self.api_endpoint = "https://www.pixelmuse.studio/api/predictions"
37
+ self.headers = {
38
+ "accept": "*/*",
39
+ "accept-language": "en-US,en;q=0.9",
40
+ "content-type": "application/json",
41
+ "origin": "https://www.pixelmuse.studio",
42
+ "referer": "https://www.pixelmuse.studio/",
43
+ "sec-ch-ua": '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
44
+ "sec-ch-ua-mobile": "?0",
45
+ "sec-ch-ua-platform": '"Windows"',
46
+ "sec-fetch-dest": "empty",
47
+ "sec-fetch-mode": "cors",
48
+ "sec-fetch-site": "same-origin",
49
+ "user-agent": LitAgent().random(),
50
+ }
51
+ self.session = requests.Session()
52
+ self.session.headers.update(self.headers)
53
+ self.session.proxies.update(proxies)
54
+ self.timeout = timeout
55
+ self.model = model
56
+ self.prompt: str = "AI-generated image - webscout"
57
+ self.image_extension: str = "webp"
58
+
59
+ def generate(
60
+ self, prompt: str, amount: int = 1,
61
+ max_retries: int = 3, retry_delay: int = 5,
62
+ style: str = "none", aspect_ratio: str = "1:1"
63
+ ) -> List[bytes]:
64
+ """Generate some amazing images from your prompt! 🎨
65
+
66
+ Args:
67
+ prompt (str): Your creative prompt
68
+ amount (int): How many images to generate
69
+ max_retries (int): Max retry attempts if generation fails
70
+ retry_delay (int): Seconds to wait between retries
71
+ style (str): Style to apply (default: "none")
72
+ aspect_ratio (str): Aspect ratio (default: "1:1")
73
+
74
+ Returns:
75
+ List[bytes]: Your generated images as bytes
76
+ """
77
+ assert bool(prompt), "Prompt cannot be empty."
78
+ assert isinstance(amount, int) and amount > 0, "Amount must be a positive integer."
79
+
80
+ self.prompt = prompt
81
+ response = []
82
+
83
+ for _ in range(amount):
84
+ for attempt in range(max_retries):
85
+ try:
86
+ with self.session.post(
87
+ self.api_endpoint,
88
+ json=self._create_payload(prompt, self.model, style, aspect_ratio),
89
+ timeout=self.timeout
90
+ ) as resp:
91
+ resp.raise_for_status()
92
+ data = resp.json()
93
+
94
+ if 'output' in data and len(data['output']) > 0:
95
+ image_url = data['output'][0]
96
+ # Get the image data from the URL
97
+ img_resp = self.session.get(image_url, timeout=self.timeout)
98
+ img_resp.raise_for_status()
99
+ response.append(img_resp.content)
100
+ break
101
+ else:
102
+ print(f"Warning: No image data in response: {data}")
103
+ if attempt == max_retries - 1:
104
+ raise Exception("No image data received after all retries")
105
+
106
+ except Exception as e:
107
+ print(f"Error generating image (attempt {attempt + 1}/{max_retries}): {str(e)}")
108
+ if attempt == max_retries - 1:
109
+ raise
110
+ import time
111
+ time.sleep(retry_delay)
112
+
113
+ return response
114
+
115
+ def _create_payload(self, prompt: str, model: str, style: str, aspect_ratio: str) -> dict:
116
+ """Create the API request payload 📦
117
+
118
+ Args:
119
+ prompt (str): The image generation prompt
120
+ model (str): Model to use
121
+ style (str): Style to apply
122
+ aspect_ratio (str): Aspect ratio
123
+
124
+ Returns:
125
+ dict: API request payload
126
+ """
127
+ return {
128
+ "prompt": prompt,
129
+ "model": model,
130
+ "style": style,
131
+ "aspect_ratio": aspect_ratio
132
+ }
133
+
134
+ def save(
135
+ self,
136
+ response: List[bytes],
137
+ name: str = None,
138
+ dir: str = os.getcwd(),
139
+ filenames_prefix: str = "",
140
+ ) -> List[str]:
141
+ """Save your amazing images! 💾
142
+
143
+ Args:
144
+ response (List[bytes]): List of image data
145
+ name (str, optional): Base name for saved files
146
+ dir (str, optional): Where to save the images
147
+ filenames_prefix (str, optional): Prefix for filenames
148
+
149
+ Returns:
150
+ List[str]: List of saved filenames
151
+ """
152
+ assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
153
+ name = self.prompt if name is None else name
154
+
155
+ if not os.path.exists(dir):
156
+ os.makedirs(dir)
157
+
158
+ filenames = []
159
+ count = 0
160
+ for image in response:
161
+ def complete_path():
162
+ count_value = "" if count == 0 else f"_{count}"
163
+ return os.path.join(dir, name + count_value + "." + self.image_extension)
164
+
165
+ while os.path.isfile(complete_path()):
166
+ count += 1
167
+
168
+ absolute_path_to_file = complete_path()
169
+ filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
170
+
171
+ with open(absolute_path_to_file, "wb") as fh:
172
+ fh.write(image)
173
+ return filenames
174
+
175
+
176
+ if __name__ == "__main__":
177
+ bot = PixelMuseImager()
178
+ try:
179
+ resp = bot.generate("A magical forest with glowing mushrooms and fairy lights", 1)
180
+ print(bot.save(resp))
181
+ except Exception:
182
+ pass
@@ -2,7 +2,7 @@ import uuid
2
2
  import requests
3
3
  import json
4
4
  import os
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Union, Any, Dict, List, Optional
6
6
 
7
7
  from webscout.AIbase import ImageProvider
8
8
  from webscout import exceptions
@@ -1,7 +1,7 @@
1
1
  """
2
2
  Text processing utilities for TTS providers.
3
3
  """
4
- from typing import List, Dict, Tuple, Set, Optional, Pattern
4
+ from typing import Union, List, Dict, Tuple, Set, Optional, Pattern
5
5
  import re
6
6
 
7
7
 
@@ -1,6 +1,6 @@
1
1
  import requests
2
2
  from requests.exceptions import RequestException
3
- from typing import Any, Dict
3
+ from typing import Union, Any, Dict
4
4
  from webscout.AIutel import Conversation, Optimizers
5
5
  from webscout.litagent import LitAgent
6
6
  from webscout.prompt_manager import AwesomePrompts
@@ -1,10 +1,10 @@
1
1
  import requests
2
2
  import json
3
- from typing import Any, Dict, Generator
3
+ from typing import Union, Any, Dict, Generator
4
4
  from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
5
5
  from webscout.AIbase import Provider
6
6
  from webscout import exceptions
7
- from webscout import LitAgent as Lit
7
+ from webscout.litagent import LitAgent as Lit
8
8
 
9
9
  class TextPollinationsAI(Provider):
10
10
  """
@@ -103,7 +103,7 @@ class TextPollinationsAI(Provider):
103
103
  raw: bool = False,
104
104
  optimizer: str = None,
105
105
  conversationally: bool = False,
106
- ) -> Dict[str, Any] | Generator[Dict[str, Any], None, None]:
106
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
107
107
  """Chat with AI"""
108
108
  conversation_prompt = self.conversation.gen_complete_prompt(prompt)
109
109
  if optimizer:
@@ -175,7 +175,7 @@ class TextPollinationsAI(Provider):
175
175
  stream: bool = False,
176
176
  optimizer: str = None,
177
177
  conversationally: bool = False,
178
- ) -> str | Generator[str, None, None]:
178
+ ) -> Union[str, Generator[str, None, None]]:
179
179
  """Generate response as a string"""
180
180
  def for_stream():
181
181
  for response in self.ask(
@@ -8,8 +8,7 @@ from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts, sanitize_stream
9
9
  from webscout.AIbase import Provider, AsyncProvider
10
10
  from webscout import exceptions
11
- from webscout import LitAgent
12
-
11
+ from webscout.litagent import LitAgent
13
12
  class TwoAI(Provider):
14
13
  """
15
14
  A class to interact with the Two AI API with LitAgent user-agent.
@@ -8,7 +8,7 @@ from webscout.AIutel import Conversation
8
8
  from webscout.AIutel import AwesomePrompts, sanitize_stream
9
9
  from webscout.AIbase import Provider
10
10
  from webscout import exceptions
11
- from webscout import LitAgent
11
+ from webscout.litagent import LitAgent
12
12
 
13
13
  class Venice(Provider):
14
14
  """
@@ -18,7 +18,9 @@ class Venice(Provider):
18
18
  AVAILABLE_MODELS = [
19
19
  "llama-3.3-70b",
20
20
  "llama-3.2-3b-akash",
21
- "qwen2dot5-coder-32b"
21
+ "qwen2dot5-coder-32b",
22
+ "deepseek-coder-v2-lite",
23
+
22
24
  ]
23
25
 
24
26
  def __init__(
@@ -0,0 +1,234 @@
1
+ import re
2
+ import time
3
+ import requests
4
+ import json
5
+ from typing import Union, Any, Dict, Generator, Optional
6
+ import uuid
7
+
8
+ from webscout.AIutel import Optimizers
9
+ from webscout.AIutel import Conversation
10
+ from webscout.AIutel import AwesomePrompts
11
+ from webscout.AIbase import Provider
12
+ from webscout import exceptions
13
+ from webscout.litagent import LitAgent
14
+
15
+
16
+ class VercelAI(Provider):
17
+ """
18
+ A class to interact with the Vercel AI API.
19
+ """
20
+
21
+ AVAILABLE_MODELS = [
22
+ "chat-model",
23
+ "chat-model-reasoning"
24
+ ]
25
+
26
+ def __init__(
27
+ self,
28
+ is_conversation: bool = True,
29
+ max_tokens: int = 600,
30
+ timeout: int = 30,
31
+ intro: str = None,
32
+ filepath: str = None,
33
+ update_file: bool = True,
34
+ proxies: dict = {},
35
+ history_offset: int = 10250,
36
+ act: str = None,
37
+ model: str = "chat-model",
38
+ system_prompt: str = "You are a helpful AI assistant."
39
+ ):
40
+ """Initializes the Vercel AI API client."""
41
+
42
+ if model not in self.AVAILABLE_MODELS:
43
+ raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
44
+
45
+ self.session = requests.Session()
46
+ self.is_conversation = is_conversation
47
+ self.max_tokens_to_sample = max_tokens
48
+ self.api_endpoint = "https://chat.vercel.ai/api/chat"
49
+ self.stream_chunk_size = 64
50
+ self.timeout = timeout
51
+ self.last_response = {}
52
+ self.model = model
53
+ self.system_prompt = system_prompt
54
+ self.litagent = LitAgent()
55
+ self.headers = self.litagent.generate_fingerprint()
56
+ self.session.headers.update(self.headers)
57
+ self.session.proxies = proxies
58
+
59
+ # Add Vercel AI specific headers
60
+ self.session.headers.update({
61
+ "authority": "chat.vercel.ai",
62
+ "accept": "*/*",
63
+ "accept-encoding": "gzip, deflate, br, zstd",
64
+ "accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
65
+ "content-type": "application/json",
66
+ "dnt": "1",
67
+ "origin": "https://chat.vercel.ai",
68
+ "priority": "u=1, i",
69
+ "referer": "https://chat.vercel.ai/",
70
+ "sec-ch-ua-mobile": "?0",
71
+ "sec-ch-ua-platform": '"Windows"',
72
+ "sec-fetch-dest": "empty",
73
+ "sec-fetch-mode": "cors",
74
+ "sec-fetch-site": "same-origin",
75
+ "sec-gpc": "1",
76
+ "x-kpsdk-c": "1-Cl4OUDwFNA",
77
+ "x-kpsdk-cd": json.dumps({
78
+ "workTime": int(time.time() * 1000),
79
+ "id": str(uuid.uuid4()),
80
+ "answers": [5, 5],
81
+ "duration": 26.9,
82
+ "d": 1981,
83
+ "st": int(time.time() * 1000) - 1000,
84
+ "rst": int(time.time() * 1000) - 500
85
+ }),
86
+ "x-kpsdk-ct": str(uuid.uuid4()),
87
+ "x-kpsdk-r": "1-B1NfB2A",
88
+ "x-kpsdk-v": "j-1.0.0"
89
+ })
90
+
91
+ # Add cookies
92
+ self.session.cookies.update({
93
+ "KP_UIDz": str(uuid.uuid4()),
94
+ "KP_UIDz-ssn": str(uuid.uuid4())
95
+ })
96
+
97
+ self.__available_optimizers = (
98
+ method
99
+ for method in dir(Optimizers)
100
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
101
+ )
102
+ Conversation.intro = (
103
+ AwesomePrompts().get_act(
104
+ act, raise_not_found=True, default=None, case_insensitive=True
105
+ )
106
+ if act
107
+ else intro or Conversation.intro
108
+ )
109
+ self.conversation = Conversation(
110
+ is_conversation, self.max_tokens_to_sample, filepath, update_file
111
+ )
112
+ self.conversation.history_offset = history_offset
113
+
114
+ def ask(
115
+ self,
116
+ prompt: str,
117
+ stream: bool = False,
118
+ raw: bool = False,
119
+ optimizer: str = None,
120
+ conversationally: bool = False,
121
+ ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
122
+ """Chat with AI"""
123
+ conversation_prompt = self.conversation.gen_complete_prompt(prompt)
124
+ if optimizer:
125
+ if optimizer in self.__available_optimizers:
126
+ conversation_prompt = getattr(Optimizers, optimizer)(
127
+ conversation_prompt if conversationally else prompt
128
+ )
129
+ else:
130
+ raise Exception(
131
+ f"Optimizer is not one of {self.__available_optimizers}"
132
+ )
133
+
134
+ payload = {
135
+ "id": "guest",
136
+ "messages": [
137
+ {
138
+ "id": str(uuid.uuid4()),
139
+ "createdAt": "2025-03-29T09:13:16.992Z",
140
+ "role": "user",
141
+ "content": conversation_prompt,
142
+ "parts": [{"type": "text", "text": conversation_prompt}]
143
+ }
144
+ ],
145
+ "selectedChatModelId": self.model
146
+ }
147
+
148
+ def for_stream():
149
+ response = self.session.post(
150
+ self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout
151
+ )
152
+ if not response.ok:
153
+ error_msg = f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
154
+ raise exceptions.FailedToGenerateResponseError(error_msg)
155
+
156
+ streaming_response = ""
157
+ for line in response.iter_lines(decode_unicode=True):
158
+ if line:
159
+ match = re.search(r'0:"(.*?)"', line)
160
+ if match:
161
+ content = match.group(1)
162
+ streaming_response += content
163
+ yield content if raw else dict(text=content)
164
+ self.last_response.update(dict(text=streaming_response))
165
+ self.conversation.update_chat_history(
166
+ prompt, self.get_message(self.last_response)
167
+ )
168
+
169
+ def for_non_stream():
170
+ for _ in for_stream():
171
+ pass
172
+ return self.last_response
173
+
174
+ return for_stream() if stream else for_non_stream()
175
+
176
+ def chat(
177
+ self,
178
+ prompt: str,
179
+ stream: bool = False,
180
+ optimizer: str = None,
181
+ conversationally: bool = False,
182
+ ) -> str:
183
+ """Generate response `str`"""
184
+ def for_stream():
185
+ for response in self.ask(
186
+ prompt, True, optimizer=optimizer, conversationally=conversationally
187
+ ):
188
+ yield self.get_message(response)
189
+
190
+ def for_non_stream():
191
+ return self.get_message(
192
+ self.ask(
193
+ prompt,
194
+ False,
195
+ optimizer=optimizer,
196
+ conversationally=conversationally,
197
+ )
198
+ )
199
+
200
+ return for_stream() if stream else for_non_stream()
201
+
202
+ def get_message(self, response: dict) -> str:
203
+ """Retrieves message only from response"""
204
+ assert isinstance(response, dict), "Response should be of dict data-type only"
205
+ return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
206
+
207
+ if __name__ == "__main__":
208
+ print("-" * 80)
209
+ print(f"{'Model':<50} {'Status':<10} {'Response'}")
210
+ print("-" * 80)
211
+
212
+ # Test all available models
213
+ working = 0
214
+ total = len(VercelAI.AVAILABLE_MODELS)
215
+
216
+ for model in VercelAI.AVAILABLE_MODELS:
217
+ try:
218
+ test_ai = VercelAI(model=model, timeout=60)
219
+ response = test_ai.chat("Say 'Hello' in one word", stream=True)
220
+ response_text = ""
221
+ for chunk in response:
222
+ response_text += chunk
223
+ print(f"\r{model:<50} {'Testing...':<10}", end="", flush=True)
224
+
225
+ if response_text and len(response_text.strip()) > 0:
226
+ status = "✓"
227
+ # Truncate response if too long
228
+ display_text = response_text.strip()[:50] + "..." if len(response_text.strip()) > 50 else response_text.strip()
229
+ else:
230
+ status = "✗"
231
+ display_text = "Empty or invalid response"
232
+ print(f"\r{model:<50} {status:<10} {display_text}")
233
+ except Exception as e:
234
+ print(f"\r{model:<50} {'✗':<10} {str(e)}")