webscout 6.6__py3-none-any.whl → 6.8__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/weather.py +5 -5
- webscout/Provider/Cloudflare.py +2 -1
- webscout/Provider/DARKAI.py +2 -2
- webscout/Provider/Free2GPT.py +5 -5
- webscout/Provider/Marcus.py +3 -3
- webscout/Provider/Netwrck.py +238 -234
- webscout/Provider/PI.py +113 -47
- webscout/Provider/Phind.py +6 -0
- webscout/Provider/PizzaGPT.py +62 -53
- webscout/Provider/RUBIKSAI.py +93 -38
- webscout/Provider/__init__.py +0 -6
- webscout/Provider/cleeai.py +2 -2
- webscout/Provider/elmo.py +2 -2
- webscout/Provider/gaurish.py +2 -2
- webscout/Provider/geminiprorealtime.py +2 -2
- webscout/Provider/lepton.py +2 -2
- webscout/Provider/llama3mitril.py +3 -3
- webscout/Provider/llamatutor.py +2 -2
- webscout/Provider/llmchat.py +3 -2
- webscout/Provider/meta.py +3 -3
- webscout/Provider/tutorai.py +1 -1
- webscout/cli.py +31 -39
- webscout/litprinter/__init__.py +16 -7
- webscout/version.py +1 -1
- webscout/webscout_search.py +1 -1
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/METADATA +2 -8
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/RECORD +31 -35
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/entry_points.txt +1 -1
- webscout/Provider/Farfalle.py +0 -227
- webscout/Provider/NinjaChat.py +0 -200
- webscout/Provider/mhystical.py +0 -176
- webstoken/t.py +0 -75
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/LICENSE.md +0 -0
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/WHEEL +0 -0
- {webscout-6.6.dist-info → webscout-6.8.dist-info}/top_level.txt +0 -0
webscout/Extra/weather.py
CHANGED
|
@@ -16,7 +16,7 @@ from rich.columns import Columns
|
|
|
16
16
|
# Initialize Rich console with force terminal
|
|
17
17
|
console = Console(force_terminal=True)
|
|
18
18
|
|
|
19
|
-
def
|
|
19
|
+
def get_emoji(condition: str) -> str:
|
|
20
20
|
"""Get appropriate emoji for weather condition"""
|
|
21
21
|
conditions = {
|
|
22
22
|
'sunny': '*', 'clear': '*',
|
|
@@ -61,7 +61,7 @@ def create_current_weather_panel(data):
|
|
|
61
61
|
location_name = f"{location['areaName'][0]['value']}, {location['country'][0]['value']}"
|
|
62
62
|
|
|
63
63
|
weather_desc = current['weatherDesc'][0]['value']
|
|
64
|
-
symbol =
|
|
64
|
+
symbol = get_emoji(weather_desc)
|
|
65
65
|
|
|
66
66
|
# Create weather info table
|
|
67
67
|
table = Table(show_header=False, box=box.ROUNDED, expand=True)
|
|
@@ -98,7 +98,7 @@ def create_forecast_panel(data):
|
|
|
98
98
|
# Get mid-day conditions (noon)
|
|
99
99
|
noon = day['hourly'][4]
|
|
100
100
|
condition = noon['weatherDesc'][0]['value']
|
|
101
|
-
symbol =
|
|
101
|
+
symbol = get_emoji(condition)
|
|
102
102
|
temp_range = f"{day['mintempC']}° - {day['maxtempC']}°"
|
|
103
103
|
rain_chance = f"v {noon['chanceofrain']}%"
|
|
104
104
|
wind = f"> {noon['windspeedKmph']} km/h"
|
|
@@ -113,7 +113,7 @@ def create_forecast_panel(data):
|
|
|
113
113
|
|
|
114
114
|
return Panel(table, title="[bold]3-Day Forecast[/]", border_style="blue")
|
|
115
115
|
|
|
116
|
-
def
|
|
116
|
+
def get(location: str):
|
|
117
117
|
"""Get weather data with progress indicator"""
|
|
118
118
|
with Progress(
|
|
119
119
|
SpinnerColumn(),
|
|
@@ -159,7 +159,7 @@ def main():
|
|
|
159
159
|
console.print("\n[bold cyan]* Weather Information[/]\n")
|
|
160
160
|
location = console.input("[cyan]Enter location: [/]")
|
|
161
161
|
|
|
162
|
-
weather_data =
|
|
162
|
+
weather_data = get(location)
|
|
163
163
|
if weather_data:
|
|
164
164
|
display_weather(weather_data)
|
|
165
165
|
|
webscout/Provider/Cloudflare.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from uuid import uuid4
|
|
3
|
+
import webscout
|
|
3
4
|
from webscout.AIutel import Optimizers
|
|
4
5
|
from webscout.AIutel import Conversation
|
|
5
6
|
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
@@ -107,7 +108,7 @@ class Cloudflare(Provider):
|
|
|
107
108
|
'Sec-Fetch-Dest': 'empty',
|
|
108
109
|
'Sec-Fetch-Mode': 'cors',
|
|
109
110
|
'Sec-Fetch-Site': 'same-origin',
|
|
110
|
-
'User-Agent':
|
|
111
|
+
'User-Agent': webscout.LitAgent().random()
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
self.cookies = {
|
webscout/Provider/DARKAI.py
CHANGED
|
@@ -4,7 +4,7 @@ from webscout.AIutel import Optimizers
|
|
|
4
4
|
from webscout.AIutel import Conversation
|
|
5
5
|
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
6
6
|
from webscout.AIbase import Provider
|
|
7
|
-
from webscout import exceptions
|
|
7
|
+
from webscout import exceptions, LitAgent
|
|
8
8
|
import requests
|
|
9
9
|
|
|
10
10
|
class DARKAI(Provider):
|
|
@@ -75,7 +75,7 @@ class DARKAI(Provider):
|
|
|
75
75
|
"sec-fetch-dest": "empty",
|
|
76
76
|
"sec-fetch-mode": "cors",
|
|
77
77
|
"sec-fetch-site": "cross-site",
|
|
78
|
-
"user-agent":
|
|
78
|
+
"user-agent": LitAgent().random(),
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
self.__available_optimizers = (
|
webscout/Provider/Free2GPT.py
CHANGED
|
@@ -9,7 +9,7 @@ from webscout.AIutel import Conversation
|
|
|
9
9
|
from webscout.AIutel import AwesomePrompts
|
|
10
10
|
from webscout.AIbase import Provider
|
|
11
11
|
from webscout import exceptions
|
|
12
|
-
|
|
12
|
+
from webscout import LitAgent
|
|
13
13
|
|
|
14
14
|
class Free2GPT(Provider):
|
|
15
15
|
"""
|
|
@@ -48,7 +48,7 @@ class Free2GPT(Provider):
|
|
|
48
48
|
self.session = requests.Session()
|
|
49
49
|
self.is_conversation = is_conversation
|
|
50
50
|
self.max_tokens_to_sample = max_tokens
|
|
51
|
-
self.api_endpoint = "https://
|
|
51
|
+
self.api_endpoint = "https://chat1.free2gpt.com/api/generate"
|
|
52
52
|
self.stream_chunk_size = 64
|
|
53
53
|
self.timeout = timeout
|
|
54
54
|
self.last_response = {}
|
|
@@ -59,15 +59,15 @@ class Free2GPT(Provider):
|
|
|
59
59
|
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
60
60
|
"content-type": "text/plain;charset=UTF-8",
|
|
61
61
|
"dnt": "1",
|
|
62
|
-
"origin": "https://
|
|
63
|
-
"referer": "https://
|
|
62
|
+
"origin": "https://chat1.free2gpt.co",
|
|
63
|
+
"referer": "https://chat1.free2gpt.co",
|
|
64
64
|
"sec-ch-ua": '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
|
|
65
65
|
"sec-ch-ua-mobile": "?0",
|
|
66
66
|
"sec-ch-ua-platform": '"Windows"',
|
|
67
67
|
"sec-fetch-dest": "empty",
|
|
68
68
|
"sec-fetch-mode": "cors",
|
|
69
69
|
"sec-fetch-site": "same-origin",
|
|
70
|
-
"user-agent":
|
|
70
|
+
"user-agent": LitAgent().random(),
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
self.__available_optimizers = (
|
webscout/Provider/Marcus.py
CHANGED
|
@@ -7,7 +7,7 @@ from webscout.AIutel import Conversation
|
|
|
7
7
|
from webscout.AIutel import AwesomePrompts
|
|
8
8
|
from webscout.AIbase import Provider
|
|
9
9
|
from webscout import exceptions
|
|
10
|
-
|
|
10
|
+
from webscout import LitAgent as Lit
|
|
11
11
|
|
|
12
12
|
class Marcus(Provider):
|
|
13
13
|
"""
|
|
@@ -39,7 +39,7 @@ class Marcus(Provider):
|
|
|
39
39
|
'accept': '*/*',
|
|
40
40
|
'origin': 'https://www.askmarcus.app',
|
|
41
41
|
'referer': 'https://www.askmarcus.app/chat',
|
|
42
|
-
'user-agent':
|
|
42
|
+
'user-agent': Lit().random(),
|
|
43
43
|
}
|
|
44
44
|
self.__available_optimizers = (
|
|
45
45
|
method
|
|
@@ -134,4 +134,4 @@ if __name__ == '__main__':
|
|
|
134
134
|
ai = Marcus(timeout=30)
|
|
135
135
|
response = ai.chat("Tell me about India", stream=True)
|
|
136
136
|
for chunk in response:
|
|
137
|
-
print(chunk)
|
|
137
|
+
print(chunk, end="", flush=True)
|
webscout/Provider/Netwrck.py
CHANGED
|
@@ -1,235 +1,239 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
self.
|
|
57
|
-
self.
|
|
58
|
-
self.
|
|
59
|
-
self.
|
|
60
|
-
self.
|
|
61
|
-
self.
|
|
62
|
-
self.
|
|
63
|
-
self.
|
|
64
|
-
self.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'
|
|
72
|
-
'accept
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
self.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
self.conversation
|
|
88
|
-
self.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
decoded_line
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
self.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
response
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
greeting = """An unknown multiverse phenomenon occurred, and you found yourself in a dark space. You looked around and found a source of light in a distance. You approached the light and *whoosh*....\nChoose your origin:\na) As a baby who just got birthed, your fate unknown\nb) As an amnesic stranded on an uninhabited island with mysterious ruins\nc) As an abandoned product of a forbidden experiment\nd) As a slave being sold at an auction\ne) Extremely Chaotic Randomizer\nOr, dive into your own fantasy."""
|
|
22
|
+
|
|
23
|
+
AVAILABLE_MODELS = {
|
|
24
|
+
"lumimaid": "neversleep/llama-3.1-lumimaid-8b",
|
|
25
|
+
"grok": "x-ai/grok-2",
|
|
26
|
+
"claude": "anthropic/claude-3.5-sonnet:beta",
|
|
27
|
+
"euryale": "sao10k/l3-euryale-70b",
|
|
28
|
+
"gpt4mini": "openai/gpt-4o-mini",
|
|
29
|
+
"mythomax": "gryphe/mythomax-l2-13b",
|
|
30
|
+
"gemini": "google/gemini-pro-1.5",
|
|
31
|
+
"lumimaid70b": "neversleep/llama-3.1-lumimaid-70b",
|
|
32
|
+
"nemotron": "nvidia/llama-3.1-nemotron-70b-instruct",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
model: str = "claude",
|
|
38
|
+
is_conversation: bool = True,
|
|
39
|
+
max_tokens: int = 2048,
|
|
40
|
+
timeout: int = 30,
|
|
41
|
+
intro: Optional[str] = None,
|
|
42
|
+
filepath: Optional[str] = None,
|
|
43
|
+
update_file: bool = False,
|
|
44
|
+
proxies: Optional[dict] = None,
|
|
45
|
+
history_offset: int = 0,
|
|
46
|
+
act: Optional[str] = None,
|
|
47
|
+
system_prompt: str = "You are a helpful assistant.",
|
|
48
|
+
temperature: float = 0.7,
|
|
49
|
+
top_p: float = 0.8,
|
|
50
|
+
logging: bool = False
|
|
51
|
+
):
|
|
52
|
+
"""Initializes the Netwrck API client."""
|
|
53
|
+
if model not in self.AVAILABLE_MODELS:
|
|
54
|
+
raise ValueError(f"Invalid model: {model}. Choose from: {list(self.AVAILABLE_MODELS.keys())}")
|
|
55
|
+
|
|
56
|
+
self.model = model
|
|
57
|
+
self.model_name = self.AVAILABLE_MODELS[model]
|
|
58
|
+
self.system_prompt = system_prompt
|
|
59
|
+
self.session = requests.Session()
|
|
60
|
+
self.is_conversation = is_conversation
|
|
61
|
+
self.max_tokens_to_sample = max_tokens
|
|
62
|
+
self.timeout = timeout
|
|
63
|
+
self.last_response: Dict[str, Any] = {}
|
|
64
|
+
self.temperature = temperature
|
|
65
|
+
self.top_p = top_p
|
|
66
|
+
|
|
67
|
+
# Initialize LitAgent for user agent generation
|
|
68
|
+
self.agent = LitAgent()
|
|
69
|
+
|
|
70
|
+
self.headers = {
|
|
71
|
+
'authority': 'netwrck.com',
|
|
72
|
+
'accept': '*/*',
|
|
73
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
74
|
+
'content-type': 'application/json',
|
|
75
|
+
'origin': 'https://netwrck.com',
|
|
76
|
+
'referer': 'https://netwrck.com/',
|
|
77
|
+
'user-agent': self.agent.random()
|
|
78
|
+
}
|
|
79
|
+
self.session.headers.update(self.headers)
|
|
80
|
+
self.proxies = proxies or {}
|
|
81
|
+
|
|
82
|
+
Conversation.intro = (
|
|
83
|
+
AwesomePrompts().get_act(act, raise_not_found=True, default=None, case_insensitive=True)
|
|
84
|
+
if act
|
|
85
|
+
else intro or Conversation.intro
|
|
86
|
+
)
|
|
87
|
+
self.conversation = Conversation(is_conversation, max_tokens, filepath, update_file)
|
|
88
|
+
self.conversation.history_offset = history_offset
|
|
89
|
+
self.__available_optimizers = (
|
|
90
|
+
method
|
|
91
|
+
for method in dir(Optimizers)
|
|
92
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Initialize logger
|
|
96
|
+
self.logger = LitLogger(name="Netwrck", format=LogFormat.MODERN_EMOJI, color_scheme=ColorScheme.CYBERPUNK) if logging else None
|
|
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
|
+
payload = {
|
|
124
|
+
"query": prompt,
|
|
125
|
+
"context": self.system_prompt,
|
|
126
|
+
"examples": [],
|
|
127
|
+
"model_name": self.model_name,
|
|
128
|
+
"greeting": self.greeting
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
def for_stream():
|
|
132
|
+
try:
|
|
133
|
+
response = self.session.post(
|
|
134
|
+
"https://netwrck.com/api/chatpred_or",
|
|
135
|
+
json=payload,
|
|
136
|
+
headers=self.headers,
|
|
137
|
+
proxies=self.proxies,
|
|
138
|
+
timeout=self.timeout,
|
|
139
|
+
stream=True,
|
|
140
|
+
)
|
|
141
|
+
response.raise_for_status()
|
|
142
|
+
|
|
143
|
+
# Initialize an empty string to accumulate the streaming text
|
|
144
|
+
streaming_text = ""
|
|
145
|
+
for line in response.iter_lines():
|
|
146
|
+
if line:
|
|
147
|
+
decoded_line = line.decode('utf-8').strip('"')
|
|
148
|
+
streaming_text += decoded_line # Accumulate the text
|
|
149
|
+
yield {"text": decoded_line} # Yield each chunk
|
|
150
|
+
|
|
151
|
+
# Optionally, you can update the conversation history with the full streaming text
|
|
152
|
+
self.conversation.update_chat_history(payload["query"], streaming_text)
|
|
153
|
+
|
|
154
|
+
except Exception as e:
|
|
155
|
+
if self.logger:
|
|
156
|
+
self.logger.error(f"Error communicating with Netwrck: {e}")
|
|
157
|
+
raise exceptions.ProviderConnectionError(f"Error communicating with Netwrck: {e}") from e
|
|
158
|
+
|
|
159
|
+
except Exception as e:
|
|
160
|
+
if self.logger:
|
|
161
|
+
self.logger.error(f"Error communicating with Netwrck: {e}")
|
|
162
|
+
raise exceptions.ProviderConnectionError(f"Error communicating with Netwrck: {e}") from e
|
|
163
|
+
|
|
164
|
+
def for_non_stream():
|
|
165
|
+
try:
|
|
166
|
+
response = self.session.post(
|
|
167
|
+
"https://netwrck.com/api/chatpred_or",
|
|
168
|
+
json=payload,
|
|
169
|
+
headers=self.headers,
|
|
170
|
+
proxies=self.proxies,
|
|
171
|
+
timeout=self.timeout,
|
|
172
|
+
)
|
|
173
|
+
response.raise_for_status()
|
|
174
|
+
# print(response.text)
|
|
175
|
+
text = response.text.strip('"')
|
|
176
|
+
self.last_response = {"text": text}
|
|
177
|
+
self.conversation.update_chat_history(prompt, text)
|
|
178
|
+
|
|
179
|
+
return self.last_response
|
|
180
|
+
except Exception as e:
|
|
181
|
+
if self.logger:
|
|
182
|
+
self.logger.error(f"Error communicating with Netwrck: {e}")
|
|
183
|
+
raise exceptions.ProviderConnectionError(f"Error communicating with Netwrck: {e}") from e
|
|
184
|
+
|
|
185
|
+
return for_stream() if stream else for_non_stream()
|
|
186
|
+
|
|
187
|
+
def chat(
|
|
188
|
+
self,
|
|
189
|
+
prompt: str,
|
|
190
|
+
stream: bool = False,
|
|
191
|
+
optimizer: Optional[str] = None,
|
|
192
|
+
conversationally: bool = False,
|
|
193
|
+
) -> str:
|
|
194
|
+
"""Generates a response from the Netwrck API."""
|
|
195
|
+
if self.logger:
|
|
196
|
+
self.logger.debug(f"chat() called with prompt: {prompt}")
|
|
197
|
+
|
|
198
|
+
def for_stream():
|
|
199
|
+
for response in self.ask(
|
|
200
|
+
prompt,
|
|
201
|
+
stream=True,
|
|
202
|
+
optimizer=optimizer,
|
|
203
|
+
conversationally=conversationally
|
|
204
|
+
):
|
|
205
|
+
yield self.get_message(response)
|
|
206
|
+
|
|
207
|
+
def for_non_stream():
|
|
208
|
+
return self.get_message(
|
|
209
|
+
self.ask(
|
|
210
|
+
prompt,
|
|
211
|
+
stream=False,
|
|
212
|
+
optimizer=optimizer,
|
|
213
|
+
conversationally=conversationally,
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
return for_stream() if stream else for_non_stream()
|
|
218
|
+
|
|
219
|
+
def get_message(self, response: Dict[str, Any]) -> str:
|
|
220
|
+
"""Retrieves message only from response"""
|
|
221
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
222
|
+
return response["text"]
|
|
223
|
+
|
|
224
|
+
# Example Usage:
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
from rich import print
|
|
227
|
+
|
|
228
|
+
# Non-streaming example
|
|
229
|
+
print("Non-Streaming Response:")
|
|
230
|
+
netwrck = Netwrck(model="claude", logging=True)
|
|
231
|
+
response = netwrck.chat("tell me about Russia")
|
|
232
|
+
print(response)
|
|
233
|
+
|
|
234
|
+
# Streaming example
|
|
235
|
+
print("\nStreaming Response:")
|
|
236
|
+
response = netwrck.chat("tell me about India", stream=True)
|
|
237
|
+
for chunk in response:
|
|
238
|
+
print(chunk, end="", flush=True)
|
|
235
239
|
print() # Add a newline at the end
|