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.
Files changed (184) hide show
  1. webscout/AIauto.py +32 -14
  2. webscout/AIbase.py +96 -37
  3. webscout/AIutel.py +491 -87
  4. webscout/Bard.py +441 -323
  5. webscout/Extra/GitToolkit/__init__.py +10 -10
  6. webscout/Extra/YTToolkit/ytapi/video.py +232 -232
  7. webscout/Litlogger/README.md +10 -0
  8. webscout/Litlogger/__init__.py +7 -59
  9. webscout/Litlogger/formats.py +4 -0
  10. webscout/Litlogger/handlers.py +103 -0
  11. webscout/Litlogger/levels.py +13 -0
  12. webscout/Litlogger/logger.py +92 -0
  13. webscout/Provider/AISEARCH/Perplexity.py +332 -358
  14. webscout/Provider/AISEARCH/felo_search.py +9 -35
  15. webscout/Provider/AISEARCH/genspark_search.py +30 -56
  16. webscout/Provider/AISEARCH/hika_search.py +4 -16
  17. webscout/Provider/AISEARCH/iask_search.py +410 -436
  18. webscout/Provider/AISEARCH/monica_search.py +4 -30
  19. webscout/Provider/AISEARCH/scira_search.py +6 -32
  20. webscout/Provider/AISEARCH/webpilotai_search.py +38 -64
  21. webscout/Provider/Blackboxai.py +153 -35
  22. webscout/Provider/Deepinfra.py +339 -339
  23. webscout/Provider/ExaChat.py +358 -358
  24. webscout/Provider/Gemini.py +169 -169
  25. webscout/Provider/GithubChat.py +1 -2
  26. webscout/Provider/Glider.py +3 -3
  27. webscout/Provider/HeckAI.py +171 -81
  28. webscout/Provider/OPENAI/BLACKBOXAI.py +766 -735
  29. webscout/Provider/OPENAI/Cloudflare.py +7 -7
  30. webscout/Provider/OPENAI/FreeGemini.py +6 -5
  31. webscout/Provider/OPENAI/NEMOTRON.py +8 -20
  32. webscout/Provider/OPENAI/Qwen3.py +283 -0
  33. webscout/Provider/OPENAI/README.md +952 -1253
  34. webscout/Provider/OPENAI/TwoAI.py +357 -0
  35. webscout/Provider/OPENAI/__init__.py +5 -1
  36. webscout/Provider/OPENAI/ai4chat.py +40 -40
  37. webscout/Provider/OPENAI/api.py +808 -649
  38. webscout/Provider/OPENAI/c4ai.py +3 -3
  39. webscout/Provider/OPENAI/chatgpt.py +555 -555
  40. webscout/Provider/OPENAI/chatgptclone.py +493 -487
  41. webscout/Provider/OPENAI/chatsandbox.py +4 -3
  42. webscout/Provider/OPENAI/copilot.py +242 -0
  43. webscout/Provider/OPENAI/deepinfra.py +5 -2
  44. webscout/Provider/OPENAI/e2b.py +63 -5
  45. webscout/Provider/OPENAI/exaai.py +416 -410
  46. webscout/Provider/OPENAI/exachat.py +444 -443
  47. webscout/Provider/OPENAI/freeaichat.py +2 -2
  48. webscout/Provider/OPENAI/glider.py +5 -2
  49. webscout/Provider/OPENAI/groq.py +5 -2
  50. webscout/Provider/OPENAI/heckai.py +308 -307
  51. webscout/Provider/OPENAI/mcpcore.py +8 -2
  52. webscout/Provider/OPENAI/multichat.py +4 -4
  53. webscout/Provider/OPENAI/netwrck.py +6 -5
  54. webscout/Provider/OPENAI/oivscode.py +287 -0
  55. webscout/Provider/OPENAI/opkfc.py +496 -496
  56. webscout/Provider/OPENAI/pydantic_imports.py +172 -0
  57. webscout/Provider/OPENAI/scirachat.py +15 -9
  58. webscout/Provider/OPENAI/sonus.py +304 -303
  59. webscout/Provider/OPENAI/standardinput.py +433 -433
  60. webscout/Provider/OPENAI/textpollinations.py +4 -4
  61. webscout/Provider/OPENAI/toolbaz.py +413 -413
  62. webscout/Provider/OPENAI/typefully.py +3 -3
  63. webscout/Provider/OPENAI/typegpt.py +11 -5
  64. webscout/Provider/OPENAI/uncovrAI.py +463 -462
  65. webscout/Provider/OPENAI/utils.py +90 -79
  66. webscout/Provider/OPENAI/venice.py +431 -425
  67. webscout/Provider/OPENAI/wisecat.py +387 -381
  68. webscout/Provider/OPENAI/writecream.py +3 -3
  69. webscout/Provider/OPENAI/x0gpt.py +365 -378
  70. webscout/Provider/OPENAI/yep.py +39 -13
  71. webscout/Provider/TTI/README.md +55 -101
  72. webscout/Provider/TTI/__init__.py +4 -9
  73. webscout/Provider/TTI/aiarta.py +365 -0
  74. webscout/Provider/TTI/artbit.py +0 -0
  75. webscout/Provider/TTI/base.py +64 -0
  76. webscout/Provider/TTI/fastflux.py +200 -0
  77. webscout/Provider/TTI/magicstudio.py +201 -0
  78. webscout/Provider/TTI/piclumen.py +203 -0
  79. webscout/Provider/TTI/pixelmuse.py +225 -0
  80. webscout/Provider/TTI/pollinations.py +221 -0
  81. webscout/Provider/TTI/utils.py +11 -0
  82. webscout/Provider/TTS/__init__.py +2 -1
  83. webscout/Provider/TTS/base.py +159 -159
  84. webscout/Provider/TTS/openai_fm.py +129 -0
  85. webscout/Provider/TextPollinationsAI.py +308 -308
  86. webscout/Provider/TwoAI.py +239 -44
  87. webscout/Provider/UNFINISHED/Youchat.py +330 -330
  88. webscout/Provider/UNFINISHED/puterjs.py +635 -0
  89. webscout/Provider/UNFINISHED/test_lmarena.py +119 -119
  90. webscout/Provider/Writecream.py +246 -246
  91. webscout/Provider/__init__.py +2 -0
  92. webscout/Provider/ai4chat.py +33 -8
  93. webscout/Provider/koala.py +169 -169
  94. webscout/Provider/oivscode.py +309 -0
  95. webscout/Provider/samurai.py +3 -2
  96. webscout/Provider/typegpt.py +3 -3
  97. webscout/Provider/uncovr.py +368 -368
  98. webscout/client.py +70 -0
  99. webscout/litprinter/__init__.py +58 -58
  100. webscout/optimizers.py +419 -419
  101. webscout/scout/README.md +3 -1
  102. webscout/scout/core/crawler.py +134 -64
  103. webscout/scout/core/scout.py +148 -109
  104. webscout/scout/element.py +106 -88
  105. webscout/swiftcli/Readme.md +323 -323
  106. webscout/swiftcli/plugins/manager.py +9 -2
  107. webscout/version.py +1 -1
  108. webscout/zeroart/__init__.py +134 -134
  109. webscout/zeroart/effects.py +100 -100
  110. webscout/zeroart/fonts.py +1238 -1238
  111. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/METADATA +159 -35
  112. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/RECORD +116 -161
  113. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/WHEEL +1 -1
  114. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/entry_points.txt +1 -0
  115. webscout/Litlogger/Readme.md +0 -175
  116. webscout/Litlogger/core/__init__.py +0 -6
  117. webscout/Litlogger/core/level.py +0 -23
  118. webscout/Litlogger/core/logger.py +0 -165
  119. webscout/Litlogger/handlers/__init__.py +0 -12
  120. webscout/Litlogger/handlers/console.py +0 -33
  121. webscout/Litlogger/handlers/file.py +0 -143
  122. webscout/Litlogger/handlers/network.py +0 -173
  123. webscout/Litlogger/styles/__init__.py +0 -7
  124. webscout/Litlogger/styles/colors.py +0 -249
  125. webscout/Litlogger/styles/formats.py +0 -458
  126. webscout/Litlogger/styles/text.py +0 -87
  127. webscout/Litlogger/utils/__init__.py +0 -6
  128. webscout/Litlogger/utils/detectors.py +0 -153
  129. webscout/Litlogger/utils/formatters.py +0 -200
  130. webscout/Provider/TTI/AiForce/README.md +0 -159
  131. webscout/Provider/TTI/AiForce/__init__.py +0 -22
  132. webscout/Provider/TTI/AiForce/async_aiforce.py +0 -224
  133. webscout/Provider/TTI/AiForce/sync_aiforce.py +0 -245
  134. webscout/Provider/TTI/FreeAIPlayground/README.md +0 -99
  135. webscout/Provider/TTI/FreeAIPlayground/__init__.py +0 -9
  136. webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +0 -181
  137. webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +0 -180
  138. webscout/Provider/TTI/ImgSys/README.md +0 -174
  139. webscout/Provider/TTI/ImgSys/__init__.py +0 -23
  140. webscout/Provider/TTI/ImgSys/async_imgsys.py +0 -202
  141. webscout/Provider/TTI/ImgSys/sync_imgsys.py +0 -195
  142. webscout/Provider/TTI/MagicStudio/README.md +0 -101
  143. webscout/Provider/TTI/MagicStudio/__init__.py +0 -2
  144. webscout/Provider/TTI/MagicStudio/async_magicstudio.py +0 -111
  145. webscout/Provider/TTI/MagicStudio/sync_magicstudio.py +0 -109
  146. webscout/Provider/TTI/Nexra/README.md +0 -155
  147. webscout/Provider/TTI/Nexra/__init__.py +0 -22
  148. webscout/Provider/TTI/Nexra/async_nexra.py +0 -286
  149. webscout/Provider/TTI/Nexra/sync_nexra.py +0 -258
  150. webscout/Provider/TTI/PollinationsAI/README.md +0 -146
  151. webscout/Provider/TTI/PollinationsAI/__init__.py +0 -23
  152. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +0 -311
  153. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +0 -265
  154. webscout/Provider/TTI/aiarta/README.md +0 -134
  155. webscout/Provider/TTI/aiarta/__init__.py +0 -2
  156. webscout/Provider/TTI/aiarta/async_aiarta.py +0 -482
  157. webscout/Provider/TTI/aiarta/sync_aiarta.py +0 -440
  158. webscout/Provider/TTI/artbit/README.md +0 -100
  159. webscout/Provider/TTI/artbit/__init__.py +0 -22
  160. webscout/Provider/TTI/artbit/async_artbit.py +0 -155
  161. webscout/Provider/TTI/artbit/sync_artbit.py +0 -148
  162. webscout/Provider/TTI/fastflux/README.md +0 -129
  163. webscout/Provider/TTI/fastflux/__init__.py +0 -22
  164. webscout/Provider/TTI/fastflux/async_fastflux.py +0 -261
  165. webscout/Provider/TTI/fastflux/sync_fastflux.py +0 -252
  166. webscout/Provider/TTI/huggingface/README.md +0 -114
  167. webscout/Provider/TTI/huggingface/__init__.py +0 -22
  168. webscout/Provider/TTI/huggingface/async_huggingface.py +0 -199
  169. webscout/Provider/TTI/huggingface/sync_huggingface.py +0 -195
  170. webscout/Provider/TTI/piclumen/README.md +0 -161
  171. webscout/Provider/TTI/piclumen/__init__.py +0 -23
  172. webscout/Provider/TTI/piclumen/async_piclumen.py +0 -268
  173. webscout/Provider/TTI/piclumen/sync_piclumen.py +0 -233
  174. webscout/Provider/TTI/pixelmuse/README.md +0 -79
  175. webscout/Provider/TTI/pixelmuse/__init__.py +0 -4
  176. webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +0 -249
  177. webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +0 -182
  178. webscout/Provider/TTI/talkai/README.md +0 -139
  179. webscout/Provider/TTI/talkai/__init__.py +0 -4
  180. webscout/Provider/TTI/talkai/async_talkai.py +0 -229
  181. webscout/Provider/TTI/talkai/sync_talkai.py +0 -207
  182. webscout/Provider/UNFINISHED/oivscode.py +0 -351
  183. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/licenses/LICENSE.md +0 -0
  184. {webscout-8.2.8.dist-info → webscout-8.2.9.dist-info}/top_level.txt +0 -0
@@ -1,351 +0,0 @@
1
- ############################################################
2
- # NOT WORKING
3
- ############################################################
4
-
5
- import requests
6
- import json
7
- from typing import Union, Any, Dict, Optional, Generator
8
-
9
- from webscout.AIutel import Optimizers
10
- from webscout.AIutel import Conversation
11
- from webscout.AIutel import AwesomePrompts
12
- from webscout.AIbase import Provider
13
- from webscout import exceptions
14
-
15
-
16
- class oivscode(Provider):
17
- """
18
- A class to interact with a test API.
19
- """
20
- AVAILABLE_MODELS = [
21
- "deepseek/deepseek-chat",
22
- "claude-3-5-haiku-20241022",
23
- "gpt-4o-mini",
24
- "claude-3-5-sonnet-20240620",
25
- "ours/deepseek-chat",
26
- "custom/deepseek",
27
- "Qwen/Qwen2.5-72B-Instruct-Turbo",
28
- "Qwen/Qwen2.5-Coder-32B-Instruct",
29
- "claude-3-5-sonnet-20241022",
30
- "omni-moderation-latest",
31
- "omni-moderation-latest-intents",
32
- "omni-moderation-2024-09-26",
33
- "gpt-4",
34
- "gpt-4o",
35
- "gpt-4o-audio-preview",
36
- "gpt-4o-audio-preview-2024-12-17",
37
- "gpt-4o-audio-preview-2024-10-01",
38
- "gpt-4o-mini-audio-preview-2024-12-17",
39
- "gpt-4o-mini",
40
- "gpt-4o-mini-2024-07-18",
41
- "o1",
42
- "o1-mini",
43
- "o1-mini-2024-09-12",
44
- "o1-preview",
45
- "o1-preview-2024-09-12",
46
- "o1-2024-12-17",
47
- "chatgpt-4o-latest",
48
- "gpt-4o-2024-05-13",
49
- "gpt-4o-2024-08-06",
50
- "gpt-4o-2024-11-20",
51
- "gpt-4o-realtime-preview-2024-10-01",
52
- "gpt-4o-realtime-preview",
53
- "gpt-4o-realtime-preview-2024-12-17",
54
- "gpt-4o-mini-realtime-preview",
55
- "gpt-4o-mini-realtime-preview-2024-12-17",
56
- "gpt-4-turbo-preview",
57
- "gpt-4-0314",
58
- "gpt-4-0613",
59
- "gpt-4-32k",
60
- "gpt-4-32k-0314",
61
- "gpt-4-32k-0613",
62
- "gpt-4-turbo",
63
- "gpt-4-turbo-2024-04-09",
64
- "gpt-4-1106-preview",
65
- "gpt-4-0125-preview",
66
- "gpt-4-vision-preview",
67
- "gpt-4-1106-vision-preview",
68
- "gpt-3.5-turbo",
69
- "gpt-3.5-turbo-0301",
70
- "gpt-3.5-turbo-0613",
71
- "gpt-3.5-turbo-1106",
72
- "gpt-3.5-turbo-0125",
73
- "gpt-3.5-turbo-16k",
74
- "gpt-3.5-turbo-16k-0613",
75
- "text-embedding-3-large",
76
- "text-embedding-3-small",
77
- "text-embedding-ada-002",
78
- "text-embedding-ada-002-v2",
79
- "text-moderation-stable",
80
- "text-moderation-007",
81
- "text-moderation-latest",
82
- "256-x-256/dall-e-2",
83
- "512-x-512/dall-e-2",
84
- "1024-x-1024/dall-e-2",
85
- "hd/1024-x-1792/dall-e-3",
86
- "hd/1792-x-1024/dall-e-3",
87
- "hd/1024-x-1024/dall-e-3",
88
- "standard/1024-x-1792/dall-e-3",
89
- "standard/1792-x-1024/dall-e-3",
90
- "standard/1024-x-1024/dall-e-3",
91
- "whisper-1",
92
- "tts-1",
93
- "tts-1-hd",
94
- "ft:davinci-002",
95
- "ft:babbage-002",
96
- "babbage-002",
97
- "davinci-002",
98
- "gpt-3.5-turbo-instruct",
99
- "gpt-3.5-turbo-instruct-0914",
100
- "claude-instant-1",
101
- "claude-instant-1.2",
102
- "claude-2",
103
- "claude-2.1",
104
- "claude-3-haiku-20240307",
105
- "claude-3-5-haiku-20241022",
106
- "claude-3-opus-20240229",
107
- "claude-3-sonnet-20240229",
108
- "claude-3-5-sonnet-20240620",
109
- "claude-3-5-sonnet-20241022",
110
- "togethercomputer/llama-2-70b-chat",
111
- "togethercomputer/llama-2-70b",
112
- "togethercomputer/LLaMA-2-7B-32K",
113
- "togethercomputer/Llama-2-7B-32K-Instruct",
114
- "togethercomputer/llama-2-7b",
115
- "togethercomputer/falcon-40b-instruct",
116
- "togethercomputer/falcon-7b-instruct",
117
- "togethercomputer/alpaca-7b",
118
- "HuggingFaceH4/starchat-alpha",
119
- "togethercomputer/CodeLlama-34b",
120
- "togethercomputer/CodeLlama-34b-Instruct",
121
- "togethercomputer/CodeLlama-34b-Python",
122
- "defog/sqlcoder",
123
- "NumbersStation/nsql-llama-2-7B",
124
- "WizardLM/WizardCoder-15B-V1.0",
125
- "WizardLM/WizardCoder-Python-34B-V1.0",
126
- "NousResearch/Nous-Hermes-Llama2-13b",
127
- "Austism/chronos-hermes-13b",
128
- "upstage/SOLAR-0-70b-16bit",
129
- "WizardLM/WizardLM-70B-V1.0",
130
- "deepseek/deepseek-chat",
131
- "deepseek/deepseek-coder",
132
- "fireworks_ai/accounts/fireworks/models/llama-v3p2-1b-instruct",
133
- "fireworks_ai/accounts/fireworks/models/llama-v3p2-3b-instruct",
134
- "fireworks_ai/accounts/fireworks/models/llama-v3p2-11b-vision-instruct",
135
- "accounts/fireworks/models/llama-v3p2-90b-vision-instruct",
136
- "fireworks_ai/accounts/fireworks/models/firefunction-v2",
137
- "fireworks_ai/accounts/fireworks/models/mixtral-8x22b-instruct-hf",
138
- "fireworks_ai/accounts/fireworks/models/qwen2-72b-instruct",
139
- "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct",
140
- "fireworks_ai/accounts/fireworks/models/yi-large",
141
- "fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-instruct",
142
- "fireworks_ai/accounts/fireworks/models/deepseek-v3",
143
- "fireworks_ai/nomic-ai/nomic-embed-text-v1.5",
144
- "fireworks_ai/nomic-ai/nomic-embed-text-v1",
145
- "fireworks_ai/WhereIsAI/UAE-Large-V1",
146
- "fireworks_ai/thenlper/gte-large",
147
- "fireworks_ai/thenlper/gte-base",
148
- ]
149
-
150
- def __init__(
151
- self,
152
- is_conversation: bool = True,
153
- max_tokens: int = 1024,
154
- timeout: int = 30,
155
- intro: str = None,
156
- filepath: str = None,
157
- update_file: bool = True,
158
- proxies: dict = {},
159
- history_offset: int = 10250,
160
- act: str = None,
161
- model: str = "claude-3-5-sonnet-20240620",
162
- system_prompt: str = "You are a helpful AI assistant.",
163
-
164
- ):
165
- """
166
- Initializes the oivscode with given parameters.
167
- """
168
- if model not in self.AVAILABLE_MODELS:
169
- raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
170
-
171
-
172
- self.session = requests.Session()
173
- self.is_conversation = is_conversation
174
- self.max_tokens_to_sample = max_tokens
175
- self.api_endpoint = "https://oi-vscode-server.onrender.com/v1/chat/completions"
176
- self.timeout = timeout
177
- self.last_response = {}
178
- self.model = model
179
- self.system_prompt = system_prompt
180
- self.headers = {
181
- "accept": "*/*",
182
- "accept-language": "en-US,en;q=0.9,en-GB;q=0.8,en-IN;q=0.7",
183
- "cache-control": "no-cache",
184
- "content-type": "application/json",
185
- "pragma": "no-cache",
186
- "priority": "u=1, i",
187
- "sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"',
188
- "sec-ch-ua-mobile": "?0",
189
- "sec-ch-ua-platform": '"Windows"',
190
- "sec-fetch-dest": "empty",
191
- "sec-fetch-mode": "cors",
192
- "sec-fetch-site": "same-site"
193
- }
194
-
195
-
196
- self.__available_optimizers = (
197
- method
198
- for method in dir(Optimizers)
199
- if callable(getattr(Optimizers, method)) and not method.startswith("__")
200
- )
201
- self.session.headers.update(self.headers)
202
- Conversation.intro = (
203
- AwesomePrompts().get_act(
204
- act, raise_not_found=True, default=None, case_insensitive=True
205
- )
206
- if act
207
- else intro or Conversation.intro
208
- )
209
- self.conversation = Conversation(
210
- is_conversation, self.max_tokens_to_sample, filepath, update_file
211
- )
212
- self.conversation.history_offset = history_offset
213
- self.session.proxies = proxies
214
-
215
- def ask(
216
- self,
217
- prompt: str,
218
- stream: bool = False,
219
- raw: bool = False,
220
- optimizer: str = None,
221
- conversationally: bool = False,
222
- ) -> Union[Dict[str, Any], Generator[Any, None, None]]:
223
- """Chat with AI
224
-
225
- Args:
226
- prompt (str): Prompt to be send.
227
- stream (bool, optional): Flag for streaming response. Defaults to False.
228
- raw (bool, optional): Stream back raw response as received. Defaults to False.
229
- optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
230
- conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
231
- Returns:
232
- dict or generator:
233
- If stream is False, returns a dict
234
- If stream is True, returns a generator
235
- """
236
- conversation_prompt = self.conversation.gen_complete_prompt(prompt)
237
- if optimizer:
238
- if optimizer in self.__available_optimizers:
239
- conversation_prompt = getattr(Optimizers, optimizer)(
240
- conversation_prompt if conversationally else prompt
241
- )
242
- else:
243
- raise Exception(
244
- f"Optimizer is not one of {self.__available_optimizers}"
245
- )
246
-
247
- payload = {
248
- "model": self.model,
249
- "stream": stream,
250
- "messages": [
251
- {"role": "system", "content": self.system_prompt},
252
- {"role": "user", "content": conversation_prompt}
253
- ]
254
- }
255
-
256
- def for_stream():
257
- response = self.session.post(
258
- self.api_endpoint, json=payload, stream=True, timeout=self.timeout
259
- )
260
- if not response.ok:
261
- raise exceptions.FailedToGenerateResponseError(
262
- f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
263
- )
264
- from rich import print
265
- print(response.text)
266
- message_load = ""
267
- for value in response.iter_lines(
268
- decode_unicode=True,
269
- delimiter="" if raw else "data:",
270
- chunk_size=64,
271
- ):
272
- try:
273
- resp = json.loads(value)
274
- incomplete_message = self.get_message(resp)
275
- if incomplete_message:
276
- message_load += incomplete_message
277
- resp["choices"][0]["delta"]["content"] = message_load
278
- self.last_response.update(resp)
279
- yield value if raw else resp
280
- elif raw:
281
- yield value
282
- except json.decoder.JSONDecodeError:
283
- pass
284
- self.conversation.update_chat_history(
285
- prompt, self.get_message(self.last_response)
286
- )
287
-
288
- def for_non_stream():
289
- response = self.session.post(
290
- self.chat_endpoint, json=payload, stream=False, timeout=self.timeout
291
- )
292
- if (
293
- not response.ok
294
- or not response.headers.get("Content-Type", "") == "application/json"
295
- ):
296
- raise exceptions.FailedToGenerateResponseError(
297
- f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
298
- )
299
- resp = response.json()
300
- self.last_response.update(resp)
301
- self.conversation.update_chat_history(
302
- prompt, self.get_message(self.last_response)
303
- )
304
- return resp
305
-
306
- return for_stream() if stream else for_non_stream()
307
-
308
-
309
- def chat(
310
- self,
311
- prompt: str,
312
- stream: bool = False,
313
- optimizer: str = None,
314
- conversationally: bool = False,
315
- ) -> Union[str, Generator[str, None, None]]:
316
- """Generate response `str`
317
- Args:
318
- prompt (str): Prompt to be send.
319
- stream (bool, optional): Flag for streaming response. Defaults to False.
320
- optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
321
- conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
322
- Returns:
323
- str: Response generated
324
- """
325
- def for_stream():
326
- for response in self.ask(
327
- prompt, True, optimizer=optimizer, conversationally=conversationally
328
- ):
329
- yield self.get_message(response)
330
- def for_non_stream():
331
- return self.get_message(
332
- self.ask(
333
- prompt,
334
- False,
335
- optimizer=optimizer,
336
- conversationally=conversationally,
337
- )
338
- )
339
- return for_stream() if stream else for_non_stream()
340
-
341
- def get_message(self, response: dict) -> str:
342
- """Retrieves message only from response"""
343
- assert isinstance(response, dict), "Response should be of dict data-type only"
344
- return response["text"]
345
-
346
- if __name__ == "__main__":
347
- from rich import print
348
- chatbot = oivscode()
349
- response = chatbot.chat(input(">>> "), stream=True)
350
- for chunk in response:
351
- print(chunk, end="", flush=True)