webscout 4.4__py3-none-any.whl → 4.6__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/AIutel.py +12 -1
- webscout/Agents/Onlinesearcher.py +175 -0
- webscout/Agents/__init__.py +2 -0
- webscout/Agents/functioncall.py +126 -0
- webscout/Extra/gguf.py +1 -1
- webscout/Provider/Andi.py +275 -0
- webscout/Provider/BasedGPT.py +38 -36
- webscout/Provider/Blackboxai.py +14 -10
- webscout/Provider/DARKAI.py +207 -0
- webscout/Provider/Deepseek.py +79 -133
- webscout/Provider/Llama3.py +173 -0
- webscout/Provider/PizzaGPT.py +178 -0
- webscout/Provider/RUBIKSAI.py +201 -0
- webscout/Provider/__init__.py +13 -3
- webscout/Provider/koala.py +239 -0
- webscout/__init__.py +5 -3
- webscout/version.py +1 -1
- webscout/voice.py +8 -1
- webscout/webai.py +28 -1
- webscout/webscout_search.py +1 -0
- webscout/websx_search.py +18 -369
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/METADATA +21 -37
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/RECORD +27 -18
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/WHEEL +1 -1
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/LICENSE.md +0 -0
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/entry_points.txt +0 -0
- {webscout-4.4.dist-info → webscout-4.6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
from webscout.AIutel import Optimizers
|
|
4
|
+
from webscout.AIutel import Conversation
|
|
5
|
+
from webscout.AIutel import AwesomePrompts
|
|
6
|
+
from webscout.AIbase import Provider
|
|
7
|
+
|
|
8
|
+
class LLAMA3(Provider):
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
is_conversation: bool = True,
|
|
12
|
+
max_tokens: int = 600,
|
|
13
|
+
timeout: int = 30,
|
|
14
|
+
intro: str = None,
|
|
15
|
+
filepath: str = None,
|
|
16
|
+
update_file: bool = True,
|
|
17
|
+
proxies: dict = {},
|
|
18
|
+
history_offset: int = 10250,
|
|
19
|
+
act: str = None,
|
|
20
|
+
model: str = "llama3-70b", # model= llama3-70b, llama3-8b, llama3-405b
|
|
21
|
+
system: str = "Answer as concisely as possible.",
|
|
22
|
+
):
|
|
23
|
+
"""Instantiates Snova
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
27
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
28
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
29
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
30
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
31
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
32
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
33
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
34
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
35
|
+
model (str, optional): Snova model name. Defaults to "llama3-70b".
|
|
36
|
+
system (str, optional): System prompt for Snova. Defaults to "Answer as concisely as possible.".
|
|
37
|
+
"""
|
|
38
|
+
self.session = requests.Session()
|
|
39
|
+
self.is_conversation = is_conversation
|
|
40
|
+
self.max_tokens_to_sample = max_tokens
|
|
41
|
+
self.timeout = timeout
|
|
42
|
+
self.model = model
|
|
43
|
+
self.system = system
|
|
44
|
+
self.last_response = {}
|
|
45
|
+
self.env_type = "tp16405b" if "405b" in model else "tp16"
|
|
46
|
+
self.headers = {'content-type': 'application/json'}
|
|
47
|
+
|
|
48
|
+
self.__available_optimizers = (
|
|
49
|
+
method
|
|
50
|
+
for method in dir(Optimizers)
|
|
51
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
52
|
+
)
|
|
53
|
+
self.session.headers.update(self.headers)
|
|
54
|
+
Conversation.intro = (
|
|
55
|
+
AwesomePrompts().get_act(
|
|
56
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
57
|
+
)
|
|
58
|
+
if act
|
|
59
|
+
else intro or Conversation.intro
|
|
60
|
+
)
|
|
61
|
+
self.conversation = Conversation(
|
|
62
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
63
|
+
)
|
|
64
|
+
self.conversation.history_offset = history_offset
|
|
65
|
+
self.session.proxies = proxies
|
|
66
|
+
|
|
67
|
+
def ask(
|
|
68
|
+
self,
|
|
69
|
+
prompt: str,
|
|
70
|
+
stream: bool = False,
|
|
71
|
+
raw: bool = False,
|
|
72
|
+
optimizer: str = None,
|
|
73
|
+
conversationally: bool = False,
|
|
74
|
+
) -> dict:
|
|
75
|
+
"""Chat with AI
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
prompt (str): Prompt to be send.
|
|
79
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
80
|
+
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
81
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
82
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
83
|
+
Returns:
|
|
84
|
+
dict : {}
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"text" : "How may I assist you today?"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
"""
|
|
91
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
92
|
+
if optimizer:
|
|
93
|
+
if optimizer in self.__available_optimizers:
|
|
94
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
95
|
+
conversation_prompt if conversationally else prompt
|
|
96
|
+
)
|
|
97
|
+
else:
|
|
98
|
+
raise Exception(
|
|
99
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
100
|
+
)
|
|
101
|
+
data = {'body': {'messages': [{'role': 'system', 'content': self.system}, {'role': 'user', 'content': conversation_prompt}], 'stream': True, 'model': self.model}, 'env_type': self.env_type}
|
|
102
|
+
|
|
103
|
+
def for_stream(data=data): # Pass data as a default argument
|
|
104
|
+
response = self.session.post('https://fast.snova.ai/api/completion', headers=self.headers, json=data, stream=True, timeout=self.timeout)
|
|
105
|
+
output = ''
|
|
106
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
107
|
+
if line.startswith('data:'):
|
|
108
|
+
try:
|
|
109
|
+
data = json.loads(line[len('data: '):])
|
|
110
|
+
output += data.get("choices", [{}])[0].get("delta", {}).get("content", '')
|
|
111
|
+
self.last_response.update(dict(text=output))
|
|
112
|
+
yield data if raw else dict(text=output)
|
|
113
|
+
except json.JSONDecodeError:
|
|
114
|
+
if line[len('data: '):] == '[DONE]':
|
|
115
|
+
break
|
|
116
|
+
self.conversation.update_chat_history(
|
|
117
|
+
prompt, self.get_message(self.last_response)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def for_non_stream():
|
|
121
|
+
for _ in for_stream():
|
|
122
|
+
pass
|
|
123
|
+
return self.last_response
|
|
124
|
+
|
|
125
|
+
return for_stream() if stream else for_non_stream()
|
|
126
|
+
|
|
127
|
+
def chat(
|
|
128
|
+
self,
|
|
129
|
+
prompt: str,
|
|
130
|
+
stream: bool = False,
|
|
131
|
+
optimizer: str = None,
|
|
132
|
+
conversationally: bool = False,
|
|
133
|
+
) -> str:
|
|
134
|
+
"""Generate response `str`
|
|
135
|
+
Args:
|
|
136
|
+
prompt (str): Prompt to be send.
|
|
137
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
138
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
139
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
140
|
+
Returns:
|
|
141
|
+
str: Response generated
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
def for_stream():
|
|
145
|
+
for response in self.ask(
|
|
146
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
147
|
+
):
|
|
148
|
+
yield self.get_message(response)
|
|
149
|
+
|
|
150
|
+
def for_non_stream():
|
|
151
|
+
return self.get_message(
|
|
152
|
+
self.ask(
|
|
153
|
+
prompt,
|
|
154
|
+
False,
|
|
155
|
+
optimizer=optimizer,
|
|
156
|
+
conversationally=conversationally,
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
return for_stream() if stream else for_non_stream()
|
|
161
|
+
|
|
162
|
+
def get_message(self, response: dict) -> str:
|
|
163
|
+
"""Retrieves message only from response
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
response (dict): Response generated by `self.ask`
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
str: Message extracted
|
|
170
|
+
"""
|
|
171
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
172
|
+
return response["text"]
|
|
173
|
+
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Any, AsyncGenerator, Dict, Optional
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from webscout.AIutel import Optimizers
|
|
6
|
+
from webscout.AIutel import Conversation
|
|
7
|
+
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
8
|
+
from webscout.AIbase import Provider, AsyncProvider
|
|
9
|
+
from webscout import exceptions
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PIZZAGPT(Provider):
|
|
13
|
+
"""
|
|
14
|
+
A class to interact with the PizzaGPT API.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
is_conversation: bool = True,
|
|
20
|
+
max_tokens: int = 600,
|
|
21
|
+
timeout: int = 30,
|
|
22
|
+
intro: str = None,
|
|
23
|
+
filepath: str = None,
|
|
24
|
+
update_file: bool = True,
|
|
25
|
+
proxies: dict = {},
|
|
26
|
+
history_offset: int = 10250,
|
|
27
|
+
act: str = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Initializes the PizzaGPT API with given parameters.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
34
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
35
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
36
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
37
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
38
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
39
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
40
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
41
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
42
|
+
"""
|
|
43
|
+
self.session = requests.Session()
|
|
44
|
+
self.is_conversation = is_conversation
|
|
45
|
+
self.max_tokens_to_sample = max_tokens
|
|
46
|
+
self.api_endpoint = "https://www.pizzagpt.it/api/chatx-completion"
|
|
47
|
+
self.stream_chunk_size = 64
|
|
48
|
+
self.timeout = timeout
|
|
49
|
+
self.last_response = {}
|
|
50
|
+
self.headers = {
|
|
51
|
+
"accept": "application/json",
|
|
52
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
53
|
+
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
54
|
+
"content-length": "17",
|
|
55
|
+
"content-type": "application/json",
|
|
56
|
+
"dnt": "1",
|
|
57
|
+
"origin": "https://www.pizzagpt.it",
|
|
58
|
+
"priority": "u=1, i",
|
|
59
|
+
"referer": "https://www.pizzagpt.it/en",
|
|
60
|
+
"sec-ch-ua": '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
|
|
61
|
+
"sec-ch-ua-mobile": "?0",
|
|
62
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
63
|
+
"sec-fetch-dest": "empty",
|
|
64
|
+
"sec-fetch-mode": "cors",
|
|
65
|
+
"sec-fetch-site": "same-origin",
|
|
66
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0",
|
|
67
|
+
"x-secret": "Marinara"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
self.__available_optimizers = (
|
|
71
|
+
method
|
|
72
|
+
for method in dir(Optimizers)
|
|
73
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
74
|
+
)
|
|
75
|
+
self.session.headers.update(self.headers)
|
|
76
|
+
Conversation.intro = (
|
|
77
|
+
AwesomePrompts().get_act(
|
|
78
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
79
|
+
)
|
|
80
|
+
if act
|
|
81
|
+
else intro or Conversation.intro
|
|
82
|
+
)
|
|
83
|
+
self.conversation = Conversation(
|
|
84
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
85
|
+
)
|
|
86
|
+
self.conversation.history_offset = history_offset
|
|
87
|
+
self.session.proxies = proxies
|
|
88
|
+
|
|
89
|
+
def ask(
|
|
90
|
+
self,
|
|
91
|
+
prompt: str,
|
|
92
|
+
stream: bool = False,
|
|
93
|
+
raw: bool = False,
|
|
94
|
+
optimizer: str = None,
|
|
95
|
+
conversationally: bool = False,
|
|
96
|
+
) -> dict:
|
|
97
|
+
"""Chat with AI
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
prompt (str): Prompt to be send.
|
|
101
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
102
|
+
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
103
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
104
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
105
|
+
Returns:
|
|
106
|
+
dict : {}
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"text" : "How may I assist you today?"
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
"""
|
|
113
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
114
|
+
if optimizer:
|
|
115
|
+
if optimizer in self.__available_optimizers:
|
|
116
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
117
|
+
conversation_prompt if conversationally else prompt
|
|
118
|
+
)
|
|
119
|
+
else:
|
|
120
|
+
raise Exception(
|
|
121
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
self.session.headers.update(self.headers)
|
|
125
|
+
payload = {"question": conversation_prompt}
|
|
126
|
+
|
|
127
|
+
response = self.session.post(
|
|
128
|
+
self.api_endpoint, json=payload, timeout=self.timeout
|
|
129
|
+
)
|
|
130
|
+
if not response.ok:
|
|
131
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
132
|
+
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
resp = response.json()
|
|
136
|
+
self.last_response.update(dict(text=resp['answer']['content']))
|
|
137
|
+
self.conversation.update_chat_history(
|
|
138
|
+
prompt, self.get_message(self.last_response)
|
|
139
|
+
)
|
|
140
|
+
return self.last_response # Return the updated last_response
|
|
141
|
+
|
|
142
|
+
def chat(
|
|
143
|
+
self,
|
|
144
|
+
prompt: str,
|
|
145
|
+
stream: bool = False,
|
|
146
|
+
optimizer: str = None,
|
|
147
|
+
conversationally: bool = False,
|
|
148
|
+
) -> str:
|
|
149
|
+
"""Generate response `str`
|
|
150
|
+
Args:
|
|
151
|
+
prompt (str): Prompt to be send.
|
|
152
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
153
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
154
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
155
|
+
Returns:
|
|
156
|
+
str: Response generated
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
return self.get_message(
|
|
160
|
+
self.ask(
|
|
161
|
+
prompt,
|
|
162
|
+
optimizer=optimizer,
|
|
163
|
+
conversationally=conversationally,
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
def get_message(self, response: dict) -> str:
|
|
167
|
+
"""Retrieves message only from response
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
response (dict): Response generated by `self.ask`
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
str: Message extracted
|
|
174
|
+
"""
|
|
175
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
176
|
+
return response["text"]
|
|
177
|
+
if __name__ == "__main__":
|
|
178
|
+
print(PIZZAGPT().chat("hello"))
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
from ..AIutel import Optimizers
|
|
5
|
+
from ..AIutel import Conversation
|
|
6
|
+
from ..AIutel import AwesomePrompts, sanitize_stream
|
|
7
|
+
from ..AIbase import Provider
|
|
8
|
+
from webscout import exceptions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RUBIKSAI(Provider):
|
|
12
|
+
"""
|
|
13
|
+
A class to interact with the Rubiks.ai API.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
is_conversation: bool = True,
|
|
19
|
+
max_tokens: int = 600,
|
|
20
|
+
timeout: int = 30,
|
|
21
|
+
intro: str = None,
|
|
22
|
+
filepath: str = None,
|
|
23
|
+
update_file: bool = True,
|
|
24
|
+
proxies: dict = {},
|
|
25
|
+
history_offset: int = 10250,
|
|
26
|
+
act: str = None,
|
|
27
|
+
model: str = "gpt-4o-mini",
|
|
28
|
+
) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Initializes the RUBIKSAI API with given parameters.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
34
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion.
|
|
35
|
+
Defaults to 600.
|
|
36
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
37
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
38
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
39
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
40
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
41
|
+
history_offset (int, optional): Limit conversation history to this number of last texts.
|
|
42
|
+
Defaults to 10250.
|
|
43
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
44
|
+
model (str, optional): AI model to use. Defaults to "gpt-4o-mini".
|
|
45
|
+
"""
|
|
46
|
+
self.session = requests.Session()
|
|
47
|
+
self.is_conversation = is_conversation
|
|
48
|
+
self.max_tokens_to_sample = max_tokens
|
|
49
|
+
self.api_endpoint = "https://rubiks.ai/search/api.php"
|
|
50
|
+
self.stream_chunk_size = 64
|
|
51
|
+
self.timeout = timeout
|
|
52
|
+
self.last_response = {}
|
|
53
|
+
self.model = model
|
|
54
|
+
self.headers = {
|
|
55
|
+
"accept": "text/event-stream",
|
|
56
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
57
|
+
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
58
|
+
"cache-control": "no-cache",
|
|
59
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
self.__available_optimizers = (
|
|
63
|
+
method
|
|
64
|
+
for method in dir(Optimizers)
|
|
65
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
66
|
+
)
|
|
67
|
+
self.session.headers.update(self.headers)
|
|
68
|
+
Conversation.intro = (
|
|
69
|
+
AwesomePrompts().get_act(
|
|
70
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
71
|
+
)
|
|
72
|
+
if act
|
|
73
|
+
else intro or Conversation.intro
|
|
74
|
+
)
|
|
75
|
+
self.conversation = Conversation(
|
|
76
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
77
|
+
)
|
|
78
|
+
self.conversation.history_offset = history_offset
|
|
79
|
+
self.session.proxies = proxies
|
|
80
|
+
|
|
81
|
+
def ask(
|
|
82
|
+
self,
|
|
83
|
+
prompt: str,
|
|
84
|
+
stream: bool = False,
|
|
85
|
+
raw: bool = False,
|
|
86
|
+
optimizer: str = None,
|
|
87
|
+
conversationally: bool = False,
|
|
88
|
+
) -> Dict[str, Any]:
|
|
89
|
+
"""
|
|
90
|
+
Sends a prompt to the Rubiks.ai API and returns the response.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
prompt: The text prompt to generate text from.
|
|
94
|
+
stream (bool, optional): Whether to stream the response. Defaults to False.
|
|
95
|
+
raw (bool, optional): Whether to return the raw response. Defaults to False.
|
|
96
|
+
optimizer (str, optional): The name of the optimizer to use. Defaults to None.
|
|
97
|
+
conversationally (bool, optional): Whether to chat conversationally. Defaults to False.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
The response from the API.
|
|
101
|
+
"""
|
|
102
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
103
|
+
if optimizer:
|
|
104
|
+
if optimizer in self.__available_optimizers:
|
|
105
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
106
|
+
conversation_prompt if conversationally else prompt
|
|
107
|
+
)
|
|
108
|
+
else:
|
|
109
|
+
raise Exception(
|
|
110
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
params = {
|
|
114
|
+
"q": conversation_prompt,
|
|
115
|
+
"model": self.model,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
def for_stream():
|
|
119
|
+
response = self.session.get(
|
|
120
|
+
self.api_endpoint, params=params, headers=self.headers, stream=True, timeout=self.timeout
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if not response.ok:
|
|
124
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
125
|
+
f"Failed to generate response - ({response.status_code}, {response.reason})"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
streaming_response = ""
|
|
129
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
130
|
+
if line:
|
|
131
|
+
if line.startswith("data: "):
|
|
132
|
+
json_data = line[6:]
|
|
133
|
+
if json_data == "[DONE]":
|
|
134
|
+
break
|
|
135
|
+
try:
|
|
136
|
+
data = json.loads(json_data)
|
|
137
|
+
if "choices" in data and len(data["choices"]) > 0:
|
|
138
|
+
content = data["choices"][0]["delta"].get("content", "")
|
|
139
|
+
streaming_response += content
|
|
140
|
+
yield content if raw else dict(text=streaming_response)
|
|
141
|
+
except json.decoder.JSONDecodeError:
|
|
142
|
+
continue
|
|
143
|
+
|
|
144
|
+
self.last_response.update(dict(text=streaming_response))
|
|
145
|
+
self.conversation.update_chat_history(
|
|
146
|
+
prompt, self.get_message(self.last_response)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def for_non_stream():
|
|
150
|
+
for _ in for_stream():
|
|
151
|
+
pass
|
|
152
|
+
return self.last_response
|
|
153
|
+
|
|
154
|
+
return for_stream() if stream else for_non_stream()
|
|
155
|
+
|
|
156
|
+
def chat(
|
|
157
|
+
self,
|
|
158
|
+
prompt: str,
|
|
159
|
+
stream: bool = False,
|
|
160
|
+
optimizer: str = None,
|
|
161
|
+
conversationally: bool = False,
|
|
162
|
+
) -> str:
|
|
163
|
+
"""Generate response `str`
|
|
164
|
+
Args:
|
|
165
|
+
prompt (str): Prompt to be send.
|
|
166
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
167
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
168
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
169
|
+
Returns:
|
|
170
|
+
str: Response generated
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
def for_stream():
|
|
174
|
+
for response in self.ask(
|
|
175
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
176
|
+
):
|
|
177
|
+
yield self.get_message(response)
|
|
178
|
+
|
|
179
|
+
def for_non_stream():
|
|
180
|
+
return self.get_message(
|
|
181
|
+
self.ask(
|
|
182
|
+
prompt,
|
|
183
|
+
False,
|
|
184
|
+
optimizer=optimizer,
|
|
185
|
+
conversationally=conversationally,
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
return for_stream() if stream else for_non_stream()
|
|
190
|
+
|
|
191
|
+
def get_message(self, response: dict) -> str:
|
|
192
|
+
"""Retrieves message only from response
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
response (dict): Response generated by `self.ask`
|
|
196
|
+
|
|
197
|
+
Returns:
|
|
198
|
+
str: Message extracted
|
|
199
|
+
"""
|
|
200
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
201
|
+
return response["text"]
|
webscout/Provider/__init__.py
CHANGED
|
@@ -38,6 +38,12 @@ from .Geminipro import GEMINIPRO
|
|
|
38
38
|
from .Geminiflash import GEMINIFLASH
|
|
39
39
|
from .OLLAMA import OLLAMA
|
|
40
40
|
from .FreeGemini import FreeGemini
|
|
41
|
+
from .Andi import AndiSearch
|
|
42
|
+
from .PizzaGPT import *
|
|
43
|
+
from .Llama3 import *
|
|
44
|
+
from .DARKAI import *
|
|
45
|
+
from .koala import *
|
|
46
|
+
from .RUBIKSAI import *
|
|
41
47
|
__all__ = [
|
|
42
48
|
'ThinkAnyAI',
|
|
43
49
|
'Xjai',
|
|
@@ -78,7 +84,11 @@ __all__ = [
|
|
|
78
84
|
'GEMINIPRO',
|
|
79
85
|
'GEMINIFLASH',
|
|
80
86
|
'OLLAMA',
|
|
81
|
-
'FreeGemini'
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
'FreeGemini',
|
|
88
|
+
'AndiSearch',
|
|
89
|
+
'PIZZAGPT',
|
|
90
|
+
'LLAMA3',
|
|
91
|
+
'DARKAI',
|
|
92
|
+
'KOALA',
|
|
93
|
+
'RUBIKSAI'
|
|
84
94
|
]
|