webscout 1.4.5__py3-none-any.whl → 2.0__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 +452 -0
- webscout/AIutel.py +3 -1
- webscout/Provider/Blackboxai.py +440 -0
- webscout/Provider/Cohere.py +223 -0
- webscout/Provider/Gemini.py +217 -0
- webscout/Provider/Groq.py +512 -0
- webscout/Provider/Koboldai.py +402 -0
- webscout/Provider/Leo.py +469 -0
- webscout/Provider/Llama2.py +437 -0
- webscout/Provider/OpenGPT.py +487 -0
- webscout/Provider/Openai.py +511 -0
- webscout/Provider/Perplexity.py +230 -0
- webscout/Provider/Phind.py +518 -0
- webscout/Provider/Reka.py +226 -0
- webscout/Provider/ThinkAnyAI.py +280 -0
- webscout/Provider/Xjai.py +230 -0
- webscout/Provider/Yepchat.py +478 -0
- webscout/Provider/Youchat.py +221 -0
- webscout/Provider/__init__.py +57 -0
- webscout/__init__.py +79 -9
- webscout/async_providers.py +1 -11
- webscout/exceptions.py +5 -0
- webscout/version.py +1 -1
- webscout/webai.py +59 -24
- webscout/webscout_search.py +2 -8
- {webscout-1.4.5.dist-info → webscout-2.0.dist-info}/METADATA +293 -40
- webscout-2.0.dist-info/RECORD +55 -0
- webscout/AI.py +0 -5532
- webscout-1.4.5.dist-info/RECORD +0 -38
- {webscout-1.4.5.dist-info → webscout-2.0.dist-info}/LICENSE.md +0 -0
- {webscout-1.4.5.dist-info → webscout-2.0.dist-info}/WHEEL +0 -0
- {webscout-1.4.5.dist-info → webscout-2.0.dist-info}/entry_points.txt +0 -0
- {webscout-1.4.5.dist-info → webscout-2.0.dist-info}/top_level.txt +0 -0
webscout/AIauto.py
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
from webscout.AI import Provider, AsyncProvider
|
|
2
|
+
from webscout.AI import OPENGPT, AsyncOPENGPT
|
|
3
|
+
from webscout.AI import KOBOLDAI, AsyncKOBOLDAI
|
|
4
|
+
from webscout.AI import PhindSearch, AsyncPhindSearch
|
|
5
|
+
from webscout.AI import LLAMA2, AsyncLLAMA2
|
|
6
|
+
from webscout.AI import BLACKBOXAI, AsyncBLACKBOXAI
|
|
7
|
+
from webscout.AI import PERPLEXITY
|
|
8
|
+
from webscout.AI import ThinkAnyAI
|
|
9
|
+
from webscout.AI import YouChat
|
|
10
|
+
from webscout.AI import YEPCHAT
|
|
11
|
+
from webscout.g4f import GPT4FREE, AsyncGPT4FREE
|
|
12
|
+
from webscout.g4f import TestProviders
|
|
13
|
+
from webscout.exceptions import AllProvidersFailure
|
|
14
|
+
from webscout.async_providers import mapper as async_provider_map
|
|
15
|
+
from typing import AsyncGenerator
|
|
16
|
+
|
|
17
|
+
from typing import Union
|
|
18
|
+
from typing import Any
|
|
19
|
+
import logging
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
provider_map: dict[
|
|
23
|
+
str, Union[OPENGPT, KOBOLDAI, PhindSearch, LLAMA2, BLACKBOXAI, PERPLEXITY, GPT4FREE, ThinkAnyAI, YEPCHAT, YouChat]
|
|
24
|
+
] = {
|
|
25
|
+
"PhindSearch": PhindSearch,
|
|
26
|
+
"perplexity": PERPLEXITY,
|
|
27
|
+
"opengpt": OPENGPT,
|
|
28
|
+
"koboldai": KOBOLDAI,
|
|
29
|
+
"llama2": LLAMA2,
|
|
30
|
+
"blackboxai": BLACKBOXAI,
|
|
31
|
+
"gpt4free": GPT4FREE,
|
|
32
|
+
"thinkany": ThinkAnyAI,
|
|
33
|
+
"yepchat": YEPCHAT,
|
|
34
|
+
"you": YouChat,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class AUTO(Provider):
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
is_conversation: bool = True,
|
|
42
|
+
max_tokens: int = 600,
|
|
43
|
+
timeout: int = 30,
|
|
44
|
+
intro: str = None,
|
|
45
|
+
filepath: str = None,
|
|
46
|
+
update_file: bool = True,
|
|
47
|
+
proxies: dict = {},
|
|
48
|
+
history_offset: int = 10250,
|
|
49
|
+
act: str = None,
|
|
50
|
+
exclude: list[str] = [],
|
|
51
|
+
):
|
|
52
|
+
"""Instantiates AUTO
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True
|
|
56
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
57
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
58
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
59
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
60
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
61
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
62
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
63
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
64
|
+
exclude(list[str], optional): List of providers to be excluded. Defaults to [].
|
|
65
|
+
"""
|
|
66
|
+
self.provider: Union[OPENGPT, KOBOLDAI, PhindSearch, LLAMA2, BLACKBOXAI, PERPLEXITY, GPT4FREE, ThinkAnyAI, YEPCHAT, YouChat] = None
|
|
67
|
+
self.provider_name: str = None
|
|
68
|
+
self.is_conversation = is_conversation
|
|
69
|
+
self.max_tokens = max_tokens
|
|
70
|
+
self.timeout = timeout
|
|
71
|
+
self.intro = intro
|
|
72
|
+
self.filepath = filepath
|
|
73
|
+
self.update_file = update_file
|
|
74
|
+
self.proxies = proxies
|
|
75
|
+
self.history_offset = history_offset
|
|
76
|
+
self.act = act
|
|
77
|
+
self.exclude = exclude
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def last_response(self) -> dict[str, Any]:
|
|
81
|
+
return self.provider.last_response
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def conversation(self) -> object:
|
|
85
|
+
return self.provider.conversation
|
|
86
|
+
|
|
87
|
+
def ask(
|
|
88
|
+
self,
|
|
89
|
+
prompt: str,
|
|
90
|
+
stream: bool = False,
|
|
91
|
+
raw: bool = False,
|
|
92
|
+
optimizer: str = None,
|
|
93
|
+
conversationally: bool = False,
|
|
94
|
+
run_new_test: bool = False,
|
|
95
|
+
) -> dict:
|
|
96
|
+
"""Chat with AI
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
prompt (str): Prompt to be send.
|
|
100
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
101
|
+
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
102
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
103
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
104
|
+
run_new_test (bool, optional): Perform new test on g4f-based providers. Defaults to False.
|
|
105
|
+
Returns:
|
|
106
|
+
dict : {}
|
|
107
|
+
"""
|
|
108
|
+
ask_kwargs: dict[str, Union[str, bool]] = {
|
|
109
|
+
"prompt": prompt,
|
|
110
|
+
"stream": stream,
|
|
111
|
+
"raw": raw,
|
|
112
|
+
"optimizer": optimizer,
|
|
113
|
+
"conversationally": conversationally,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# tgpt-based providers
|
|
117
|
+
for provider_name, provider_obj in provider_map.items():
|
|
118
|
+
# continue
|
|
119
|
+
if provider_name in self.exclude:
|
|
120
|
+
continue
|
|
121
|
+
try:
|
|
122
|
+
self.provider_name = f"tgpt-{provider_name}"
|
|
123
|
+
self.provider = provider_obj(
|
|
124
|
+
is_conversation=self.is_conversation,
|
|
125
|
+
max_tokens=self.max_tokens,
|
|
126
|
+
timeout=self.timeout,
|
|
127
|
+
intro=self.intro,
|
|
128
|
+
filepath=self.filepath,
|
|
129
|
+
update_file=self.update_file,
|
|
130
|
+
proxies=self.proxies,
|
|
131
|
+
history_offset=self.history_offset,
|
|
132
|
+
act=self.act,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def for_stream():
|
|
136
|
+
for chunk in self.provider.ask(**ask_kwargs):
|
|
137
|
+
yield chunk
|
|
138
|
+
|
|
139
|
+
def for_non_stream():
|
|
140
|
+
return self.provider.ask(**ask_kwargs)
|
|
141
|
+
|
|
142
|
+
return for_stream() if stream else for_non_stream()
|
|
143
|
+
|
|
144
|
+
except Exception as e:
|
|
145
|
+
logging.debug(
|
|
146
|
+
f"Failed to generate response using provider {provider_name} - {e}"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# g4f-based providers
|
|
150
|
+
|
|
151
|
+
for provider_info in TestProviders(timeout=self.timeout).get_results(
|
|
152
|
+
run=run_new_test
|
|
153
|
+
):
|
|
154
|
+
if provider_info["name"] in self.exclude:
|
|
155
|
+
continue
|
|
156
|
+
try:
|
|
157
|
+
self.provider_name = f"g4f-{provider_info['name']}"
|
|
158
|
+
self.provider = GPT4FREE(
|
|
159
|
+
provider=provider_info["name"],
|
|
160
|
+
is_conversation=self.is_conversation,
|
|
161
|
+
max_tokens=self.max_tokens,
|
|
162
|
+
intro=self.intro,
|
|
163
|
+
filepath=self.filepath,
|
|
164
|
+
update_file=self.update_file,
|
|
165
|
+
proxies=self.proxies,
|
|
166
|
+
history_offset=self.history_offset,
|
|
167
|
+
act=self.act,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def for_stream():
|
|
171
|
+
for chunk in self.provider.ask(**ask_kwargs):
|
|
172
|
+
yield chunk
|
|
173
|
+
|
|
174
|
+
def for_non_stream():
|
|
175
|
+
return self.provider.ask(**ask_kwargs)
|
|
176
|
+
|
|
177
|
+
return for_stream() if stream else for_non_stream()
|
|
178
|
+
|
|
179
|
+
except Exception as e:
|
|
180
|
+
logging.debug(
|
|
181
|
+
f"Failed to generate response using GPT4FREE-base provider {provider_name} - {e}"
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
raise AllProvidersFailure(
|
|
185
|
+
"None of the providers generated response successfully."
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
def chat(
|
|
189
|
+
self,
|
|
190
|
+
prompt: str,
|
|
191
|
+
stream: bool = False,
|
|
192
|
+
optimizer: str = None,
|
|
193
|
+
conversationally: bool = False,
|
|
194
|
+
run_new_test: bool = False,
|
|
195
|
+
) -> str:
|
|
196
|
+
"""Generate response `str`
|
|
197
|
+
Args:
|
|
198
|
+
prompt (str): Prompt to be send.
|
|
199
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
200
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
201
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
202
|
+
run_new_test (bool, optional): Perform new test on g4f-based providers. Defaults to False.
|
|
203
|
+
Returns:
|
|
204
|
+
str: Response generated
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
def for_stream():
|
|
208
|
+
for response in self.ask(
|
|
209
|
+
prompt,
|
|
210
|
+
True,
|
|
211
|
+
optimizer=optimizer,
|
|
212
|
+
conversationally=conversationally,
|
|
213
|
+
run_new_test=run_new_test,
|
|
214
|
+
):
|
|
215
|
+
yield self.get_message(response)
|
|
216
|
+
|
|
217
|
+
def for_non_stream():
|
|
218
|
+
ask_response = self.ask(
|
|
219
|
+
prompt,
|
|
220
|
+
False,
|
|
221
|
+
optimizer=optimizer,
|
|
222
|
+
conversationally=conversationally,
|
|
223
|
+
run_new_test=run_new_test,
|
|
224
|
+
)
|
|
225
|
+
return self.get_message(ask_response)
|
|
226
|
+
|
|
227
|
+
return for_stream() if stream else for_non_stream()
|
|
228
|
+
|
|
229
|
+
def get_message(self, response: dict) -> str:
|
|
230
|
+
"""Retrieves message only from response
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
response (dict): Response generated by `self.ask`
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
str: Message extracted
|
|
237
|
+
"""
|
|
238
|
+
assert self.provider is not None, "Chat with AI first"
|
|
239
|
+
return self.provider.get_message(response)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class AsyncAUTO(AsyncProvider):
|
|
243
|
+
def __init__(
|
|
244
|
+
self,
|
|
245
|
+
is_conversation: bool = True,
|
|
246
|
+
max_tokens: int = 600,
|
|
247
|
+
timeout: int = 30,
|
|
248
|
+
intro: str = None,
|
|
249
|
+
filepath: str = None,
|
|
250
|
+
update_file: bool = True,
|
|
251
|
+
proxies: dict = {},
|
|
252
|
+
history_offset: int = 10250,
|
|
253
|
+
act: str = None,
|
|
254
|
+
exclude: list[str] = [],
|
|
255
|
+
):
|
|
256
|
+
"""Instantiates AsyncAUTO
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True
|
|
260
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
261
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
262
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
263
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
264
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
265
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
266
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
267
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
268
|
+
exclude(list[str], optional): List of providers to be excluded. Defaults to [].
|
|
269
|
+
"""
|
|
270
|
+
self.provider: Union[
|
|
271
|
+
AsyncOPENGPT,
|
|
272
|
+
AsyncKOBOLDAI,
|
|
273
|
+
AsyncPhindSearch,
|
|
274
|
+
AsyncLLAMA2,
|
|
275
|
+
AsyncBLACKBOXAI,
|
|
276
|
+
AsyncGPT4FREE,
|
|
277
|
+
] = None
|
|
278
|
+
self.provider_name: str = None
|
|
279
|
+
self.is_conversation = is_conversation
|
|
280
|
+
self.max_tokens = max_tokens
|
|
281
|
+
self.timeout = timeout
|
|
282
|
+
self.intro = intro
|
|
283
|
+
self.filepath = filepath
|
|
284
|
+
self.update_file = update_file
|
|
285
|
+
self.proxies = proxies
|
|
286
|
+
self.history_offset = history_offset
|
|
287
|
+
self.act = act
|
|
288
|
+
self.exclude = exclude
|
|
289
|
+
|
|
290
|
+
@property
|
|
291
|
+
def last_response(self) -> dict[str, Any]:
|
|
292
|
+
return self.provider.last_response
|
|
293
|
+
|
|
294
|
+
@property
|
|
295
|
+
def conversation(self) -> object:
|
|
296
|
+
return self.provider.conversation
|
|
297
|
+
|
|
298
|
+
async def ask(
|
|
299
|
+
self,
|
|
300
|
+
prompt: str,
|
|
301
|
+
stream: bool = False,
|
|
302
|
+
raw: bool = False,
|
|
303
|
+
optimizer: str = None,
|
|
304
|
+
conversationally: bool = False,
|
|
305
|
+
run_new_test: bool = False,
|
|
306
|
+
) -> dict | AsyncGenerator:
|
|
307
|
+
"""Chat with AI asynchronously.
|
|
308
|
+
|
|
309
|
+
Args:
|
|
310
|
+
prompt (str): Prompt to be send.
|
|
311
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
312
|
+
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
313
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
314
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
315
|
+
run_new_test (bool, optional): Perform new test on g4f-based providers. Defaults to False.
|
|
316
|
+
Returns:
|
|
317
|
+
dict|AsyncGenerator : ai response.
|
|
318
|
+
"""
|
|
319
|
+
ask_kwargs: dict[str, Union[str, bool]] = {
|
|
320
|
+
"prompt": prompt,
|
|
321
|
+
"stream": stream,
|
|
322
|
+
"raw": raw,
|
|
323
|
+
"optimizer": optimizer,
|
|
324
|
+
"conversationally": conversationally,
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
# tgpt-based providers
|
|
328
|
+
for provider_name, provider_obj in async_provider_map.items():
|
|
329
|
+
if provider_name in self.exclude:
|
|
330
|
+
continue
|
|
331
|
+
try:
|
|
332
|
+
self.provider_name = f"tgpt-{provider_name}"
|
|
333
|
+
self.provider = provider_obj(
|
|
334
|
+
is_conversation=self.is_conversation,
|
|
335
|
+
max_tokens=self.max_tokens,
|
|
336
|
+
timeout=self.timeout,
|
|
337
|
+
intro=self.intro,
|
|
338
|
+
filepath=self.filepath,
|
|
339
|
+
update_file=self.update_file,
|
|
340
|
+
proxies=self.proxies,
|
|
341
|
+
history_offset=self.history_offset,
|
|
342
|
+
act=self.act,
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
async def for_stream():
|
|
346
|
+
async_ask = await self.provider.ask(**ask_kwargs)
|
|
347
|
+
async for chunk in async_ask:
|
|
348
|
+
yield chunk
|
|
349
|
+
|
|
350
|
+
async def for_non_stream():
|
|
351
|
+
return await self.provider.ask(**ask_kwargs)
|
|
352
|
+
|
|
353
|
+
return for_stream() if stream else await for_non_stream()
|
|
354
|
+
|
|
355
|
+
except Exception as e:
|
|
356
|
+
logging.debug(
|
|
357
|
+
f"Failed to generate response using provider {provider_name} - {e}"
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
# g4f-based providers
|
|
361
|
+
|
|
362
|
+
for provider_info in TestProviders(timeout=self.timeout).get_results(
|
|
363
|
+
run=run_new_test
|
|
364
|
+
):
|
|
365
|
+
if provider_info["name"] in self.exclude:
|
|
366
|
+
continue
|
|
367
|
+
try:
|
|
368
|
+
self.provider_name = f"g4f-{provider_info['name']}"
|
|
369
|
+
self.provider = AsyncGPT4FREE(
|
|
370
|
+
provider=provider_info["name"],
|
|
371
|
+
is_conversation=self.is_conversation,
|
|
372
|
+
max_tokens=self.max_tokens,
|
|
373
|
+
intro=self.intro,
|
|
374
|
+
filepath=self.filepath,
|
|
375
|
+
update_file=self.update_file,
|
|
376
|
+
proxies=self.proxies,
|
|
377
|
+
history_offset=self.history_offset,
|
|
378
|
+
act=self.act,
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
async def for_stream():
|
|
382
|
+
async_ask = await self.provider.ask(**ask_kwargs)
|
|
383
|
+
async for chunk in async_ask:
|
|
384
|
+
yield chunk
|
|
385
|
+
|
|
386
|
+
async def for_non_stream():
|
|
387
|
+
return await self.provider.ask(**ask_kwargs)
|
|
388
|
+
|
|
389
|
+
return for_stream() if stream else await for_non_stream()
|
|
390
|
+
|
|
391
|
+
except Exception as e:
|
|
392
|
+
logging.debug(
|
|
393
|
+
f"Failed to generate response using GPT4FREE-base provider {provider_name} - {e}"
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
raise AllProvidersFailure(
|
|
397
|
+
"None of the providers generated response successfully."
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
async def chat(
|
|
401
|
+
self,
|
|
402
|
+
prompt: str,
|
|
403
|
+
stream: bool = False,
|
|
404
|
+
optimizer: str = None,
|
|
405
|
+
conversationally: bool = False,
|
|
406
|
+
run_new_test: bool = False,
|
|
407
|
+
) -> str | AsyncGenerator:
|
|
408
|
+
"""Generate response `str` asynchronously.
|
|
409
|
+
Args:
|
|
410
|
+
prompt (str): Prompt to be send.
|
|
411
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
412
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
413
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
414
|
+
run_new_test (bool, optional): Perform new test on g4f-based providers. Defaults to False.
|
|
415
|
+
Returns:
|
|
416
|
+
str|AsyncGenerator: Response generated
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
async def for_stream():
|
|
420
|
+
async_ask = await self.ask(
|
|
421
|
+
prompt,
|
|
422
|
+
True,
|
|
423
|
+
optimizer=optimizer,
|
|
424
|
+
conversationally=conversationally,
|
|
425
|
+
run_new_test=run_new_test,
|
|
426
|
+
)
|
|
427
|
+
async for response in async_ask:
|
|
428
|
+
yield await self.get_message(response)
|
|
429
|
+
|
|
430
|
+
async def for_non_stream():
|
|
431
|
+
ask_response = await self.ask(
|
|
432
|
+
prompt,
|
|
433
|
+
False,
|
|
434
|
+
optimizer=optimizer,
|
|
435
|
+
conversationally=conversationally,
|
|
436
|
+
run_new_test=run_new_test,
|
|
437
|
+
)
|
|
438
|
+
return await self.get_message(ask_response)
|
|
439
|
+
|
|
440
|
+
return for_stream() if stream else await for_non_stream()
|
|
441
|
+
|
|
442
|
+
async def get_message(self, response: dict) -> str:
|
|
443
|
+
"""Retrieves message only from response
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
response (dict): Response generated by `self.ask`
|
|
447
|
+
|
|
448
|
+
Returns:
|
|
449
|
+
str: Message extracted
|
|
450
|
+
"""
|
|
451
|
+
assert self.provider is not None, "Chat with AI first"
|
|
452
|
+
return await self.provider.get_message(response)
|