webscout 5.3__py3-none-any.whl → 5.4__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 +8 -12
- webscout/Agents/Onlinesearcher.py +5 -5
- webscout/Agents/functioncall.py +123 -97
- webscout/Local/_version.py +2 -2
- webscout/Provider/Andi.py +1 -21
- webscout/Provider/BasedGPT.py +1 -21
- webscout/Provider/Blackboxai.py +1 -21
- webscout/Provider/Chatify.py +3 -2
- webscout/Provider/Cloudflare.py +1 -22
- webscout/Provider/Cohere.py +2 -23
- webscout/Provider/DARKAI.py +0 -1
- webscout/Provider/Deepinfra.py +2 -16
- webscout/Provider/EDITEE.py +3 -26
- webscout/Provider/Gemini.py +1 -24
- webscout/Provider/Groq.py +0 -2
- webscout/Provider/Koboldai.py +0 -21
- webscout/Provider/Llama.py +4 -21
- webscout/Provider/OLLAMA.py +0 -17
- webscout/Provider/Openai.py +2 -22
- webscout/Provider/Perplexity.py +1 -2
- webscout/Provider/Phind.py +3 -508
- webscout/Provider/Reka.py +4 -21
- webscout/Provider/TTS/streamElements.py +0 -17
- webscout/Provider/TTS/voicepod.py +0 -1
- webscout/Provider/ThinkAnyAI.py +17 -78
- webscout/Provider/Youchat.py +3 -20
- webscout/Provider/__init__.py +12 -5
- webscout/Provider/cleeai.py +212 -0
- webscout/Provider/elmo.py +237 -0
- webscout/Provider/felo_search.py +4 -22
- webscout/Provider/geminiapi.py +198 -0
- webscout/Provider/genspark.py +222 -0
- webscout/Provider/julius.py +3 -20
- webscout/Provider/koala.py +1 -1
- webscout/Provider/lepton.py +194 -0
- webscout/Provider/turboseek.py +4 -21
- webscout/Provider/x0gpt.py +3 -2
- webscout/Provider/xdash.py +2 -22
- webscout/Provider/yep.py +391 -149
- webscout/YTdownloader.py +2 -3
- webscout/version.py +1 -1
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/METADATA +37 -63
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/RECORD +47 -42
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/LICENSE.md +0 -0
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/WHEEL +0 -0
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/entry_points.txt +0 -0
- {webscout-5.3.dist-info → webscout-5.4.dist-info}/top_level.txt +0 -0
webscout/Provider/felo_search.py
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import uuid
|
|
3
|
-
from selenium import webdriver
|
|
4
|
-
from selenium.webdriver.chrome.options import Options
|
|
5
|
-
from selenium.webdriver.common.by import By
|
|
6
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
7
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
8
|
-
import click
|
|
1
|
+
import re
|
|
9
2
|
import requests
|
|
10
|
-
from requests import get
|
|
11
3
|
from uuid import uuid4
|
|
12
|
-
from re import findall
|
|
13
|
-
from requests.exceptions import RequestException
|
|
14
|
-
from curl_cffi.requests import get, RequestsError
|
|
15
|
-
import g4f
|
|
16
|
-
from random import randint
|
|
17
|
-
from PIL import Image
|
|
18
|
-
import io
|
|
19
|
-
import re
|
|
20
4
|
import json
|
|
21
|
-
import yaml
|
|
22
5
|
from webscout.AIutel import Optimizers
|
|
23
6
|
from webscout.AIutel import Conversation
|
|
24
7
|
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
25
8
|
from webscout.AIbase import Provider, AsyncProvider
|
|
26
9
|
from webscout import exceptions
|
|
27
10
|
from typing import Any, AsyncGenerator, Dict
|
|
28
|
-
|
|
29
|
-
import httpx
|
|
11
|
+
|
|
30
12
|
|
|
31
13
|
class Felo(Provider):
|
|
32
14
|
def __init__(
|
|
@@ -188,11 +170,11 @@ class Felo(Provider):
|
|
|
188
170
|
text = re.sub(r'\[\[\d+\]\]', '', response["text"])
|
|
189
171
|
return text
|
|
190
172
|
else:
|
|
191
|
-
return ""
|
|
173
|
+
return ""
|
|
192
174
|
|
|
193
175
|
if __name__ == '__main__':
|
|
194
176
|
from rich import print
|
|
195
177
|
ai = Felo()
|
|
196
|
-
response = ai.chat(input(">>> ")
|
|
178
|
+
response = ai.chat(input(">>> "))
|
|
197
179
|
for chunk in response:
|
|
198
180
|
print(chunk, end="", flush=True)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Install the Google AI Python SDK
|
|
3
|
+
|
|
4
|
+
$ pip install google-generativeai
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import google.generativeai as genai
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
from webscout.AIutel import Optimizers
|
|
12
|
+
from webscout.AIutel import Conversation
|
|
13
|
+
from webscout.AIutel import AwesomePrompts
|
|
14
|
+
from webscout.AIbase import Provider
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class GEMINIAPI(Provider):
|
|
18
|
+
"""
|
|
19
|
+
A class to interact with the Gemini API using the google-generativeai library.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
api_key,
|
|
25
|
+
model_name: str = "gemini-1.5-flash-latest",
|
|
26
|
+
temperature: float = 1,
|
|
27
|
+
top_p: float = 0.95,
|
|
28
|
+
top_k: int = 64,
|
|
29
|
+
max_output_tokens: int = 8192,
|
|
30
|
+
is_conversation: bool = True,
|
|
31
|
+
timeout: int = 30,
|
|
32
|
+
intro: str = None,
|
|
33
|
+
filepath: str = None,
|
|
34
|
+
update_file: bool = True,
|
|
35
|
+
proxies: dict = {},
|
|
36
|
+
history_offset: int = 10250,
|
|
37
|
+
act: str = None,
|
|
38
|
+
system_instruction: str = "You are a helpful and informative AI assistant.",
|
|
39
|
+
):
|
|
40
|
+
"""
|
|
41
|
+
Initializes the Gemini API with the given parameters.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
api_key (str, optional): Your Gemini API key. If None, it will use the environment variable "GEMINI_API_KEY".
|
|
45
|
+
Defaults to None.
|
|
46
|
+
model_name (str, optional): The name of the Gemini model to use.
|
|
47
|
+
Defaults to "gemini-1.5-flash-exp-0827".
|
|
48
|
+
temperature (float, optional): The temperature parameter for the model. Defaults to 1.
|
|
49
|
+
top_p (float, optional): The top_p parameter for the model. Defaults to 0.95.
|
|
50
|
+
top_k (int, optional): The top_k parameter for the model. Defaults to 64.
|
|
51
|
+
max_output_tokens (int, optional): The maximum number of output tokens. Defaults to 8192.
|
|
52
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
53
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
54
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
55
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
56
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
57
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
58
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
59
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
60
|
+
system_instruction (str, optional): System instruction to guide the AI's behavior.
|
|
61
|
+
Defaults to "You are a helpful and informative AI assistant.".
|
|
62
|
+
"""
|
|
63
|
+
self.api_key = api_key
|
|
64
|
+
self.model_name = model_name
|
|
65
|
+
self.temperature = temperature
|
|
66
|
+
self.top_p = top_p
|
|
67
|
+
self.top_k = top_k
|
|
68
|
+
self.max_output_tokens = max_output_tokens
|
|
69
|
+
self.system_instruction = system_instruction
|
|
70
|
+
|
|
71
|
+
self.session = requests.Session() # Not directly used for Gemini API calls, but can be used for other requests
|
|
72
|
+
self.is_conversation = is_conversation
|
|
73
|
+
self.max_tokens_to_sample = max_output_tokens
|
|
74
|
+
self.timeout = timeout
|
|
75
|
+
self.last_response = {}
|
|
76
|
+
|
|
77
|
+
self.__available_optimizers = (
|
|
78
|
+
method
|
|
79
|
+
for method in dir(Optimizers)
|
|
80
|
+
if callable(getattr(Optimizers, method)) and not method.startswith("__")
|
|
81
|
+
)
|
|
82
|
+
Conversation.intro = (
|
|
83
|
+
AwesomePrompts().get_act(
|
|
84
|
+
act, raise_not_found=True, default=None, case_insensitive=True
|
|
85
|
+
)
|
|
86
|
+
if act
|
|
87
|
+
else intro or Conversation.intro
|
|
88
|
+
)
|
|
89
|
+
self.conversation = Conversation(
|
|
90
|
+
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
|
91
|
+
)
|
|
92
|
+
self.conversation.history_offset = history_offset
|
|
93
|
+
self.session.proxies = proxies
|
|
94
|
+
|
|
95
|
+
# Configure the Gemini API
|
|
96
|
+
genai.configure(api_key=self.api_key)
|
|
97
|
+
|
|
98
|
+
# Create the model with generation config
|
|
99
|
+
self.generation_config = {
|
|
100
|
+
"temperature": self.temperature,
|
|
101
|
+
"top_p": self.top_p,
|
|
102
|
+
"top_k": self.top_k,
|
|
103
|
+
"max_output_tokens": self.max_output_tokens,
|
|
104
|
+
"response_mime_type": "text/plain",
|
|
105
|
+
}
|
|
106
|
+
self.model = genai.GenerativeModel(
|
|
107
|
+
model_name=self.model_name,
|
|
108
|
+
generation_config=self.generation_config,
|
|
109
|
+
system_instruction=self.system_instruction,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Start the chat session
|
|
113
|
+
self.chat_session = self.model.start_chat()
|
|
114
|
+
|
|
115
|
+
def ask(
|
|
116
|
+
self,
|
|
117
|
+
prompt: str,
|
|
118
|
+
stream: bool = False,
|
|
119
|
+
raw: bool = False,
|
|
120
|
+
optimizer: str = None,
|
|
121
|
+
conversationally: bool = False,
|
|
122
|
+
) -> dict:
|
|
123
|
+
"""Chat with AI
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
prompt (str): Prompt to be send.
|
|
127
|
+
stream (bool, optional): Not used for Gemini API. Defaults to False.
|
|
128
|
+
raw (bool, optional): Not used for Gemini API. Defaults to False.
|
|
129
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
130
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
131
|
+
Returns:
|
|
132
|
+
dict : {}
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"text" : "How may I assist you today?"
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
"""
|
|
139
|
+
conversation_prompt = self.conversation.gen_complete_prompt(prompt)
|
|
140
|
+
if optimizer:
|
|
141
|
+
if optimizer in self.__available_optimizers:
|
|
142
|
+
conversation_prompt = getattr(Optimizers, optimizer)(
|
|
143
|
+
conversation_prompt if conversationally else prompt
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
raise Exception(
|
|
147
|
+
f"Optimizer is not one of {self.__available_optimizers}"
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Send the message to the chat session and get the response
|
|
151
|
+
response = self.chat_session.send_message(conversation_prompt)
|
|
152
|
+
self.last_response.update(dict(text=response.text))
|
|
153
|
+
self.conversation.update_chat_history(
|
|
154
|
+
prompt, self.get_message(self.last_response)
|
|
155
|
+
)
|
|
156
|
+
return self.last_response
|
|
157
|
+
|
|
158
|
+
def chat(
|
|
159
|
+
self,
|
|
160
|
+
prompt: str,
|
|
161
|
+
stream: bool = False, # Streaming not supported by the current google-generativeai library
|
|
162
|
+
optimizer: str = None,
|
|
163
|
+
conversationally: bool = False,
|
|
164
|
+
) -> str:
|
|
165
|
+
"""Generate response `str`
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
prompt (str): Prompt to be send.
|
|
169
|
+
stream (bool, optional): Not used for Gemini API. Defaults to False.
|
|
170
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
171
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
172
|
+
Returns:
|
|
173
|
+
str: Response generated
|
|
174
|
+
"""
|
|
175
|
+
return self.get_message(
|
|
176
|
+
self.ask(
|
|
177
|
+
prompt,
|
|
178
|
+
optimizer=optimizer,
|
|
179
|
+
conversationally=conversationally,
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
def get_message(self, response: dict) -> str:
|
|
184
|
+
"""Retrieves message only from response
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
response (dict): Response generated by `self.ask`
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
str: Message extracted
|
|
191
|
+
"""
|
|
192
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
193
|
+
return response["text"]
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
ai = GEMINIAPI(api_key="")
|
|
196
|
+
res = ai.chat(input(">>> "))
|
|
197
|
+
for r in res:
|
|
198
|
+
print(r, end="", flush=True)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import cloudscraper
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from webscout.AIutel import Optimizers
|
|
6
|
+
from webscout.AIutel import Conversation
|
|
7
|
+
from webscout.AIutel import AwesomePrompts
|
|
8
|
+
from webscout.AIbase import Provider
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Genspark(Provider):
|
|
12
|
+
"""
|
|
13
|
+
A class to interact with the Genspark.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
|
+
) -> None:
|
|
28
|
+
"""Instantiates Genspark
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
is_conversation (bool, optional): Flag for chatting conversationally. Defaults to True.
|
|
32
|
+
max_tokens (int, optional): Maximum number of tokens to be generated upon completion. Defaults to 600.
|
|
33
|
+
timeout (int, optional): Http request timeout. Defaults to 30.
|
|
34
|
+
intro (str, optional): Conversation introductory prompt. Defaults to None.
|
|
35
|
+
filepath (str, optional): Path to file containing conversation history. Defaults to None.
|
|
36
|
+
update_file (bool, optional): Add new prompts and responses to the file. Defaults to True.
|
|
37
|
+
proxies (dict, optional): Http request proxies. Defaults to {}.
|
|
38
|
+
history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
|
|
39
|
+
act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
|
|
40
|
+
"""
|
|
41
|
+
self.session = cloudscraper.create_scraper()
|
|
42
|
+
self.is_conversation = is_conversation
|
|
43
|
+
self.max_tokens_to_sample = max_tokens
|
|
44
|
+
self.chat_endpoint = "https://www.genspark.ai/api/search/stream"
|
|
45
|
+
self.stream_chunk_size = 64
|
|
46
|
+
self.timeout = timeout
|
|
47
|
+
self.last_response = {}
|
|
48
|
+
self.headers = {
|
|
49
|
+
"Accept": "*/*",
|
|
50
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
51
|
+
"Accept-Language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"DNT": "1",
|
|
54
|
+
"Origin": "https://www.genspark.ai",
|
|
55
|
+
"Priority": "u=1, i",
|
|
56
|
+
"Sec-CH-UA": '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
|
|
57
|
+
"Sec-CH-UA-Mobile": "?0",
|
|
58
|
+
"Sec-CH-UA-Platform": '"Windows"',
|
|
59
|
+
"Sec-Fetch-Dest": "empty",
|
|
60
|
+
"Sec-Fetch-Mode": "cors",
|
|
61
|
+
"Sec-Fetch-Site": "same-origin",
|
|
62
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
|
|
63
|
+
}
|
|
64
|
+
self.cookies = {
|
|
65
|
+
"i18n_redirected": "en-US",
|
|
66
|
+
"agree_terms": "0",
|
|
67
|
+
"session_id": uuid4().hex,
|
|
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.url = (
|
|
125
|
+
f"https://www.genspark.ai/api/search/stream?query={conversation_prompt}"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
payload = {}
|
|
129
|
+
def for_stream():
|
|
130
|
+
response = self.session.post(
|
|
131
|
+
self.url,
|
|
132
|
+
headers=self.headers,
|
|
133
|
+
cookies=self.cookies,
|
|
134
|
+
json=payload,
|
|
135
|
+
stream=True,
|
|
136
|
+
timeout=self.timeout,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
partial_response = ""
|
|
140
|
+
for line in response.iter_lines(decode_unicode=True):
|
|
141
|
+
if line:
|
|
142
|
+
try:
|
|
143
|
+
data = json.loads(line[5:])
|
|
144
|
+
if (
|
|
145
|
+
data["type"] == "result_field"
|
|
146
|
+
and data["field_name"] == "deep_dive_result"
|
|
147
|
+
):
|
|
148
|
+
deep_dive_result = data["field_value"]
|
|
149
|
+
if "detailAnswer" in deep_dive_result:
|
|
150
|
+
new_content = deep_dive_result["detailAnswer"][
|
|
151
|
+
len(partial_response) :
|
|
152
|
+
]
|
|
153
|
+
partial_response = deep_dive_result["detailAnswer"]
|
|
154
|
+
self.last_response.update(dict(text=new_content))
|
|
155
|
+
yield new_content if raw else dict(text=new_content)
|
|
156
|
+
except json.JSONDecodeError:
|
|
157
|
+
print(f"Skipping invalid JSON line: {line}")
|
|
158
|
+
self.conversation.update_chat_history(
|
|
159
|
+
prompt, self.get_message(self.last_response)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
def for_non_stream():
|
|
163
|
+
for _ in for_stream():
|
|
164
|
+
pass
|
|
165
|
+
return self.last_response
|
|
166
|
+
|
|
167
|
+
return for_stream() if stream else for_non_stream()
|
|
168
|
+
|
|
169
|
+
def chat(
|
|
170
|
+
self,
|
|
171
|
+
prompt: str,
|
|
172
|
+
stream: bool = False,
|
|
173
|
+
optimizer: str = None,
|
|
174
|
+
conversationally: bool = False,
|
|
175
|
+
) -> str:
|
|
176
|
+
"""Generate response `str`
|
|
177
|
+
Args:
|
|
178
|
+
prompt (str): Prompt to be send.
|
|
179
|
+
stream (bool, optional): Flag for streaming response. Defaults to False.
|
|
180
|
+
optimizer (str, optional): Prompt optimizer name - `[code, shell_command]`. Defaults to None.
|
|
181
|
+
conversationally (bool, optional): Chat conversationally when using optimizer. Defaults to False.
|
|
182
|
+
Returns:
|
|
183
|
+
str: Response generated
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
def for_stream():
|
|
187
|
+
for response in self.ask(
|
|
188
|
+
prompt, True, optimizer=optimizer, conversationally=conversationally
|
|
189
|
+
):
|
|
190
|
+
yield self.get_message(response)
|
|
191
|
+
|
|
192
|
+
def for_non_stream():
|
|
193
|
+
return self.get_message(
|
|
194
|
+
self.ask(
|
|
195
|
+
prompt,
|
|
196
|
+
False,
|
|
197
|
+
optimizer=optimizer,
|
|
198
|
+
conversationally=conversationally,
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
return for_stream() if stream else for_non_stream()
|
|
203
|
+
|
|
204
|
+
def get_message(self, response: dict) -> str:
|
|
205
|
+
"""Retrieves message only from response
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
response (dict): Response generated by `self.ask`
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
str: Message extracted
|
|
212
|
+
"""
|
|
213
|
+
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
214
|
+
return response["text"]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == "__main__":
|
|
218
|
+
from rich import print
|
|
219
|
+
ai = Genspark()
|
|
220
|
+
response = ai.chat(input(">>> "))
|
|
221
|
+
for chunk in response:
|
|
222
|
+
print(chunk, end="", flush=True)
|
webscout/Provider/julius.py
CHANGED
|
@@ -1,32 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import uuid
|
|
3
|
-
|
|
4
|
-
from selenium.webdriver.chrome.options import Options
|
|
5
|
-
from selenium.webdriver.common.by import By
|
|
6
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
7
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
8
|
-
import click
|
|
3
|
+
|
|
9
4
|
import requests
|
|
10
|
-
from requests import get
|
|
11
|
-
from uuid import uuid4
|
|
12
|
-
from re import findall
|
|
13
|
-
from requests.exceptions import RequestException
|
|
14
|
-
from curl_cffi.requests import get, RequestsError
|
|
15
|
-
import g4f
|
|
16
|
-
from random import randint
|
|
17
|
-
from PIL import Image
|
|
18
|
-
import io
|
|
19
|
-
import re
|
|
20
5
|
import json
|
|
21
|
-
import yaml
|
|
22
6
|
from webscout.AIutel import Optimizers
|
|
23
7
|
from webscout.AIutel import Conversation
|
|
24
8
|
from webscout.AIutel import AwesomePrompts, sanitize_stream
|
|
25
9
|
from webscout.AIbase import Provider, AsyncProvider
|
|
26
10
|
from webscout import exceptions
|
|
27
11
|
from typing import Any, AsyncGenerator, Dict
|
|
28
|
-
|
|
29
|
-
import httpx
|
|
12
|
+
|
|
30
13
|
|
|
31
14
|
class Julius(Provider):
|
|
32
15
|
AVAILABLE_MODELS = [
|
webscout/Provider/koala.py
CHANGED
|
@@ -236,7 +236,7 @@ class KOALA(Provider):
|
|
|
236
236
|
str: Message extracted
|
|
237
237
|
"""
|
|
238
238
|
assert isinstance(response, dict), "Response should be of dict data-type only"
|
|
239
|
-
return response["text"]
|
|
239
|
+
return response["text"].replace('\\n', '\n').replace('\\n\\n', '\n\n')
|
|
240
240
|
if __name__ == '__main__':
|
|
241
241
|
from rich import print
|
|
242
242
|
ai = KOALA()
|