webscout 5.4__py3-none-any.whl → 5.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.
- webscout/Agents/Onlinesearcher.py +3 -3
- webscout/Agents/__init__.py +0 -1
- webscout/Agents/functioncall.py +3 -3
- webscout/Provider/Bing.py +243 -0
- webscout/Provider/Chatify.py +1 -1
- webscout/Provider/Cloudflare.py +1 -1
- webscout/Provider/DARKAI.py +1 -1
- webscout/Provider/DiscordRocks.py +109 -246
- webscout/Provider/Farfalle.py +1 -1
- webscout/Provider/Free2GPT.py +234 -0
- webscout/{Agents/ai.py → Provider/GPTWeb.py} +40 -33
- webscout/Provider/Llama3.py +65 -62
- webscout/Provider/OLLAMA.py +1 -1
- webscout/Provider/PizzaGPT.py +1 -1
- webscout/Provider/RUBIKSAI.py +13 -3
- webscout/Provider/Reka.py +0 -1
- webscout/Provider/TTI/Nexra.py +120 -0
- webscout/Provider/TTI/__init__.py +4 -1
- webscout/Provider/TTI/aiforce.py +137 -0
- webscout/Provider/TTI/blackboximage.py +153 -0
- webscout/Provider/TTI/deepinfra.py +2 -2
- webscout/Provider/TeachAnything.py +1 -1
- webscout/Provider/Youchat.py +1 -1
- webscout/Provider/__init__.py +11 -6
- webscout/Provider/{NetFly.py → aigames.py} +76 -79
- webscout/Provider/cleeai.py +1 -1
- webscout/Provider/elmo.py +1 -1
- webscout/Provider/felo_search.py +1 -1
- webscout/Provider/genspark.py +1 -1
- webscout/Provider/julius.py +7 -1
- webscout/Provider/lepton.py +1 -1
- webscout/Provider/meta.py +1 -1
- webscout/Provider/turboseek.py +1 -1
- webscout/Provider/upstage.py +230 -0
- webscout/Provider/x0gpt.py +1 -1
- webscout/Provider/xdash.py +1 -1
- webscout/Provider/yep.py +2 -2
- webscout/tempid.py +46 -2
- webscout/version.py +1 -1
- webscout/webai.py +1 -1
- webscout/webscout_search_async.py +9 -9
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/METADATA +7 -30
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/RECORD +47 -42
- webscout/Provider/ThinkAnyAI.py +0 -219
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/LICENSE.md +0 -0
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/WHEEL +0 -0
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/entry_points.txt +0 -0
- {webscout-5.4.dist-info → webscout-5.6.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import colorlog
|
|
3
3
|
from webscout import WEBS
|
|
4
|
-
from webscout
|
|
4
|
+
from webscout import DeepInfra
|
|
5
5
|
import httpx
|
|
6
6
|
from bs4 import BeautifulSoup
|
|
7
7
|
from typing import List, Dict
|
|
@@ -10,7 +10,7 @@ import logging
|
|
|
10
10
|
class WebSearchAgent:
|
|
11
11
|
def __init__(self):
|
|
12
12
|
self.webs = WEBS()
|
|
13
|
-
self.ai =
|
|
13
|
+
self.ai = DeepInfra(is_conversation=False)
|
|
14
14
|
|
|
15
15
|
def generate_search_queries(self, information, num_queries=3):
|
|
16
16
|
prompt = f"""
|
|
@@ -112,7 +112,7 @@ class WebSearchAgent:
|
|
|
112
112
|
class OnlineSearcher:
|
|
113
113
|
def __init__(self):
|
|
114
114
|
self.agent = WebSearchAgent()
|
|
115
|
-
self.ai =
|
|
115
|
+
self.ai = DeepInfra(is_conversation=False)
|
|
116
116
|
|
|
117
117
|
def answer_question(self, question: str):
|
|
118
118
|
search_results = self.agent.search(question)
|
webscout/Agents/__init__.py
CHANGED
webscout/Agents/functioncall.py
CHANGED
|
@@ -4,12 +4,12 @@ import json
|
|
|
4
4
|
import time
|
|
5
5
|
from typing import Any, Dict, Optional
|
|
6
6
|
import requests
|
|
7
|
-
from webscout import WEBS,
|
|
7
|
+
from webscout import WEBS, DeepInfra
|
|
8
8
|
|
|
9
9
|
class FunctionCallingAgent:
|
|
10
|
-
def __init__(self,
|
|
10
|
+
def __init__(self,
|
|
11
11
|
tools: list = None):
|
|
12
|
-
self.ai =
|
|
12
|
+
self.ai = DeepInfra(timeout=300, intro=None)
|
|
13
13
|
self.tools = tools if tools is not None else []
|
|
14
14
|
self.knowledge_cutoff = "September 2022"
|
|
15
15
|
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
import requests
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
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
|
|
9
|
+
from webscout import exceptions
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Bing(Provider):
|
|
13
|
+
"""
|
|
14
|
+
A class to interact with the Nexra Bing Chat API.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
AVAILABLE_CONVERSATION_STYLES = [
|
|
18
|
+
"Balanced",
|
|
19
|
+
"Creative",
|
|
20
|
+
"Precise",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
is_conversation: bool = True,
|
|
26
|
+
max_tokens: int = 600,
|
|
27
|
+
timeout: int = 30,
|
|
28
|
+
intro: str = None,
|
|
29
|
+
filepath: str = None,
|
|
30
|
+
update_file: bool = True,
|
|
31
|
+
proxies: dict = {},
|
|
32
|
+
history_offset: int = 10250,
|
|
33
|
+
act: str = None,
|
|
34
|
+
system_prompt: str = "You are a helpful AI assistant.",
|
|
35
|
+
conversation_style: str = "Balanced",
|
|
36
|
+
):
|
|
37
|
+
"""
|
|
38
|
+
Initializes the Nexra Bing Chat API with given parameters.
|
|
39
|
+
"""
|
|
40
|
+
if conversation_style not in self.AVAILABLE_CONVERSATION_STYLES:
|
|
41
|
+
raise ValueError(
|
|
42
|
+
f"Invalid conversation_style: {conversation_style}. Choose from: {self.AVAILABLE_CONVERSATION_STYLES}"
|
|
43
|
+
)
|
|
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://nexra.aryahcr.cc/api/chat/complements"
|
|
49
|
+
self.stream_chunk_size = 1024
|
|
50
|
+
|
|
51
|
+
self.timeout = timeout
|
|
52
|
+
self.last_response = {}
|
|
53
|
+
self.system_prompt = system_prompt
|
|
54
|
+
self.conversation_style = conversation_style
|
|
55
|
+
self.headers = {"Content-Type": "application/json"}
|
|
56
|
+
|
|
57
|
+
self.__available_optimizers = (
|
|
58
|
+
method
|
|
59
|
+
for method in dir(Optimizers)
|
|
60
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
61
|
+
)
|
|
62
|
+
self.session.headers.update(self.headers)
|
|
63
|
+
Conversation.intro = (
|
|
64
|
+
AwesomePrompts().get_act(
|
|
65
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
66
|
+
)
|
|
67
|
+
if act
|
|
68
|
+
else intro or Conversation.intro
|
|
69
|
+
)
|
|
70
|
+
self.conversation = Conversation(
|
|
71
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
72
|
+
)
|
|
73
|
+
self.conversation.history_offset = history_offset
|
|
74
|
+
self.session.proxies = proxies
|
|
75
|
+
|
|
76
|
+
def ask(
|
|
77
|
+
self,
|
|
78
|
+
prompt: str,
|
|
79
|
+
stream: bool = False,
|
|
80
|
+
raw: bool = False,
|
|
81
|
+
optimizer: str = None,
|
|
82
|
+
conversationally: bool = False,
|
|
83
|
+
) -> Dict[str, Any]:
|
|
84
|
+
"""Chat with AI"""
|
|
85
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
86
|
+
if optimizer:
|
|
87
|
+
if optimizer in self.__available_optimizers:
|
|
88
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
89
|
+
conversation_prompt if conversationally else prompt
|
|
90
|
+
)
|
|
91
|
+
else:
|
|
92
|
+
raise Exception(
|
|
93
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
messages = [
|
|
97
|
+
{"role": "system", "content": self.system_prompt},
|
|
98
|
+
{"role": "user", "content": conversation_prompt},
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
data = {
|
|
102
|
+
"messages": messages,
|
|
103
|
+
"conversation_style": self.conversation_style,
|
|
104
|
+
"markdown": False,
|
|
105
|
+
"stream": stream,
|
|
106
|
+
"model": "Bing",
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
def for_stream():
|
|
110
|
+
try:
|
|
111
|
+
response = self.session.post(
|
|
112
|
+
self.api_endpoint, json=data, stream=True, timeout=self.timeout
|
|
113
|
+
)
|
|
114
|
+
response.raise_for_status()
|
|
115
|
+
|
|
116
|
+
full_response = ""
|
|
117
|
+
tmp = None
|
|
118
|
+
for chunk in response.iter_content(chunk_size=self.stream_chunk_size):
|
|
119
|
+
if chunk:
|
|
120
|
+
chk = chunk.decode()
|
|
121
|
+
chk = chk.split(" ")
|
|
122
|
+
|
|
123
|
+
for data in chk:
|
|
124
|
+
result = None
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
convert = json.loads(data)
|
|
128
|
+
result = data
|
|
129
|
+
tmp = None
|
|
130
|
+
except Exception as e:
|
|
131
|
+
if tmp is None:
|
|
132
|
+
tmp = data
|
|
133
|
+
else:
|
|
134
|
+
try:
|
|
135
|
+
convert = json.loads(tmp)
|
|
136
|
+
result = tmp
|
|
137
|
+
tmp = None
|
|
138
|
+
except Exception as e:
|
|
139
|
+
tmp = tmp + data
|
|
140
|
+
try:
|
|
141
|
+
convert = json.loads(tmp)
|
|
142
|
+
result = tmp
|
|
143
|
+
tmp = None
|
|
144
|
+
except Exception as e:
|
|
145
|
+
tmp = tmp
|
|
146
|
+
|
|
147
|
+
if result is not None:
|
|
148
|
+
if "code" not in result and "status" not in result:
|
|
149
|
+
full_response += result
|
|
150
|
+
|
|
151
|
+
yield result if raw else dict(text=full_response)
|
|
152
|
+
else:
|
|
153
|
+
raise exceptions.FailedToGenerateResponseError(result)
|
|
154
|
+
self.last_response.update(dict(text=full_response))
|
|
155
|
+
self.conversation.update_chat_history(
|
|
156
|
+
prompt, self.get_message(self.last_response)
|
|
157
|
+
)
|
|
158
|
+
except requests.exceptions.RequestException as e:
|
|
159
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
160
|
+
f"An error occurred: {e}"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
def for_non_stream():
|
|
164
|
+
try:
|
|
165
|
+
response = self.session.post(
|
|
166
|
+
self.api_endpoint,
|
|
167
|
+
headers=self.headers,
|
|
168
|
+
json=data,
|
|
169
|
+
timeout=self.timeout,
|
|
170
|
+
)
|
|
171
|
+
response.raise_for_status()
|
|
172
|
+
|
|
173
|
+
# Remove any leading non-printable characters
|
|
174
|
+
clean_text = response.text.lstrip()
|
|
175
|
+
|
|
176
|
+
# Attempt to parse the response as JSON
|
|
177
|
+
resp = json.loads(clean_text)
|
|
178
|
+
|
|
179
|
+
if "message" in resp:
|
|
180
|
+
self.last_response.update(dict(text=resp["message"]))
|
|
181
|
+
self.conversation.update_chat_history(
|
|
182
|
+
prompt, self.get_message(self.last_response)
|
|
183
|
+
)
|
|
184
|
+
return self.last_response
|
|
185
|
+
else:
|
|
186
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
187
|
+
f"Unexpected response format: {clean_text}"
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
except json.JSONDecodeError as e:
|
|
191
|
+
# Handle JSON decoding error, print raw response for debugging
|
|
192
|
+
print(f"Error decoding JSON. Raw response: {response.text}")
|
|
193
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
194
|
+
f"Failed to decode JSON response - {response.text}"
|
|
195
|
+
) from e
|
|
196
|
+
except requests.exceptions.RequestException as e:
|
|
197
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
198
|
+
f"An error occurred: {e}"
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
return for_stream() if stream else for_non_stream()
|
|
202
|
+
|
|
203
|
+
def chat(
|
|
204
|
+
self,
|
|
205
|
+
prompt: str,
|
|
206
|
+
stream: bool = False,
|
|
207
|
+
optimizer: str = None,
|
|
208
|
+
conversationally: bool = False,
|
|
209
|
+
) -> str:
|
|
210
|
+
"""Generate response `str`"""
|
|
211
|
+
|
|
212
|
+
def for_stream():
|
|
213
|
+
for response in self.ask(
|
|
214
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
215
|
+
):
|
|
216
|
+
yield self.get_message(response)
|
|
217
|
+
|
|
218
|
+
def for_non_stream():
|
|
219
|
+
return self.get_message(
|
|
220
|
+
self.ask(
|
|
221
|
+
prompt,
|
|
222
|
+
False,
|
|
223
|
+
optimizer=optimizer,
|
|
224
|
+
conversationally=conversationally,
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
return for_stream() if stream else for_non_stream()
|
|
229
|
+
|
|
230
|
+
def get_message(self, response: dict) -> str:
|
|
231
|
+
"""Retrieves message only from response"""
|
|
232
|
+
assert isinstance(
|
|
233
|
+
response, dict
|
|
234
|
+
), "Response should be of dict data-type only"
|
|
235
|
+
text = re.sub(r"<sup>.*?</sup>", "", response["text"])
|
|
236
|
+
return text
|
|
237
|
+
|
|
238
|
+
if __name__ == "__main__":
|
|
239
|
+
from rich import print
|
|
240
|
+
ai = Bing()
|
|
241
|
+
response = ai.chat(input(">>> "))
|
|
242
|
+
for chunk in response:
|
|
243
|
+
print(chunk, end="", flush=True)
|
webscout/Provider/Chatify.py
CHANGED
webscout/Provider/Cloudflare.py
CHANGED
webscout/Provider/DARKAI.py
CHANGED
|
@@ -218,7 +218,7 @@ class DARKAI(Provider):
|
|
|
218
218
|
return response["text"]
|
|
219
219
|
if __name__ == '__main__':
|
|
220
220
|
from rich import print
|
|
221
|
-
ai = DARKAI()
|
|
221
|
+
ai = DARKAI(model='llama-3-405b')
|
|
222
222
|
response = ai.chat("tell me about india")
|
|
223
223
|
for chunk in response:
|
|
224
224
|
print(chunk, end="", flush=True)
|