webscout 5.5__tar.gz → 5.6__tar.gz
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-5.5/webscout.egg-info → webscout-5.6}/PKG-INFO +5 -29
- {webscout-5.5 → webscout-5.6}/README.md +3 -28
- {webscout-5.5 → webscout-5.6}/setup.py +1 -0
- {webscout-5.5 → webscout-5.6}/webscout/Agents/Onlinesearcher.py +3 -3
- {webscout-5.5 → webscout-5.6}/webscout/Agents/__init__.py +0 -1
- {webscout-5.5 → webscout-5.6}/webscout/Agents/functioncall.py +3 -3
- webscout-5.6/webscout/Provider/Bing.py +243 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Chatify.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Cloudflare.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/DARKAI.py +1 -1
- webscout-5.6/webscout/Provider/DiscordRocks.py +253 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Farfalle.py +1 -1
- webscout-5.6/webscout/Provider/Free2GPT.py +234 -0
- webscout-5.5/webscout/Provider/Llama3.py → webscout-5.6/webscout/Provider/GPTWeb.py +40 -33
- webscout-5.6/webscout/Provider/Llama3.py +189 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/OLLAMA.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/PizzaGPT.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/RUBIKSAI.py +13 -3
- webscout-5.6/webscout/Provider/TTI/Nexra.py +120 -0
- webscout-5.6/webscout/Provider/TTI/__init__.py +5 -0
- webscout-5.6/webscout/Provider/TTI/blackboximage.py +153 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTI/deepinfra.py +2 -2
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TeachAnything.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Youchat.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/__init__.py +11 -6
- webscout-5.5/webscout/Agents/ai.py → webscout-5.6/webscout/Provider/aigames.py +57 -30
- {webscout-5.5 → webscout-5.6}/webscout/Provider/cleeai.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/elmo.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/felo_search.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/genspark.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/julius.py +7 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/lepton.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/meta.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/turboseek.py +1 -1
- webscout-5.6/webscout/Provider/upstage.py +230 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/x0gpt.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/xdash.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/Provider/yep.py +2 -2
- {webscout-5.5 → webscout-5.6}/webscout/version.py +1 -1
- {webscout-5.5 → webscout-5.6}/webscout/webai.py +1 -1
- {webscout-5.5 → webscout-5.6/webscout.egg-info}/PKG-INFO +5 -29
- {webscout-5.5 → webscout-5.6}/webscout.egg-info/SOURCES.txt +7 -3
- {webscout-5.5 → webscout-5.6}/webscout.egg-info/requires.txt +1 -0
- webscout-5.5/webscout/Provider/DiscordRocks.py +0 -390
- webscout-5.5/webscout/Provider/NetFly.py +0 -216
- webscout-5.5/webscout/Provider/TTI/__init__.py +0 -3
- webscout-5.5/webscout/Provider/ThinkAnyAI.py +0 -219
- {webscout-5.5 → webscout-5.6}/LICENSE.md +0 -0
- {webscout-5.5 → webscout-5.6}/setup.cfg +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/AIauto.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/AIbase.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/AIutel.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Bard.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Bing_search.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/DWEBS.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Extra/__init__.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Extra/autollama.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Extra/gguf.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Extra/weather.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Extra/weather_ascii.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/LLM.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/__init__.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/_version.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/formats.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/model.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/rawdog.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/samplers.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/thread.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Local/utils.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/AI21.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Andi.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/BasedGPT.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Blackboxai.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Cohere.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Deepinfra.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Deepseek.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/EDITEE.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Gemini.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Groq.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Koboldai.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Llama.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Openai.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/PI.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Perplexity.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Phind.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Poe.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/Reka.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTI/PollinationsAI.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTI/aiforce.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTS/__init__.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTS/streamElements.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/TTS/voicepod.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/ai4chat.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/cerebras.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/geminiapi.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/Provider/koala.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/YTdownloader.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/__init__.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/__main__.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/cli.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/exceptions.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/g4f.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/models.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/tempid.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/transcriber.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/utils.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/webscout_search.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/webscout_search_async.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout/websx_search.py +0 -0
- {webscout-5.5 → webscout-5.6}/webscout.egg-info/dependency_links.txt +0 -0
- {webscout-5.5 → webscout-5.6}/webscout.egg-info/entry_points.txt +0 -0
- {webscout-5.5 → webscout-5.6}/webscout.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: webscout
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.6
|
|
4
4
|
Summary: Search for anything using Google, DuckDuckGo, phind.com, Contains AI models, can transcribe yt videos, temporary email and phone number generation, has TTS support, webai (terminal gpt and open interpreter) and offline LLMs and more
|
|
5
5
|
Author: OEvortex
|
|
6
6
|
Author-email: helpingai5@gmail.com
|
|
@@ -54,6 +54,7 @@ Requires-Dist: bson
|
|
|
54
54
|
Requires-Dist: cloudscraper
|
|
55
55
|
Requires-Dist: emoji
|
|
56
56
|
Requires-Dist: openai
|
|
57
|
+
Requires-Dist: prompt-toolkit
|
|
57
58
|
Provides-Extra: dev
|
|
58
59
|
Requires-Dist: ruff>=0.1.6; extra == "dev"
|
|
59
60
|
Requires-Dist: pytest>=7.4.2; extra == "dev"
|
|
@@ -830,7 +831,8 @@ print(result)
|
|
|
830
831
|
___
|
|
831
832
|
</details>
|
|
832
833
|
|
|
833
|
-
### Text to images - DeepInfraImager, PollinationsAI
|
|
834
|
+
### Text to images - DeepInfraImager, PollinationsAI, BlackboxAIImager, AiForceimagger, NexraImager
|
|
835
|
+
**Every TTI provider have same usage code just u need to change import **
|
|
834
836
|
```python
|
|
835
837
|
from webscout import DeepInfraImager
|
|
836
838
|
bot = DeepInfraImager()
|
|
@@ -1067,32 +1069,6 @@ print(response_str)
|
|
|
1067
1069
|
```
|
|
1068
1070
|
|
|
1069
1071
|
|
|
1070
|
-
### `ThinkAny` - AI search engine
|
|
1071
|
-
```python
|
|
1072
|
-
from webscout import ThinkAnyAI
|
|
1073
|
-
|
|
1074
|
-
ai = ThinkAnyAI(
|
|
1075
|
-
is_conversation=True,
|
|
1076
|
-
max_tokens=800,
|
|
1077
|
-
timeout=30,
|
|
1078
|
-
intro=None,
|
|
1079
|
-
filepath=None,
|
|
1080
|
-
update_file=True,
|
|
1081
|
-
proxies={},
|
|
1082
|
-
history_offset=10250,
|
|
1083
|
-
act=None,
|
|
1084
|
-
web_search=False,
|
|
1085
|
-
)
|
|
1086
|
-
|
|
1087
|
-
prompt = "what is meaning of life"
|
|
1088
|
-
|
|
1089
|
-
response = ai.ask(prompt)
|
|
1090
|
-
|
|
1091
|
-
# Extract and print the message from the response
|
|
1092
|
-
message = ai.get_message(response)
|
|
1093
|
-
print(message)
|
|
1094
|
-
```
|
|
1095
|
-
|
|
1096
1072
|
### `poe`- chat with poe
|
|
1097
1073
|
Usage code similar to other proviers
|
|
1098
1074
|
|
|
@@ -1406,7 +1382,7 @@ if "error" not in function_call_data:
|
|
|
1406
1382
|
else:
|
|
1407
1383
|
print(f"Error: {function_call_data['error']}")
|
|
1408
1384
|
```
|
|
1409
|
-
### LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai, AI4Chat, Farfalle, PIAI, Felo, XDASH, Julius, YouChat, YEPCHAT, Cloudflare, TurboSeek,
|
|
1385
|
+
### LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai, AI4Chat, Farfalle, PIAI, Felo, XDASH, Julius, YouChat, YEPCHAT, Cloudflare, TurboSeek, Editee, AI21, Chatify, Cerebras, X0GPT, Lepton, GEMINIAPI, Cleeai, Elmo, Genspark, Upstage, Free2GPT, Bing, DiscordRocks
|
|
1410
1386
|
code similar to other provider
|
|
1411
1387
|
### `LLM`
|
|
1412
1388
|
```python
|
|
@@ -765,7 +765,8 @@ print(result)
|
|
|
765
765
|
___
|
|
766
766
|
</details>
|
|
767
767
|
|
|
768
|
-
### Text to images - DeepInfraImager, PollinationsAI
|
|
768
|
+
### Text to images - DeepInfraImager, PollinationsAI, BlackboxAIImager, AiForceimagger, NexraImager
|
|
769
|
+
**Every TTI provider have same usage code just u need to change import **
|
|
769
770
|
```python
|
|
770
771
|
from webscout import DeepInfraImager
|
|
771
772
|
bot = DeepInfraImager()
|
|
@@ -1002,32 +1003,6 @@ print(response_str)
|
|
|
1002
1003
|
```
|
|
1003
1004
|
|
|
1004
1005
|
|
|
1005
|
-
### `ThinkAny` - AI search engine
|
|
1006
|
-
```python
|
|
1007
|
-
from webscout import ThinkAnyAI
|
|
1008
|
-
|
|
1009
|
-
ai = ThinkAnyAI(
|
|
1010
|
-
is_conversation=True,
|
|
1011
|
-
max_tokens=800,
|
|
1012
|
-
timeout=30,
|
|
1013
|
-
intro=None,
|
|
1014
|
-
filepath=None,
|
|
1015
|
-
update_file=True,
|
|
1016
|
-
proxies={},
|
|
1017
|
-
history_offset=10250,
|
|
1018
|
-
act=None,
|
|
1019
|
-
web_search=False,
|
|
1020
|
-
)
|
|
1021
|
-
|
|
1022
|
-
prompt = "what is meaning of life"
|
|
1023
|
-
|
|
1024
|
-
response = ai.ask(prompt)
|
|
1025
|
-
|
|
1026
|
-
# Extract and print the message from the response
|
|
1027
|
-
message = ai.get_message(response)
|
|
1028
|
-
print(message)
|
|
1029
|
-
```
|
|
1030
|
-
|
|
1031
1006
|
### `poe`- chat with poe
|
|
1032
1007
|
Usage code similar to other proviers
|
|
1033
1008
|
|
|
@@ -1341,7 +1316,7 @@ if "error" not in function_call_data:
|
|
|
1341
1316
|
else:
|
|
1342
1317
|
print(f"Error: {function_call_data['error']}")
|
|
1343
1318
|
```
|
|
1344
|
-
### LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai, AI4Chat, Farfalle, PIAI, Felo, XDASH, Julius, YouChat, YEPCHAT, Cloudflare, TurboSeek,
|
|
1319
|
+
### LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai, AI4Chat, Farfalle, PIAI, Felo, XDASH, Julius, YouChat, YEPCHAT, Cloudflare, TurboSeek, Editee, AI21, Chatify, Cerebras, X0GPT, Lepton, GEMINIAPI, Cleeai, Elmo, Genspark, Upstage, Free2GPT, Bing, DiscordRocks
|
|
1345
1320
|
code similar to other provider
|
|
1346
1321
|
### `LLM`
|
|
1347
1322
|
```python
|
|
@@ -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)
|
|
@@ -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)
|
|
@@ -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)
|