webscout 3.8__tar.gz → 3.9__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-3.8/webscout.egg-info → webscout-3.9}/PKG-INFO +5 -330
- {webscout-3.8 → webscout-3.9}/README.md +4 -329
- {webscout-3.8 → webscout-3.9}/setup.py +1 -1
- {webscout-3.8 → webscout-3.9}/webscout/AIutel.py +5 -1
- {webscout-3.8 → webscout-3.9}/webscout/Local/_version.py +1 -1
- webscout-3.9/webscout/Provider/Geminiflash.py +152 -0
- webscout-3.9/webscout/Provider/Geminipro.py +152 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Youchat.py +5 -1
- {webscout-3.8 → webscout-3.9}/webscout/Provider/__init__.py +6 -0
- {webscout-3.8 → webscout-3.9}/webscout/__init__.py +3 -0
- webscout-3.9/webscout/version.py +2 -0
- {webscout-3.8 → webscout-3.9}/webscout/webai.py +48 -0
- {webscout-3.8 → webscout-3.9/webscout.egg-info}/PKG-INFO +5 -330
- {webscout-3.8 → webscout-3.9}/webscout.egg-info/SOURCES.txt +2 -0
- webscout-3.8/webscout/version.py +0 -2
- {webscout-3.8 → webscout-3.9}/LICENSE.md +0 -0
- {webscout-3.8 → webscout-3.9}/setup.cfg +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/AIauto.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/AIbase.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/DWEBS.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Extra/__init__.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Extra/autollama.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Extra/gguf.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/LLM.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/__init__.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/formats.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/model.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/rawdog.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/samplers.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/thread.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Local/utils.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/BasedGPT.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Berlin4h.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Blackboxai.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/ChatGPTUK.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Cohere.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Deepinfra.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Deepseek.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Gemini.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Groq.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Koboldai.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Leo.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Llama2.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/OpenGPT.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Openai.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Perplexity.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Phind.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Poe.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Reka.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/ThinkAnyAI.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/VTLchat.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Xjai.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/Provider/Yepchat.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/__main__.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/async_providers.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/cli.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/exceptions.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/g4f.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/models.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/tempid.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/transcriber.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/utils.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/voice.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/webscout_search.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/webscout_search_async.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout/websx_search.py +0 -0
- {webscout-3.8 → webscout-3.9}/webscout.egg-info/dependency_links.txt +0 -0
- {webscout-3.8 → webscout-3.9}/webscout.egg-info/entry_points.txt +0 -0
- {webscout-3.8 → webscout-3.9}/webscout.egg-info/requires.txt +0 -0
- {webscout-3.8 → webscout-3.9}/webscout.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: webscout
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.9
|
|
4
4
|
Summary: Search for anything using Google, DuckDuckGo, brave, qwant, 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
|
|
@@ -1421,6 +1421,9 @@ provider = VTLchat()
|
|
|
1421
1421
|
response = provider.chat("Hello, how are you?")
|
|
1422
1422
|
print(response)
|
|
1423
1423
|
```
|
|
1424
|
+
|
|
1425
|
+
### 21. GeminiFlash and geminipro
|
|
1426
|
+
**Usage similar to other providers**
|
|
1424
1427
|
### `LLM`
|
|
1425
1428
|
```python
|
|
1426
1429
|
from webscout.LLM import LLM
|
|
@@ -1698,335 +1701,7 @@ if __name__ == "__main__":
|
|
|
1698
1701
|
```
|
|
1699
1702
|
|
|
1700
1703
|
## `Webai` - terminal gpt and a open interpeter
|
|
1701
|
-
|
|
1702
|
-
```python
|
|
1703
|
-
import time
|
|
1704
|
-
import uuid
|
|
1705
|
-
from typing import Dict, Any, Optional, AsyncGenerator
|
|
1706
|
-
from rich.console import Console
|
|
1707
|
-
from rich.markdown import Markdown
|
|
1708
|
-
from rich.panel import Panel
|
|
1709
|
-
from rich.style import Style
|
|
1710
|
-
import webscout
|
|
1711
|
-
import webscout.AIutel
|
|
1712
|
-
import g4f
|
|
1713
|
-
from webscout.g4f import *
|
|
1714
|
-
from webscout.async_providers import mapper as async_provider_map
|
|
1715
|
-
|
|
1716
|
-
class TaskExecutor:
|
|
1717
|
-
"""
|
|
1718
|
-
Manages an interactive chat session, handling user input, AI responses,
|
|
1719
|
-
and optional features like web search, code execution, and text-to-speech.
|
|
1720
|
-
"""
|
|
1721
|
-
|
|
1722
|
-
def __init__(self) -> None:
|
|
1723
|
-
"""Initializes the conversational assistant with default settings."""
|
|
1724
|
-
self._console: Console = Console()
|
|
1725
|
-
|
|
1726
|
-
# Session configuration
|
|
1727
|
-
self._selected_provider: str = "phind"
|
|
1728
|
-
self._selected_model: str = "Phind Model"
|
|
1729
|
-
self._conversation_enabled: bool = True
|
|
1730
|
-
self._max_tokens: int = 600
|
|
1731
|
-
self._temperature: float = 0.2
|
|
1732
|
-
self._top_k: int = -1
|
|
1733
|
-
self._top_p: float = 0.999
|
|
1734
|
-
self._timeout: int = 30
|
|
1735
|
-
self._auth_token: str = None # API key, if required
|
|
1736
|
-
self._chat_completion_enabled: bool = True # g4fauto
|
|
1737
|
-
self._ignore_working: bool = False # Ignore working status of providers
|
|
1738
|
-
self._proxy_path: str = None # Path to proxy configuration
|
|
1739
|
-
|
|
1740
|
-
# History Management
|
|
1741
|
-
self._history_filepath: str = "history.txt"
|
|
1742
|
-
self._update_history_file: bool = True
|
|
1743
|
-
self._history_offset: int = 10250
|
|
1744
|
-
|
|
1745
|
-
# Prompt Engineering
|
|
1746
|
-
self._initial_prompt: str = None
|
|
1747
|
-
self._awesome_prompt_content: str = None
|
|
1748
|
-
|
|
1749
|
-
# Optional Features
|
|
1750
|
-
self._web_search_enabled: bool = False # Enable web search
|
|
1751
|
-
self._rawdog_enabled: bool = True
|
|
1752
|
-
self._internal_script_execution_enabled: bool = True
|
|
1753
|
-
self._script_confirmation_required: bool = False
|
|
1754
|
-
self._selected_interpreter: str = "python"
|
|
1755
|
-
self._selected_optimizer: str = "code"
|
|
1756
|
-
self._suppress_output: bool = False # Suppress verbose output
|
|
1757
|
-
|
|
1758
|
-
# AI provider mapping
|
|
1759
|
-
self._ai_provider_mapping: Dict[str, Any] = {
|
|
1760
|
-
"phind": webscout.PhindSearch,
|
|
1761
|
-
"opengpt": webscout.OPENGPT,
|
|
1762
|
-
"koboldai": webscout.KOBOLDAI,
|
|
1763
|
-
"blackboxai": webscout.BLACKBOXAI,
|
|
1764
|
-
"llama2": webscout.LLAMA2,
|
|
1765
|
-
"yepchat": webscout.YEPCHAT,
|
|
1766
|
-
"leo": webscout.LEO,
|
|
1767
|
-
"groq": webscout.GROQ,
|
|
1768
|
-
"openai": webscout.OPENAI,
|
|
1769
|
-
"perplexity": webscout.PERPLEXITY,
|
|
1770
|
-
"you": webscout.YouChat,
|
|
1771
|
-
"xjai": webscout.Xjai,
|
|
1772
|
-
"cohere": webscout.Cohere,
|
|
1773
|
-
"reka": webscout.REKA,
|
|
1774
|
-
"thinkany": webscout.ThinkAnyAI,
|
|
1775
|
-
"gemini": webscout.GEMINI,
|
|
1776
|
-
"berlin4h": webscout.Berlin4h,
|
|
1777
|
-
"chatgptuk": webscout.ChatGPTUK,
|
|
1778
|
-
"poe": webscout.POE,
|
|
1779
|
-
"basedgpt": webscout.BasedGPT,
|
|
1780
|
-
"deepseek": webscout.DeepSeek,
|
|
1781
|
-
"deepinfra": webscout.DeepInfra,
|
|
1782
|
-
"opengenptv2": webscout.OPENGPTv2
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
# Initialize Rawdog if enabled
|
|
1786
|
-
if self._rawdog_enabled:
|
|
1787
|
-
self._rawdog_instance: webscout.AIutel.RawDog = webscout.AIutel.RawDog(
|
|
1788
|
-
quiet=self._suppress_output,
|
|
1789
|
-
internal_exec=self._internal_script_execution_enabled,
|
|
1790
|
-
confirm_script=self._script_confirmation_required,
|
|
1791
|
-
interpreter=self._selected_interpreter,
|
|
1792
|
-
)
|
|
1793
|
-
|
|
1794
|
-
self._initial_prompt = self._rawdog_instance.intro_prompt
|
|
1795
|
-
|
|
1796
|
-
# Initialize the selected AI model
|
|
1797
|
-
self._ai_model = self._get_ai_model()
|
|
1798
|
-
|
|
1799
|
-
def _get_ai_model(self):
|
|
1800
|
-
"""
|
|
1801
|
-
Determines the appropriate AI model based on the selected provider,
|
|
1802
|
-
including automatic provider selection and g4fauto support.
|
|
1803
|
-
"""
|
|
1804
|
-
if self._selected_provider == "g4fauto":
|
|
1805
|
-
# Automatically select the best provider from g4f
|
|
1806
|
-
test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
|
|
1807
|
-
g4fauto = test.best if not self._ignore_working else test.auto
|
|
1808
|
-
if isinstance(g4fauto, str):
|
|
1809
|
-
self._selected_provider = "g4fauto+" + g4fauto
|
|
1810
|
-
self._ai_model = self._create_g4f_model(g4fauto)
|
|
1811
|
-
else:
|
|
1812
|
-
raise Exception(
|
|
1813
|
-
"No working g4f provider found. "
|
|
1814
|
-
"Consider running 'webscout.webai gpt4free test -y' first"
|
|
1815
|
-
)
|
|
1816
|
-
else:
|
|
1817
|
-
# Use the specified provider
|
|
1818
|
-
self._ai_model = self._ai_provider_mapping[self._selected_provider](
|
|
1819
|
-
is_conversation=self._conversation_enabled,
|
|
1820
|
-
max_tokens=self._max_tokens,
|
|
1821
|
-
timeout=self._timeout,
|
|
1822
|
-
intro=self._initial_prompt,
|
|
1823
|
-
filepath=self._history_filepath,
|
|
1824
|
-
update_file=self._update_history_file,
|
|
1825
|
-
proxies={}, # Load proxies from config if needed
|
|
1826
|
-
history_offset=self._history_offset,
|
|
1827
|
-
act=self._awesome_prompt_content,
|
|
1828
|
-
model=self._selected_model,
|
|
1829
|
-
quiet=self._suppress_output,
|
|
1830
|
-
# auth=self._auth_token, # Pass API key if required
|
|
1831
|
-
)
|
|
1832
|
-
return self._ai_model
|
|
1833
|
-
|
|
1834
|
-
def _create_g4f_model(self, provider: str):
|
|
1835
|
-
"""
|
|
1836
|
-
Creates a g4f model instance using the provided provider and webscout.WEBS for web search.
|
|
1837
|
-
"""
|
|
1838
|
-
return webscout.g4f.GPT4FREE(
|
|
1839
|
-
provider=provider,
|
|
1840
|
-
auth=self._auth_token,
|
|
1841
|
-
max_tokens=self._max_tokens,
|
|
1842
|
-
chat_completion=self._chat_completion_enabled,
|
|
1843
|
-
ignore_working=self._ignore_working,
|
|
1844
|
-
timeout=self._timeout,
|
|
1845
|
-
intro=self._initial_prompt,
|
|
1846
|
-
filepath=self._history_filepath,
|
|
1847
|
-
update_file=self._update_history_file,
|
|
1848
|
-
proxies={}, # Load proxies from config if needed
|
|
1849
|
-
history_offset=self._history_offset,
|
|
1850
|
-
act=self._awesome_prompt_content,
|
|
1851
|
-
)
|
|
1852
|
-
|
|
1853
|
-
def process_query(self, query: str) -> None:
|
|
1854
|
-
"""
|
|
1855
|
-
Processes a user query, potentially enhancing it with web search results,
|
|
1856
|
-
passing it to the AI model, and handling the response.
|
|
1857
|
-
|
|
1858
|
-
Args:
|
|
1859
|
-
query: The user's text input.
|
|
1860
|
-
|
|
1861
|
-
Returns:
|
|
1862
|
-
None
|
|
1863
|
-
"""
|
|
1864
|
-
if self._web_search_enabled:
|
|
1865
|
-
query = self._augment_query_with_web_search(query)
|
|
1866
|
-
|
|
1867
|
-
# Apply code optimization if configured
|
|
1868
|
-
if self._selected_optimizer == "code":
|
|
1869
|
-
query = webscout.AIutel.Optimizers.code(query)
|
|
1870
|
-
|
|
1871
|
-
try:
|
|
1872
|
-
response: str = self._ai_model.chat(query)
|
|
1873
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1874
|
-
self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
|
|
1875
|
-
return
|
|
1876
|
-
|
|
1877
|
-
# Handle Rawdog responses if enabled
|
|
1878
|
-
if self._rawdog_enabled:
|
|
1879
|
-
self._handle_rawdog_response(response)
|
|
1880
|
-
else:
|
|
1881
|
-
self._console.print(Markdown(f"LLM: {response}"))
|
|
1882
|
-
|
|
1883
|
-
def _augment_query_with_web_search(self, query: str) -> str:
|
|
1884
|
-
"""Performs a web search and appends the results to the query.
|
|
1885
|
-
|
|
1886
|
-
Args:
|
|
1887
|
-
query: The user's text input.
|
|
1888
|
-
|
|
1889
|
-
Returns:
|
|
1890
|
-
str: The augmented query with web search results.
|
|
1891
|
-
"""
|
|
1892
|
-
web_search_results = webscout.WEBS().text(query, max_results=3)
|
|
1893
|
-
if web_search_results:
|
|
1894
|
-
formatted_results = "\n".join(
|
|
1895
|
-
f"{i+1}. {result['title']} - {result['href']}\n\nBody: {result['body']}"
|
|
1896
|
-
for i, result in enumerate(web_search_results)
|
|
1897
|
-
)
|
|
1898
|
-
query += f"\n\n## Web Search Results are:\n\n{formatted_results}"
|
|
1899
|
-
return query
|
|
1900
|
-
|
|
1901
|
-
def _handle_rawdog_response(self, response: str) -> None:
|
|
1902
|
-
"""Handles AI responses, potentially executing them as code with Rawdog.
|
|
1903
|
-
|
|
1904
|
-
Args:
|
|
1905
|
-
response: The AI model's response.
|
|
1906
|
-
|
|
1907
|
-
Returns:
|
|
1908
|
-
None
|
|
1909
|
-
"""
|
|
1910
|
-
try:
|
|
1911
|
-
is_feedback = self._rawdog_instance.main(response)
|
|
1912
|
-
if is_feedback and "PREVIOUS SCRIPT EXCEPTION" in is_feedback:
|
|
1913
|
-
self._console.print(Markdown(f"LLM: {is_feedback}"))
|
|
1914
|
-
error_message = is_feedback.split("PREVIOUS SCRIPT EXCEPTION:\n")[1].strip()
|
|
1915
|
-
# Generate a solution for the error and execute it
|
|
1916
|
-
error_solution_query = (
|
|
1917
|
-
f"The following code was executed and resulted in an error:\n\n"
|
|
1918
|
-
f"{response}\n\n"
|
|
1919
|
-
f"Error: {error_message}\n\n"
|
|
1920
|
-
f"Please provide a solution to fix this error in the code and execute it."
|
|
1921
|
-
)
|
|
1922
|
-
try:
|
|
1923
|
-
new_response = self._ai_model.chat(error_solution_query)
|
|
1924
|
-
self._handle_rawdog_response(new_response)
|
|
1925
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1926
|
-
self._console.print(Markdown(f"LLM: [red]Error while generating solution: {e}[/red]"))
|
|
1927
|
-
else:
|
|
1928
|
-
self._console.print(Markdown("LLM: (Script executed successfully)"))
|
|
1929
|
-
except Exception as e:
|
|
1930
|
-
self._console.print(Markdown(f"LLM: [red]Error: {e}[/red]"))
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
async def process_async_query(self, query: str) -> None:
|
|
1934
|
-
"""
|
|
1935
|
-
Asynchronously processes a user query, potentially enhancing it with web search results,
|
|
1936
|
-
passing it to the AI model, and handling the response.
|
|
1937
|
-
|
|
1938
|
-
Args:
|
|
1939
|
-
query: The user's text input.
|
|
1940
|
-
|
|
1941
|
-
Returns:
|
|
1942
|
-
None
|
|
1943
|
-
"""
|
|
1944
|
-
if self._web_search_enabled:
|
|
1945
|
-
query = self._augment_query_with_web_search(query)
|
|
1946
|
-
|
|
1947
|
-
# Apply code optimization if configured
|
|
1948
|
-
if self._selected_optimizer == "code":
|
|
1949
|
-
query = webscout.AIutel.Optimizers.code(query)
|
|
1950
|
-
|
|
1951
|
-
async_model = self._get_async_ai_model()
|
|
1952
|
-
|
|
1953
|
-
try:
|
|
1954
|
-
async for response in async_model.chat(query, stream=True):
|
|
1955
|
-
self._console.print(Markdown(f"LLM: {response}"), end="")
|
|
1956
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1957
|
-
self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
|
|
1958
|
-
return
|
|
1959
|
-
|
|
1960
|
-
# Handle Rawdog responses if enabled
|
|
1961
|
-
if self._rawdog_enabled:
|
|
1962
|
-
self._handle_rawdog_response(response)
|
|
1963
|
-
else:
|
|
1964
|
-
self._console.print(Markdown(f"LLM: {response}"))
|
|
1965
|
-
|
|
1966
|
-
def _get_async_ai_model(self):
|
|
1967
|
-
"""
|
|
1968
|
-
Determines the appropriate asynchronous AI model based on the selected provider.
|
|
1969
|
-
"""
|
|
1970
|
-
if self._selected_provider == "g4fauto":
|
|
1971
|
-
# Automatically select the best provider from g4f
|
|
1972
|
-
test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
|
|
1973
|
-
g4fauto = test.best if not self._ignore_working else test.auto
|
|
1974
|
-
if isinstance(g4fauto, str):
|
|
1975
|
-
self._selected_provider = "g4fauto+" + g4fauto
|
|
1976
|
-
self._ai_model = self._create_async_g4f_model(g4fauto)
|
|
1977
|
-
else:
|
|
1978
|
-
raise Exception(
|
|
1979
|
-
"No working g4f provider found. "
|
|
1980
|
-
"Consider running 'webscout gpt4free test -y' first"
|
|
1981
|
-
)
|
|
1982
|
-
else:
|
|
1983
|
-
# Use the specified provider
|
|
1984
|
-
if self._selected_provider in async_provider_map:
|
|
1985
|
-
self._ai_model = async_provider_map[self._selected_provider](
|
|
1986
|
-
is_conversation=self._conversation_enabled,
|
|
1987
|
-
max_tokens=self._max_tokens,
|
|
1988
|
-
timeout=self._timeout,
|
|
1989
|
-
intro=self._initial_prompt,
|
|
1990
|
-
filepath=self._history_filepath,
|
|
1991
|
-
update_file=self._update_history_file,
|
|
1992
|
-
proxies={}, # Load proxies from config if needed
|
|
1993
|
-
history_offset=self._history_offset,
|
|
1994
|
-
act=self._awesome_prompt_content,
|
|
1995
|
-
model=self._selected_model,
|
|
1996
|
-
quiet=self._suppress_output,
|
|
1997
|
-
auth=self._auth_token, # Pass API key if required
|
|
1998
|
-
)
|
|
1999
|
-
else:
|
|
2000
|
-
raise Exception(
|
|
2001
|
-
f"Asynchronous provider '{self._selected_provider}' is not yet supported"
|
|
2002
|
-
)
|
|
2003
|
-
return self._ai_model
|
|
2004
|
-
|
|
2005
|
-
def _create_async_g4f_model(self, provider: str):
|
|
2006
|
-
"""
|
|
2007
|
-
Creates an asynchronous g4f model instance using the provided provider and webscout.WEBS for web search.
|
|
2008
|
-
"""
|
|
2009
|
-
return webscout.g4f.AsyncGPT4FREE(
|
|
2010
|
-
provider=provider,
|
|
2011
|
-
auth=self._auth_token,
|
|
2012
|
-
max_tokens=self._max_tokens,
|
|
2013
|
-
chat_completion=self._chat_completion_enabled,
|
|
2014
|
-
ignore_working=self._ignore_working,
|
|
2015
|
-
timeout=self._timeout,
|
|
2016
|
-
intro=self._initial_prompt,
|
|
2017
|
-
filepath=self._history_filepath,
|
|
2018
|
-
update_file=self._update_history_file,
|
|
2019
|
-
proxies={}, # Load proxies from config if needed
|
|
2020
|
-
history_offset=self._history_offset,
|
|
2021
|
-
act=self._awesome_prompt_content,
|
|
2022
|
-
)
|
|
2023
|
-
|
|
2024
|
-
if __name__ == "__main__":
|
|
2025
|
-
assistant = TaskExecutor()
|
|
2026
|
-
while True:
|
|
2027
|
-
input_query = input("Enter your query: ")
|
|
2028
|
-
assistant.process_query(input_query)
|
|
2029
|
-
|
|
1704
|
+
Code is in rawdog.py file
|
|
2030
1705
|
```
|
|
2031
1706
|
```shell
|
|
2032
1707
|
python -m webscout.webai webai --provider "phind" --rawdog
|
|
@@ -1355,6 +1355,9 @@ provider = VTLchat()
|
|
|
1355
1355
|
response = provider.chat("Hello, how are you?")
|
|
1356
1356
|
print(response)
|
|
1357
1357
|
```
|
|
1358
|
+
|
|
1359
|
+
### 21. GeminiFlash and geminipro
|
|
1360
|
+
**Usage similar to other providers**
|
|
1358
1361
|
### `LLM`
|
|
1359
1362
|
```python
|
|
1360
1363
|
from webscout.LLM import LLM
|
|
@@ -1632,335 +1635,7 @@ if __name__ == "__main__":
|
|
|
1632
1635
|
```
|
|
1633
1636
|
|
|
1634
1637
|
## `Webai` - terminal gpt and a open interpeter
|
|
1635
|
-
|
|
1636
|
-
```python
|
|
1637
|
-
import time
|
|
1638
|
-
import uuid
|
|
1639
|
-
from typing import Dict, Any, Optional, AsyncGenerator
|
|
1640
|
-
from rich.console import Console
|
|
1641
|
-
from rich.markdown import Markdown
|
|
1642
|
-
from rich.panel import Panel
|
|
1643
|
-
from rich.style import Style
|
|
1644
|
-
import webscout
|
|
1645
|
-
import webscout.AIutel
|
|
1646
|
-
import g4f
|
|
1647
|
-
from webscout.g4f import *
|
|
1648
|
-
from webscout.async_providers import mapper as async_provider_map
|
|
1649
|
-
|
|
1650
|
-
class TaskExecutor:
|
|
1651
|
-
"""
|
|
1652
|
-
Manages an interactive chat session, handling user input, AI responses,
|
|
1653
|
-
and optional features like web search, code execution, and text-to-speech.
|
|
1654
|
-
"""
|
|
1655
|
-
|
|
1656
|
-
def __init__(self) -> None:
|
|
1657
|
-
"""Initializes the conversational assistant with default settings."""
|
|
1658
|
-
self._console: Console = Console()
|
|
1659
|
-
|
|
1660
|
-
# Session configuration
|
|
1661
|
-
self._selected_provider: str = "phind"
|
|
1662
|
-
self._selected_model: str = "Phind Model"
|
|
1663
|
-
self._conversation_enabled: bool = True
|
|
1664
|
-
self._max_tokens: int = 600
|
|
1665
|
-
self._temperature: float = 0.2
|
|
1666
|
-
self._top_k: int = -1
|
|
1667
|
-
self._top_p: float = 0.999
|
|
1668
|
-
self._timeout: int = 30
|
|
1669
|
-
self._auth_token: str = None # API key, if required
|
|
1670
|
-
self._chat_completion_enabled: bool = True # g4fauto
|
|
1671
|
-
self._ignore_working: bool = False # Ignore working status of providers
|
|
1672
|
-
self._proxy_path: str = None # Path to proxy configuration
|
|
1673
|
-
|
|
1674
|
-
# History Management
|
|
1675
|
-
self._history_filepath: str = "history.txt"
|
|
1676
|
-
self._update_history_file: bool = True
|
|
1677
|
-
self._history_offset: int = 10250
|
|
1678
|
-
|
|
1679
|
-
# Prompt Engineering
|
|
1680
|
-
self._initial_prompt: str = None
|
|
1681
|
-
self._awesome_prompt_content: str = None
|
|
1682
|
-
|
|
1683
|
-
# Optional Features
|
|
1684
|
-
self._web_search_enabled: bool = False # Enable web search
|
|
1685
|
-
self._rawdog_enabled: bool = True
|
|
1686
|
-
self._internal_script_execution_enabled: bool = True
|
|
1687
|
-
self._script_confirmation_required: bool = False
|
|
1688
|
-
self._selected_interpreter: str = "python"
|
|
1689
|
-
self._selected_optimizer: str = "code"
|
|
1690
|
-
self._suppress_output: bool = False # Suppress verbose output
|
|
1691
|
-
|
|
1692
|
-
# AI provider mapping
|
|
1693
|
-
self._ai_provider_mapping: Dict[str, Any] = {
|
|
1694
|
-
"phind": webscout.PhindSearch,
|
|
1695
|
-
"opengpt": webscout.OPENGPT,
|
|
1696
|
-
"koboldai": webscout.KOBOLDAI,
|
|
1697
|
-
"blackboxai": webscout.BLACKBOXAI,
|
|
1698
|
-
"llama2": webscout.LLAMA2,
|
|
1699
|
-
"yepchat": webscout.YEPCHAT,
|
|
1700
|
-
"leo": webscout.LEO,
|
|
1701
|
-
"groq": webscout.GROQ,
|
|
1702
|
-
"openai": webscout.OPENAI,
|
|
1703
|
-
"perplexity": webscout.PERPLEXITY,
|
|
1704
|
-
"you": webscout.YouChat,
|
|
1705
|
-
"xjai": webscout.Xjai,
|
|
1706
|
-
"cohere": webscout.Cohere,
|
|
1707
|
-
"reka": webscout.REKA,
|
|
1708
|
-
"thinkany": webscout.ThinkAnyAI,
|
|
1709
|
-
"gemini": webscout.GEMINI,
|
|
1710
|
-
"berlin4h": webscout.Berlin4h,
|
|
1711
|
-
"chatgptuk": webscout.ChatGPTUK,
|
|
1712
|
-
"poe": webscout.POE,
|
|
1713
|
-
"basedgpt": webscout.BasedGPT,
|
|
1714
|
-
"deepseek": webscout.DeepSeek,
|
|
1715
|
-
"deepinfra": webscout.DeepInfra,
|
|
1716
|
-
"opengenptv2": webscout.OPENGPTv2
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
# Initialize Rawdog if enabled
|
|
1720
|
-
if self._rawdog_enabled:
|
|
1721
|
-
self._rawdog_instance: webscout.AIutel.RawDog = webscout.AIutel.RawDog(
|
|
1722
|
-
quiet=self._suppress_output,
|
|
1723
|
-
internal_exec=self._internal_script_execution_enabled,
|
|
1724
|
-
confirm_script=self._script_confirmation_required,
|
|
1725
|
-
interpreter=self._selected_interpreter,
|
|
1726
|
-
)
|
|
1727
|
-
|
|
1728
|
-
self._initial_prompt = self._rawdog_instance.intro_prompt
|
|
1729
|
-
|
|
1730
|
-
# Initialize the selected AI model
|
|
1731
|
-
self._ai_model = self._get_ai_model()
|
|
1732
|
-
|
|
1733
|
-
def _get_ai_model(self):
|
|
1734
|
-
"""
|
|
1735
|
-
Determines the appropriate AI model based on the selected provider,
|
|
1736
|
-
including automatic provider selection and g4fauto support.
|
|
1737
|
-
"""
|
|
1738
|
-
if self._selected_provider == "g4fauto":
|
|
1739
|
-
# Automatically select the best provider from g4f
|
|
1740
|
-
test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
|
|
1741
|
-
g4fauto = test.best if not self._ignore_working else test.auto
|
|
1742
|
-
if isinstance(g4fauto, str):
|
|
1743
|
-
self._selected_provider = "g4fauto+" + g4fauto
|
|
1744
|
-
self._ai_model = self._create_g4f_model(g4fauto)
|
|
1745
|
-
else:
|
|
1746
|
-
raise Exception(
|
|
1747
|
-
"No working g4f provider found. "
|
|
1748
|
-
"Consider running 'webscout.webai gpt4free test -y' first"
|
|
1749
|
-
)
|
|
1750
|
-
else:
|
|
1751
|
-
# Use the specified provider
|
|
1752
|
-
self._ai_model = self._ai_provider_mapping[self._selected_provider](
|
|
1753
|
-
is_conversation=self._conversation_enabled,
|
|
1754
|
-
max_tokens=self._max_tokens,
|
|
1755
|
-
timeout=self._timeout,
|
|
1756
|
-
intro=self._initial_prompt,
|
|
1757
|
-
filepath=self._history_filepath,
|
|
1758
|
-
update_file=self._update_history_file,
|
|
1759
|
-
proxies={}, # Load proxies from config if needed
|
|
1760
|
-
history_offset=self._history_offset,
|
|
1761
|
-
act=self._awesome_prompt_content,
|
|
1762
|
-
model=self._selected_model,
|
|
1763
|
-
quiet=self._suppress_output,
|
|
1764
|
-
# auth=self._auth_token, # Pass API key if required
|
|
1765
|
-
)
|
|
1766
|
-
return self._ai_model
|
|
1767
|
-
|
|
1768
|
-
def _create_g4f_model(self, provider: str):
|
|
1769
|
-
"""
|
|
1770
|
-
Creates a g4f model instance using the provided provider and webscout.WEBS for web search.
|
|
1771
|
-
"""
|
|
1772
|
-
return webscout.g4f.GPT4FREE(
|
|
1773
|
-
provider=provider,
|
|
1774
|
-
auth=self._auth_token,
|
|
1775
|
-
max_tokens=self._max_tokens,
|
|
1776
|
-
chat_completion=self._chat_completion_enabled,
|
|
1777
|
-
ignore_working=self._ignore_working,
|
|
1778
|
-
timeout=self._timeout,
|
|
1779
|
-
intro=self._initial_prompt,
|
|
1780
|
-
filepath=self._history_filepath,
|
|
1781
|
-
update_file=self._update_history_file,
|
|
1782
|
-
proxies={}, # Load proxies from config if needed
|
|
1783
|
-
history_offset=self._history_offset,
|
|
1784
|
-
act=self._awesome_prompt_content,
|
|
1785
|
-
)
|
|
1786
|
-
|
|
1787
|
-
def process_query(self, query: str) -> None:
|
|
1788
|
-
"""
|
|
1789
|
-
Processes a user query, potentially enhancing it with web search results,
|
|
1790
|
-
passing it to the AI model, and handling the response.
|
|
1791
|
-
|
|
1792
|
-
Args:
|
|
1793
|
-
query: The user's text input.
|
|
1794
|
-
|
|
1795
|
-
Returns:
|
|
1796
|
-
None
|
|
1797
|
-
"""
|
|
1798
|
-
if self._web_search_enabled:
|
|
1799
|
-
query = self._augment_query_with_web_search(query)
|
|
1800
|
-
|
|
1801
|
-
# Apply code optimization if configured
|
|
1802
|
-
if self._selected_optimizer == "code":
|
|
1803
|
-
query = webscout.AIutel.Optimizers.code(query)
|
|
1804
|
-
|
|
1805
|
-
try:
|
|
1806
|
-
response: str = self._ai_model.chat(query)
|
|
1807
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1808
|
-
self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
|
|
1809
|
-
return
|
|
1810
|
-
|
|
1811
|
-
# Handle Rawdog responses if enabled
|
|
1812
|
-
if self._rawdog_enabled:
|
|
1813
|
-
self._handle_rawdog_response(response)
|
|
1814
|
-
else:
|
|
1815
|
-
self._console.print(Markdown(f"LLM: {response}"))
|
|
1816
|
-
|
|
1817
|
-
def _augment_query_with_web_search(self, query: str) -> str:
|
|
1818
|
-
"""Performs a web search and appends the results to the query.
|
|
1819
|
-
|
|
1820
|
-
Args:
|
|
1821
|
-
query: The user's text input.
|
|
1822
|
-
|
|
1823
|
-
Returns:
|
|
1824
|
-
str: The augmented query with web search results.
|
|
1825
|
-
"""
|
|
1826
|
-
web_search_results = webscout.WEBS().text(query, max_results=3)
|
|
1827
|
-
if web_search_results:
|
|
1828
|
-
formatted_results = "\n".join(
|
|
1829
|
-
f"{i+1}. {result['title']} - {result['href']}\n\nBody: {result['body']}"
|
|
1830
|
-
for i, result in enumerate(web_search_results)
|
|
1831
|
-
)
|
|
1832
|
-
query += f"\n\n## Web Search Results are:\n\n{formatted_results}"
|
|
1833
|
-
return query
|
|
1834
|
-
|
|
1835
|
-
def _handle_rawdog_response(self, response: str) -> None:
|
|
1836
|
-
"""Handles AI responses, potentially executing them as code with Rawdog.
|
|
1837
|
-
|
|
1838
|
-
Args:
|
|
1839
|
-
response: The AI model's response.
|
|
1840
|
-
|
|
1841
|
-
Returns:
|
|
1842
|
-
None
|
|
1843
|
-
"""
|
|
1844
|
-
try:
|
|
1845
|
-
is_feedback = self._rawdog_instance.main(response)
|
|
1846
|
-
if is_feedback and "PREVIOUS SCRIPT EXCEPTION" in is_feedback:
|
|
1847
|
-
self._console.print(Markdown(f"LLM: {is_feedback}"))
|
|
1848
|
-
error_message = is_feedback.split("PREVIOUS SCRIPT EXCEPTION:\n")[1].strip()
|
|
1849
|
-
# Generate a solution for the error and execute it
|
|
1850
|
-
error_solution_query = (
|
|
1851
|
-
f"The following code was executed and resulted in an error:\n\n"
|
|
1852
|
-
f"{response}\n\n"
|
|
1853
|
-
f"Error: {error_message}\n\n"
|
|
1854
|
-
f"Please provide a solution to fix this error in the code and execute it."
|
|
1855
|
-
)
|
|
1856
|
-
try:
|
|
1857
|
-
new_response = self._ai_model.chat(error_solution_query)
|
|
1858
|
-
self._handle_rawdog_response(new_response)
|
|
1859
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1860
|
-
self._console.print(Markdown(f"LLM: [red]Error while generating solution: {e}[/red]"))
|
|
1861
|
-
else:
|
|
1862
|
-
self._console.print(Markdown("LLM: (Script executed successfully)"))
|
|
1863
|
-
except Exception as e:
|
|
1864
|
-
self._console.print(Markdown(f"LLM: [red]Error: {e}[/red]"))
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
async def process_async_query(self, query: str) -> None:
|
|
1868
|
-
"""
|
|
1869
|
-
Asynchronously processes a user query, potentially enhancing it with web search results,
|
|
1870
|
-
passing it to the AI model, and handling the response.
|
|
1871
|
-
|
|
1872
|
-
Args:
|
|
1873
|
-
query: The user's text input.
|
|
1874
|
-
|
|
1875
|
-
Returns:
|
|
1876
|
-
None
|
|
1877
|
-
"""
|
|
1878
|
-
if self._web_search_enabled:
|
|
1879
|
-
query = self._augment_query_with_web_search(query)
|
|
1880
|
-
|
|
1881
|
-
# Apply code optimization if configured
|
|
1882
|
-
if self._selected_optimizer == "code":
|
|
1883
|
-
query = webscout.AIutel.Optimizers.code(query)
|
|
1884
|
-
|
|
1885
|
-
async_model = self._get_async_ai_model()
|
|
1886
|
-
|
|
1887
|
-
try:
|
|
1888
|
-
async for response in async_model.chat(query, stream=True):
|
|
1889
|
-
self._console.print(Markdown(f"LLM: {response}"), end="")
|
|
1890
|
-
except webscout.exceptions.FailedToGenerateResponseError as e:
|
|
1891
|
-
self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
|
|
1892
|
-
return
|
|
1893
|
-
|
|
1894
|
-
# Handle Rawdog responses if enabled
|
|
1895
|
-
if self._rawdog_enabled:
|
|
1896
|
-
self._handle_rawdog_response(response)
|
|
1897
|
-
else:
|
|
1898
|
-
self._console.print(Markdown(f"LLM: {response}"))
|
|
1899
|
-
|
|
1900
|
-
def _get_async_ai_model(self):
|
|
1901
|
-
"""
|
|
1902
|
-
Determines the appropriate asynchronous AI model based on the selected provider.
|
|
1903
|
-
"""
|
|
1904
|
-
if self._selected_provider == "g4fauto":
|
|
1905
|
-
# Automatically select the best provider from g4f
|
|
1906
|
-
test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
|
|
1907
|
-
g4fauto = test.best if not self._ignore_working else test.auto
|
|
1908
|
-
if isinstance(g4fauto, str):
|
|
1909
|
-
self._selected_provider = "g4fauto+" + g4fauto
|
|
1910
|
-
self._ai_model = self._create_async_g4f_model(g4fauto)
|
|
1911
|
-
else:
|
|
1912
|
-
raise Exception(
|
|
1913
|
-
"No working g4f provider found. "
|
|
1914
|
-
"Consider running 'webscout gpt4free test -y' first"
|
|
1915
|
-
)
|
|
1916
|
-
else:
|
|
1917
|
-
# Use the specified provider
|
|
1918
|
-
if self._selected_provider in async_provider_map:
|
|
1919
|
-
self._ai_model = async_provider_map[self._selected_provider](
|
|
1920
|
-
is_conversation=self._conversation_enabled,
|
|
1921
|
-
max_tokens=self._max_tokens,
|
|
1922
|
-
timeout=self._timeout,
|
|
1923
|
-
intro=self._initial_prompt,
|
|
1924
|
-
filepath=self._history_filepath,
|
|
1925
|
-
update_file=self._update_history_file,
|
|
1926
|
-
proxies={}, # Load proxies from config if needed
|
|
1927
|
-
history_offset=self._history_offset,
|
|
1928
|
-
act=self._awesome_prompt_content,
|
|
1929
|
-
model=self._selected_model,
|
|
1930
|
-
quiet=self._suppress_output,
|
|
1931
|
-
auth=self._auth_token, # Pass API key if required
|
|
1932
|
-
)
|
|
1933
|
-
else:
|
|
1934
|
-
raise Exception(
|
|
1935
|
-
f"Asynchronous provider '{self._selected_provider}' is not yet supported"
|
|
1936
|
-
)
|
|
1937
|
-
return self._ai_model
|
|
1938
|
-
|
|
1939
|
-
def _create_async_g4f_model(self, provider: str):
|
|
1940
|
-
"""
|
|
1941
|
-
Creates an asynchronous g4f model instance using the provided provider and webscout.WEBS for web search.
|
|
1942
|
-
"""
|
|
1943
|
-
return webscout.g4f.AsyncGPT4FREE(
|
|
1944
|
-
provider=provider,
|
|
1945
|
-
auth=self._auth_token,
|
|
1946
|
-
max_tokens=self._max_tokens,
|
|
1947
|
-
chat_completion=self._chat_completion_enabled,
|
|
1948
|
-
ignore_working=self._ignore_working,
|
|
1949
|
-
timeout=self._timeout,
|
|
1950
|
-
intro=self._initial_prompt,
|
|
1951
|
-
filepath=self._history_filepath,
|
|
1952
|
-
update_file=self._update_history_file,
|
|
1953
|
-
proxies={}, # Load proxies from config if needed
|
|
1954
|
-
history_offset=self._history_offset,
|
|
1955
|
-
act=self._awesome_prompt_content,
|
|
1956
|
-
)
|
|
1957
|
-
|
|
1958
|
-
if __name__ == "__main__":
|
|
1959
|
-
assistant = TaskExecutor()
|
|
1960
|
-
while True:
|
|
1961
|
-
input_query = input("Enter your query: ")
|
|
1962
|
-
assistant.process_query(input_query)
|
|
1963
|
-
|
|
1638
|
+
Code is in rawdog.py file
|
|
1964
1639
|
```
|
|
1965
1640
|
```shell
|
|
1966
1641
|
python -m webscout.webai webai --provider "phind" --rawdog
|