webscout 6.5__py3-none-any.whl → 6.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/Extra/autocoder/autocoder_utiles.py +119 -101
- webscout/Provider/AISEARCH/__init__.py +2 -0
- webscout/Provider/AISEARCH/ooai.py +155 -0
- webscout/Provider/Amigo.py +70 -85
- webscout/Provider/{prefind.py → Jadve.py} +72 -70
- webscout/Provider/Netwrck.py +235 -0
- webscout/Provider/Openai.py +4 -3
- webscout/Provider/PI.py +2 -2
- webscout/Provider/PizzaGPT.py +3 -3
- webscout/Provider/TeachAnything.py +15 -2
- webscout/Provider/Youchat.py +42 -8
- webscout/Provider/__init__.py +134 -147
- webscout/Provider/multichat.py +230 -0
- webscout/Provider/promptrefine.py +2 -2
- webscout/Provider/talkai.py +10 -13
- webscout/Provider/turboseek.py +5 -4
- webscout/Provider/tutorai.py +8 -112
- webscout/Provider/typegpt.py +4 -5
- webscout/Provider/x0gpt.py +81 -9
- webscout/Provider/yep.py +123 -361
- webscout/__init__.py +10 -1
- webscout/conversation.py +24 -9
- webscout/exceptions.py +188 -20
- webscout/litprinter/__init__.py +4 -117
- webscout/litprinter/colors.py +54 -0
- webscout/optimizers.py +335 -185
- webscout/scout/__init__.py +2 -5
- webscout/scout/core/__init__.py +7 -0
- webscout/scout/core/crawler.py +140 -0
- webscout/scout/core/scout.py +571 -0
- webscout/scout/core/search_result.py +96 -0
- webscout/scout/core/text_analyzer.py +63 -0
- webscout/scout/core/text_utils.py +277 -0
- webscout/scout/core/web_analyzer.py +52 -0
- webscout/scout/element.py +6 -5
- webscout/update_checker.py +117 -58
- webscout/version.py +1 -1
- webscout/zeroart/base.py +15 -16
- webscout/zeroart/effects.py +1 -1
- webscout/zeroart/fonts.py +1 -1
- {webscout-6.5.dist-info → webscout-6.6.dist-info}/METADATA +8 -165
- {webscout-6.5.dist-info → webscout-6.6.dist-info}/RECORD +59 -41
- webscout-6.6.dist-info/top_level.txt +2 -0
- webstoken/__init__.py +30 -0
- webstoken/classifier.py +189 -0
- webstoken/keywords.py +216 -0
- webstoken/language.py +128 -0
- webstoken/ner.py +164 -0
- webstoken/normalizer.py +35 -0
- webstoken/processor.py +77 -0
- webstoken/sentiment.py +206 -0
- webstoken/stemmer.py +73 -0
- webstoken/t.py +75 -0
- webstoken/tagger.py +60 -0
- webstoken/tokenizer.py +158 -0
- webscout/Provider/Perplexity.py +0 -591
- webscout/Provider/RoboCoders.py +0 -206
- webscout/Provider/genspark.py +0 -225
- webscout/Provider/perplexitylabs.py +0 -265
- webscout/Provider/twitterclone.py +0 -251
- webscout/Provider/upstage.py +0 -230
- webscout-6.5.dist-info/top_level.txt +0 -1
- /webscout/Provider/{felo_search.py → AISEARCH/felo_search.py} +0 -0
- {webscout-6.5.dist-info → webscout-6.6.dist-info}/LICENSE.md +0 -0
- {webscout-6.5.dist-info → webscout-6.6.dist-info}/WHEEL +0 -0
- {webscout-6.5.dist-info → webscout-6.6.dist-info}/entry_points.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
import json
|
|
3
|
-
import
|
|
4
|
-
import os
|
|
3
|
+
import re
|
|
5
4
|
from typing import Any, Dict, Optional, Generator
|
|
6
5
|
|
|
7
6
|
from webscout.AIutel import Optimizers
|
|
8
7
|
from webscout.AIutel import Conversation
|
|
9
|
-
from webscout.AIutel import AwesomePrompts
|
|
10
|
-
from webscout.AIbase import
|
|
8
|
+
from webscout.AIutel import AwesomePrompts
|
|
9
|
+
from webscout.AIbase import Provider
|
|
11
10
|
from webscout import exceptions
|
|
11
|
+
from webscout.litagent import LitAgent
|
|
12
12
|
|
|
13
|
-
class
|
|
13
|
+
class JadveOpenAI(Provider):
|
|
14
14
|
"""
|
|
15
|
-
A class to interact with the
|
|
15
|
+
A class to interact with the OpenAI API through jadve.com.
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
-
AVAILABLE_MODELS = ["
|
|
18
|
+
AVAILABLE_MODELS = ["gpt-4o", "gpt-4o-mini"]
|
|
19
19
|
|
|
20
20
|
def __init__(
|
|
21
21
|
self,
|
|
@@ -28,10 +28,11 @@ class PrefindAI(Provider):
|
|
|
28
28
|
proxies: dict = {},
|
|
29
29
|
history_offset: int = 10250,
|
|
30
30
|
act: str = None,
|
|
31
|
-
model: str = "
|
|
31
|
+
model: str = "gpt-4o-mini",
|
|
32
|
+
system_prompt: str = "You are a helpful AI assistant."
|
|
32
33
|
):
|
|
33
34
|
"""
|
|
34
|
-
Initializes the
|
|
35
|
+
Initializes the OpenAI API client through jadve.com with given parameters.
|
|
35
36
|
|
|
36
37
|
Args:
|
|
37
38
|
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
@@ -43,30 +44,45 @@ class PrefindAI(Provider):
|
|
|
43
44
|
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
44
45
|
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
45
46
|
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
system_prompt (str, optional): System prompt for OpenAI. Defaults to "You are a helpful AI assistant.".
|
|
48
|
+
model (str, optional): AI model to use for text generation. Defaults to "gpt-4o".
|
|
48
49
|
"""
|
|
50
|
+
if model not in self.AVAILABLE_MODELS:
|
|
51
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
|
|
52
|
+
|
|
49
53
|
self.session = requests.Session()
|
|
50
54
|
self.is_conversation = is_conversation
|
|
51
55
|
self.max_tokens_to_sample = max_tokens
|
|
52
|
-
self.api_endpoint = "https://
|
|
56
|
+
self.api_endpoint = "https://openai.jadve.com/chatgpt"
|
|
53
57
|
self.stream_chunk_size = 64
|
|
54
58
|
self.timeout = timeout
|
|
55
59
|
self.last_response = {}
|
|
56
60
|
self.model = model
|
|
57
|
-
self.
|
|
61
|
+
self.system_prompt = system_prompt
|
|
62
|
+
self.headers = {
|
|
63
|
+
"accept": "*/*",
|
|
64
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
65
|
+
"accept-language": "en",
|
|
66
|
+
"content-type": "application/json",
|
|
67
|
+
"dnt": "1",
|
|
68
|
+
"origin": "https://jadve.com",
|
|
69
|
+
"priority": "u=1, i",
|
|
70
|
+
"referer": "https://jadve.com/",
|
|
71
|
+
"sec-ch-ua": '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
|
72
|
+
"sec-ch-ua-mobile": "?0",
|
|
73
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
74
|
+
"sec-fetch-dest": "empty",
|
|
75
|
+
"sec-fetch-mode": "cors",
|
|
76
|
+
"sec-fetch-site": "same-site",
|
|
77
|
+
"user-agent": LitAgent().random(),
|
|
78
|
+
}
|
|
58
79
|
|
|
59
80
|
self.__available_optimizers = (
|
|
60
81
|
method
|
|
61
82
|
for method in dir(Optimizers)
|
|
62
83
|
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
63
84
|
)
|
|
64
|
-
self.session.headers.update(
|
|
65
|
-
{
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
"Accept": "text/event-stream",
|
|
68
|
-
}
|
|
69
|
-
)
|
|
85
|
+
self.session.headers.update(self.headers)
|
|
70
86
|
Conversation.intro = (
|
|
71
87
|
AwesomePrompts().get_act(
|
|
72
88
|
act, raise_not_found=True, default=None, case_insensitive=True
|
|
@@ -80,25 +96,6 @@ class PrefindAI(Provider):
|
|
|
80
96
|
self.conversation.history_offset = history_offset
|
|
81
97
|
self.session.proxies = proxies
|
|
82
98
|
|
|
83
|
-
def get_device_token(self) -> str:
|
|
84
|
-
"""
|
|
85
|
-
Retrieves a device token from the Prefind AI API.
|
|
86
|
-
"""
|
|
87
|
-
device_token_url = "https://api.prefind.ai/api/auth/device-token/create"
|
|
88
|
-
headers = {"Content-Type": "application/json; charset=utf-8"}
|
|
89
|
-
data = {}
|
|
90
|
-
response = requests.post(
|
|
91
|
-
device_token_url, headers=headers, data=json.dumps(data)
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
if response.status_code == 200:
|
|
95
|
-
device_token_data = response.json()
|
|
96
|
-
return device_token_data["sessionToken"]
|
|
97
|
-
else:
|
|
98
|
-
raise exceptions.FailedToGenerateResponseError(
|
|
99
|
-
f"Failed to get device token - ({response.status_code}, {response.reason}) - {response.text}"
|
|
100
|
-
)
|
|
101
|
-
|
|
102
99
|
def ask(
|
|
103
100
|
self,
|
|
104
101
|
prompt: str,
|
|
@@ -106,11 +103,10 @@ class PrefindAI(Provider):
|
|
|
106
103
|
raw: bool = False,
|
|
107
104
|
optimizer: str = None,
|
|
108
105
|
conversationally: bool = False,
|
|
109
|
-
) ->
|
|
106
|
+
) -> dict:
|
|
110
107
|
"""Chat with AI
|
|
111
|
-
|
|
112
108
|
Args:
|
|
113
|
-
prompt (str): Prompt to be
|
|
109
|
+
prompt (str): Prompt to be sent.
|
|
114
110
|
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
115
111
|
raw (bool, optional): Stream back raw response as received. Defaults to False.
|
|
116
112
|
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
@@ -134,43 +130,51 @@ class PrefindAI(Provider):
|
|
|
134
130
|
f"Optimizer is not one of {self.__available_optimizers}"
|
|
135
131
|
)
|
|
136
132
|
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
payload = {
|
|
134
|
+
"action": "sendmessage",
|
|
135
|
+
"model": self.model,
|
|
136
|
+
"messages": [
|
|
137
|
+
{"role": "system", "content": self.system_prompt},
|
|
138
|
+
{"role": "user", "content": conversation_prompt}
|
|
139
|
+
],
|
|
140
|
+
"temperature": 0.7,
|
|
141
|
+
"language": "en",
|
|
142
|
+
"returnTokensUsage": True,
|
|
143
|
+
"botId": "guest-chat",
|
|
144
|
+
"chatId": ""
|
|
145
|
+
}
|
|
146
|
+
|
|
139
147
|
def for_stream():
|
|
140
148
|
response = self.session.post(
|
|
141
|
-
self.api_endpoint, json=
|
|
149
|
+
self.api_endpoint, headers=self.headers, json=payload, stream=True, timeout=self.timeout
|
|
142
150
|
)
|
|
151
|
+
|
|
143
152
|
if not response.ok:
|
|
144
153
|
raise exceptions.FailedToGenerateResponseError(
|
|
145
154
|
f"Failed to generate response - ({response.status_code}, {response.reason}) - {response.text}"
|
|
146
155
|
)
|
|
147
|
-
|
|
148
156
|
streaming_text = ""
|
|
149
|
-
for line in response.iter_lines(decode_unicode=True):
|
|
157
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
150
158
|
if line:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
resp = dict(text=content)
|
|
166
|
-
self.last_response.update(resp)
|
|
167
|
-
yield resp if raw else resp
|
|
159
|
+
if line.startswith("data: "):
|
|
160
|
+
data = line[6:]
|
|
161
|
+
if data == "[DONE]":
|
|
162
|
+
break
|
|
163
|
+
try:
|
|
164
|
+
json_data = json.loads(data)
|
|
165
|
+
if "choices" in json_data and len(json_data["choices"]) > 0:
|
|
166
|
+
content = json_data["choices"][0].get("delta", {}).get("content", "")
|
|
167
|
+
if content:
|
|
168
|
+
streaming_text += content
|
|
169
|
+
yield content if raw else dict(text=content)
|
|
170
|
+
except json.JSONDecodeError as e:
|
|
171
|
+
print(f"Error parsing line: {line} - {e}")
|
|
172
|
+
self.last_response.update(dict(text=streaming_text))
|
|
168
173
|
self.conversation.update_chat_history(
|
|
169
174
|
prompt, self.get_message(self.last_response)
|
|
170
175
|
)
|
|
171
176
|
|
|
172
177
|
def for_non_stream():
|
|
173
|
-
# let's make use of stream
|
|
174
178
|
for _ in for_stream():
|
|
175
179
|
pass
|
|
176
180
|
return self.last_response
|
|
@@ -214,19 +218,17 @@ class PrefindAI(Provider):
|
|
|
214
218
|
|
|
215
219
|
def get_message(self, response: dict) -> str:
|
|
216
220
|
"""Retrieves message only from response
|
|
217
|
-
|
|
218
221
|
Args:
|
|
219
222
|
response (dict): Response generated by `self.ask`
|
|
220
|
-
|
|
221
223
|
Returns:
|
|
222
224
|
str: Message extracted
|
|
223
225
|
"""
|
|
224
226
|
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
225
227
|
return response["text"]
|
|
226
|
-
|
|
227
|
-
if __name__ ==
|
|
228
|
+
|
|
229
|
+
if __name__ == "__main__":
|
|
228
230
|
from rich import print
|
|
229
|
-
ai =
|
|
230
|
-
response = ai.chat("
|
|
231
|
+
ai = JadveOpenAI(timeout=5000)
|
|
232
|
+
response = ai.chat("yo what's up", stream=True)
|
|
231
233
|
for chunk in response:
|
|
232
234
|
print(chunk, end="", flush=True)
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import uuid
|
|
3
|
+
import requests
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, Optional, Generator, Union
|
|
7
|
+
from dataclasses import dataclass, asdict
|
|
8
|
+
from datetime import date
|
|
9
|
+
|
|
10
|
+
from webscout.AIutel import Optimizers, Conversation, AwesomePrompts
|
|
11
|
+
from webscout.AIbase import Provider
|
|
12
|
+
from webscout import exceptions
|
|
13
|
+
from webscout.Litlogger import LitLogger, LogFormat, ColorScheme
|
|
14
|
+
from webscout.litagent import LitAgent
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Netwrck(Provider):
|
|
18
|
+
"""
|
|
19
|
+
A class to interact with the Netwrck.com API. Supports streaming.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
AVAILABLE_MODELS = {
|
|
23
|
+
"lumimaid": "neversleep/llama-3.1-lumimaid-8b",
|
|
24
|
+
"grok": "x-ai/grok-2",
|
|
25
|
+
"claude": "anthropic/claude-3.5-sonnet:beta",
|
|
26
|
+
"euryale": "sao10k/l3-euryale-70b",
|
|
27
|
+
"gpt4mini": "openai/gpt-4o-mini",
|
|
28
|
+
"mythomax": "gryphe/mythomax-l2-13b",
|
|
29
|
+
"gemini": "google/gemini-pro-1.5",
|
|
30
|
+
"lumimaid70b": "neversleep/llama-3.1-lumimaid-70b",
|
|
31
|
+
"nemotron": "nvidia/llama-3.1-nemotron-70b-instruct",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
model: str = "lumimaid",
|
|
37
|
+
is_conversation: bool = True,
|
|
38
|
+
max_tokens: int = 2048,
|
|
39
|
+
timeout: int = 30,
|
|
40
|
+
intro: Optional[str] = None,
|
|
41
|
+
filepath: Optional[str] = None,
|
|
42
|
+
update_file: bool = False,
|
|
43
|
+
proxies: Optional[dict] = None,
|
|
44
|
+
history_offset: int = 0,
|
|
45
|
+
act: Optional[str] = None,
|
|
46
|
+
system_prompt: str = "You are a helpful assistant.",
|
|
47
|
+
temperature: float = 0.7,
|
|
48
|
+
top_p: float = 0.8,
|
|
49
|
+
logging: bool = False
|
|
50
|
+
):
|
|
51
|
+
"""Initializes the Netwrck API client."""
|
|
52
|
+
if model not in self.AVAILABLE_MODELS:
|
|
53
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {list(self.AVAILABLE_MODELS.keys())}")
|
|
54
|
+
|
|
55
|
+
self.model = model
|
|
56
|
+
self.model_name = self.AVAILABLE_MODELS[model]
|
|
57
|
+
self.system_prompt = system_prompt
|
|
58
|
+
self.session = requests.Session()
|
|
59
|
+
self.is_conversation = is_conversation
|
|
60
|
+
self.max_tokens_to_sample = max_tokens
|
|
61
|
+
self.timeout = timeout
|
|
62
|
+
self.last_response: Dict[str, Any] = {}
|
|
63
|
+
self.temperature = temperature
|
|
64
|
+
self.top_p = top_p
|
|
65
|
+
|
|
66
|
+
# Initialize LitAgent for user agent generation
|
|
67
|
+
self.agent = LitAgent()
|
|
68
|
+
|
|
69
|
+
self.headers = {
|
|
70
|
+
'authority': 'netwrck.com',
|
|
71
|
+
'accept': '*/*',
|
|
72
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
73
|
+
'content-type': 'application/json',
|
|
74
|
+
'origin': 'https://netwrck.com',
|
|
75
|
+
'referer': 'https://netwrck.com/',
|
|
76
|
+
'user-agent': self.agent.random()
|
|
77
|
+
}
|
|
78
|
+
self.session.headers.update(self.headers)
|
|
79
|
+
self.proxies = proxies or {}
|
|
80
|
+
|
|
81
|
+
Conversation.intro = (
|
|
82
|
+
AwesomePrompts().get_act(act, raise_not_found=True, default=None, case_insensitive=True)
|
|
83
|
+
if act
|
|
84
|
+
else intro or Conversation.intro
|
|
85
|
+
)
|
|
86
|
+
self.conversation = Conversation(is_conversation, max_tokens, filepath, update_file)
|
|
87
|
+
self.conversation.history_offset = history_offset
|
|
88
|
+
self.__available_optimizers = (
|
|
89
|
+
method
|
|
90
|
+
for method in dir(Optimizers)
|
|
91
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Initialize logger
|
|
95
|
+
self.logger = LitLogger(name="Netwrck", format=LogFormat.MODERN_EMOJI, color_scheme=ColorScheme.CYBERPUNK) if logging else None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def ask(
|
|
99
|
+
self,
|
|
100
|
+
prompt: str,
|
|
101
|
+
stream: bool = False,
|
|
102
|
+
raw: bool = False,
|
|
103
|
+
optimizer: Optional[str] = None,
|
|
104
|
+
conversationally: bool = False,
|
|
105
|
+
) -> Union[Dict[str, Any], Generator]:
|
|
106
|
+
"""Sends a prompt to the Netwrck API and returns the response."""
|
|
107
|
+
|
|
108
|
+
if self.logger:
|
|
109
|
+
self.logger.debug(f"ask() called with prompt: {prompt}")
|
|
110
|
+
|
|
111
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
112
|
+
if optimizer:
|
|
113
|
+
if optimizer in self.__available_optimizers:
|
|
114
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
115
|
+
conversation_prompt if conversationally else prompt
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
if self.logger:
|
|
119
|
+
self.logger.error(f"Invalid optimizer: {optimizer}")
|
|
120
|
+
raise exceptions.FailedToGenerateResponseError(
|
|
121
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
payload = {
|
|
125
|
+
"query": conversation_prompt,
|
|
126
|
+
"context": self.system_prompt,
|
|
127
|
+
"examples": [],
|
|
128
|
+
"model_name": self.model_name,
|
|
129
|
+
"temperature": self.temperature,
|
|
130
|
+
"top_p": self.top_p,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def for_stream():
|
|
135
|
+
try:
|
|
136
|
+
response = self.session.post(
|
|
137
|
+
"https://netwrck.com/api/chatpred_or",
|
|
138
|
+
json=payload,
|
|
139
|
+
headers=self.headers,
|
|
140
|
+
proxies=self.proxies,
|
|
141
|
+
timeout=self.timeout,
|
|
142
|
+
stream=True,
|
|
143
|
+
)
|
|
144
|
+
response.raise_for_status()
|
|
145
|
+
|
|
146
|
+
streaming_text = ""
|
|
147
|
+
for line in response.iter_lines():
|
|
148
|
+
if line:
|
|
149
|
+
decoded_line = line.decode('utf-8').strip('"')
|
|
150
|
+
streaming_text += decoded_line
|
|
151
|
+
yield {"text": decoded_line} if not raw else decoded_line
|
|
152
|
+
|
|
153
|
+
self.conversation.update_chat_history(prompt, streaming_text)
|
|
154
|
+
|
|
155
|
+
except Exception as e:
|
|
156
|
+
if self.logger:
|
|
157
|
+
self.logger.error(f"Error communicating with Netwrck: {e}")
|
|
158
|
+
raise exceptions.ProviderConnectionError(f"Error communicating with Netwrck: {e}") from e
|
|
159
|
+
|
|
160
|
+
def for_non_stream():
|
|
161
|
+
try:
|
|
162
|
+
response = self.session.post(
|
|
163
|
+
"https://netwrck.com/api/chatpred_or",
|
|
164
|
+
json=payload,
|
|
165
|
+
headers=self.headers,
|
|
166
|
+
proxies=self.proxies,
|
|
167
|
+
timeout=self.timeout,
|
|
168
|
+
)
|
|
169
|
+
response.raise_for_status()
|
|
170
|
+
print(response.text)
|
|
171
|
+
text = response.text.strip('"')
|
|
172
|
+
self.last_response = {"text": text}
|
|
173
|
+
self.conversation.update_chat_history(prompt, text)
|
|
174
|
+
|
|
175
|
+
return self.last_response
|
|
176
|
+
except Exception as e:
|
|
177
|
+
if self.logger:
|
|
178
|
+
self.logger.error(f"Error communicating with Netwrck: {e}")
|
|
179
|
+
raise exceptions.ProviderConnectionError(f"Error communicating with Netwrck: {e}") from e
|
|
180
|
+
|
|
181
|
+
return for_stream() if stream else for_non_stream()
|
|
182
|
+
|
|
183
|
+
def chat(
|
|
184
|
+
self,
|
|
185
|
+
prompt: str,
|
|
186
|
+
stream: bool = False,
|
|
187
|
+
optimizer: Optional[str] = None,
|
|
188
|
+
conversationally: bool = False,
|
|
189
|
+
) -> str:
|
|
190
|
+
"""Generates a response from the Netwrck API."""
|
|
191
|
+
if self.logger:
|
|
192
|
+
self.logger.debug(f"chat() called with prompt: {prompt}")
|
|
193
|
+
|
|
194
|
+
def for_stream():
|
|
195
|
+
for response in self.ask(
|
|
196
|
+
prompt,
|
|
197
|
+
stream=True,
|
|
198
|
+
optimizer=optimizer,
|
|
199
|
+
conversationally=conversationally
|
|
200
|
+
):
|
|
201
|
+
yield self.get_message(response)
|
|
202
|
+
|
|
203
|
+
def for_non_stream():
|
|
204
|
+
return self.get_message(
|
|
205
|
+
self.ask(
|
|
206
|
+
prompt,
|
|
207
|
+
stream=False,
|
|
208
|
+
optimizer=optimizer,
|
|
209
|
+
conversationally=conversationally,
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
return for_stream() if stream else for_non_stream()
|
|
214
|
+
|
|
215
|
+
def get_message(self, response: Dict[str, Any]) -> str:
|
|
216
|
+
"""Retrieves message only from response"""
|
|
217
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
218
|
+
return response["text"]
|
|
219
|
+
|
|
220
|
+
# Example Usage:
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
from rich import print
|
|
223
|
+
|
|
224
|
+
# Non-streaming example
|
|
225
|
+
print("Non-Streaming Response:")
|
|
226
|
+
netwrck = Netwrck(model="lumimaid", logging=True)
|
|
227
|
+
response = netwrck.chat("What is the capital of France?")
|
|
228
|
+
print(response)
|
|
229
|
+
|
|
230
|
+
# Streaming example
|
|
231
|
+
print("\nStreaming Response:")
|
|
232
|
+
response = netwrck.chat("tell me about india", stream=True)
|
|
233
|
+
for chunk in response:
|
|
234
|
+
print(chunk, end="", flush=True)
|
|
235
|
+
print() # Add a newline at the end
|
webscout/Provider/Openai.py
CHANGED
|
@@ -6,7 +6,7 @@ from ..AIbase import Provider, AsyncProvider
|
|
|
6
6
|
|
|
7
7
|
from webscout import exceptions
|
|
8
8
|
from typing import Any, AsyncGenerator, Dict
|
|
9
|
-
|
|
9
|
+
import requests
|
|
10
10
|
import httpx
|
|
11
11
|
#----------------------------------------------------------OpenAI-----------------------------------
|
|
12
12
|
class OPENAI(Provider):
|
|
@@ -27,6 +27,7 @@ class OPENAI(Provider):
|
|
|
27
27
|
proxies: dict = {},
|
|
28
28
|
history_offset: int = 10250,
|
|
29
29
|
act: str = None,
|
|
30
|
+
base_url: str = "https://api.openai.com/v1/chat/completions",
|
|
30
31
|
):
|
|
31
32
|
"""Instantiates OPENAI
|
|
32
33
|
|
|
@@ -55,7 +56,7 @@ class OPENAI(Provider):
|
|
|
55
56
|
self.presence_penalty = presence_penalty
|
|
56
57
|
self.frequency_penalty = frequency_penalty
|
|
57
58
|
self.top_p = top_p
|
|
58
|
-
self.chat_endpoint =
|
|
59
|
+
self.chat_endpoint = base_url
|
|
59
60
|
self.stream_chunk_size = 64
|
|
60
61
|
self.timeout = timeout
|
|
61
62
|
self.last_response = {}
|
|
@@ -63,7 +64,7 @@ class OPENAI(Provider):
|
|
|
63
64
|
"Content-Type": "application/json",
|
|
64
65
|
"Authorization": f"Bearer {self.api_key}",
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
self.session = requests.session()
|
|
67
68
|
self.__available_optimizers = (
|
|
68
69
|
method
|
|
69
70
|
for method in dir(Optimizers)
|
webscout/Provider/PI.py
CHANGED
|
@@ -8,7 +8,7 @@ from webscout.AIutel import Conversation
|
|
|
8
8
|
from webscout.AIutel import AwesomePrompts
|
|
9
9
|
from webscout.AIbase import Provider
|
|
10
10
|
from typing import Dict
|
|
11
|
-
|
|
11
|
+
from webscout import LitAgent
|
|
12
12
|
class PiAI(Provider):
|
|
13
13
|
"""PiAI class for interacting with the Pi.ai chat API, extending the Provider class.
|
|
14
14
|
|
|
@@ -71,7 +71,7 @@ class PiAI(Provider):
|
|
|
71
71
|
'Sec-Fetch-Dest': 'empty',
|
|
72
72
|
'Sec-Fetch-Mode': 'cors',
|
|
73
73
|
'Sec-Fetch-Site': 'same-origin',
|
|
74
|
-
'User-Agent':
|
|
74
|
+
'User-Agent': LitAgent().random(),
|
|
75
75
|
'X-Api-Version': '3'
|
|
76
76
|
}
|
|
77
77
|
self.cookies = {
|
webscout/Provider/PizzaGPT.py
CHANGED
|
@@ -7,7 +7,7 @@ from webscout.AIutel import Conversation
|
|
|
7
7
|
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
8
8
|
from webscout.AIbase import Provider, AsyncProvider
|
|
9
9
|
from webscout import exceptions
|
|
10
|
-
|
|
10
|
+
from webscout import LitAgent as Lit
|
|
11
11
|
|
|
12
12
|
class PIZZAGPT(Provider):
|
|
13
13
|
"""
|
|
@@ -63,7 +63,7 @@ class PIZZAGPT(Provider):
|
|
|
63
63
|
"sec-fetch-dest": "empty",
|
|
64
64
|
"sec-fetch-mode": "cors",
|
|
65
65
|
"sec-fetch-site": "same-origin",
|
|
66
|
-
"user-agent":
|
|
66
|
+
"user-agent": Lit().random(),
|
|
67
67
|
"x-secret": "Marinara"
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -133,7 +133,7 @@ class PIZZAGPT(Provider):
|
|
|
133
133
|
)
|
|
134
134
|
|
|
135
135
|
resp = response.json()
|
|
136
|
-
self.last_response.update(dict(text=resp['
|
|
136
|
+
self.last_response.update(dict(text=resp['content']))
|
|
137
137
|
self.conversation.update_chat_history(
|
|
138
138
|
prompt, self.get_message(self.last_response)
|
|
139
139
|
)
|
|
@@ -2,6 +2,8 @@ import requests
|
|
|
2
2
|
from requests.exceptions import RequestException
|
|
3
3
|
from typing import Any, Dict
|
|
4
4
|
from webscout.AIutel import Conversation, Optimizers
|
|
5
|
+
from webscout.litagent import LitAgent
|
|
6
|
+
from webscout.prompt_manager import AwesomePrompts
|
|
5
7
|
|
|
6
8
|
class TeachAnything:
|
|
7
9
|
"""
|
|
@@ -54,15 +56,26 @@ class TeachAnything:
|
|
|
54
56
|
"content-type": "application/json",
|
|
55
57
|
"origin": "https://www.teach-anything.com",
|
|
56
58
|
"referer": "https://www.teach-anything.com/",
|
|
57
|
-
"user-agent":
|
|
59
|
+
"user-agent": LitAgent().random(),
|
|
58
60
|
}
|
|
61
|
+
self.__available_optimizers = (
|
|
62
|
+
method
|
|
63
|
+
for method in dir(Optimizers)
|
|
64
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
65
|
+
)
|
|
59
66
|
self.session.headers.update(self.headers)
|
|
67
|
+
Conversation.intro = (
|
|
68
|
+
AwesomePrompts().get_act(
|
|
69
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
70
|
+
)
|
|
71
|
+
if act
|
|
72
|
+
else intro or Conversation.intro
|
|
73
|
+
)
|
|
60
74
|
self.conversation = Conversation(
|
|
61
75
|
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
62
76
|
)
|
|
63
77
|
self.conversation.history_offset = history_offset
|
|
64
78
|
self.session.proxies = proxies
|
|
65
|
-
|
|
66
79
|
def ask(
|
|
67
80
|
self,
|
|
68
81
|
prompt: str,
|