webscout 3.0b0__tar.gz → 3.1__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.

Files changed (73) hide show
  1. {webscout-3.0b0 → webscout-3.1}/PKG-INFO +466 -29
  2. {webscout-3.0b0 → webscout-3.1}/README.md +465 -28
  3. {webscout-3.0b0 → webscout-3.1}/setup.py +1 -1
  4. {webscout-3.0b0 → webscout-3.1}/webscout/Local/__init__.py +1 -0
  5. {webscout-3.0b0 → webscout-3.1}/webscout/Local/_version.py +1 -1
  6. {webscout-3.0b0 → webscout-3.1}/webscout/Local/model.py +33 -35
  7. webscout-3.1/webscout/Local/rawdog.py +946 -0
  8. {webscout-3.0b0 → webscout-3.1}/webscout/Local/thread.py +4 -7
  9. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/BasedGPT.py +225 -225
  10. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Berlin4h.py +210 -210
  11. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Blackboxai.py +439 -439
  12. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/ChatGPTUK.py +213 -213
  13. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Cohere.py +222 -222
  14. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Gemini.py +216 -216
  15. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Groq.py +511 -511
  16. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Koboldai.py +401 -401
  17. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Leo.py +468 -468
  18. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Llama2.py +436 -436
  19. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/OpenGPT.py +486 -486
  20. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Openai.py +510 -510
  21. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Perplexity.py +229 -229
  22. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Phind.py +517 -517
  23. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Poe.py +207 -207
  24. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Reka.py +225 -225
  25. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Xjai.py +230 -230
  26. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Yepchat.py +477 -477
  27. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/Youchat.py +220 -220
  28. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/__init__.py +61 -61
  29. webscout-3.1/webscout/version.py +2 -0
  30. {webscout-3.0b0 → webscout-3.1}/webscout.egg-info/PKG-INFO +466 -29
  31. {webscout-3.0b0 → webscout-3.1}/webscout.egg-info/SOURCES.txt +1 -0
  32. webscout-3.0b0/webscout/version.py +0 -2
  33. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/__init__.py +0 -0
  34. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/documents/__init__.py +0 -0
  35. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/documents/query_results_extractor.py +0 -0
  36. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/documents/webpage_content_extractor.py +0 -0
  37. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/networks/__init__.py +0 -0
  38. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/networks/filepath_converter.py +0 -0
  39. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/networks/google_searcher.py +0 -0
  40. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/networks/network_configs.py +0 -0
  41. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/networks/webpage_fetcher.py +0 -0
  42. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/utilsdw/__init__.py +0 -0
  43. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/utilsdw/enver.py +0 -0
  44. {webscout-3.0b0 → webscout-3.1}/DeepWEBS/utilsdw/logger.py +0 -0
  45. {webscout-3.0b0 → webscout-3.1}/LICENSE.md +0 -0
  46. {webscout-3.0b0 → webscout-3.1}/setup.cfg +0 -0
  47. {webscout-3.0b0 → webscout-3.1}/webscout/AIauto.py +0 -0
  48. {webscout-3.0b0 → webscout-3.1}/webscout/AIbase.py +0 -0
  49. {webscout-3.0b0 → webscout-3.1}/webscout/AIutel.py +0 -0
  50. {webscout-3.0b0 → webscout-3.1}/webscout/DWEBS.py +0 -0
  51. {webscout-3.0b0 → webscout-3.1}/webscout/LLM.py +0 -0
  52. {webscout-3.0b0 → webscout-3.1}/webscout/Local/formats.py +0 -0
  53. {webscout-3.0b0 → webscout-3.1}/webscout/Local/samplers.py +0 -0
  54. {webscout-3.0b0 → webscout-3.1}/webscout/Local/utils.py +0 -0
  55. {webscout-3.0b0 → webscout-3.1}/webscout/Provider/ThinkAnyAI.py +0 -0
  56. {webscout-3.0b0 → webscout-3.1}/webscout/__init__.py +0 -0
  57. {webscout-3.0b0 → webscout-3.1}/webscout/__main__.py +0 -0
  58. {webscout-3.0b0 → webscout-3.1}/webscout/async_providers.py +0 -0
  59. {webscout-3.0b0 → webscout-3.1}/webscout/cli.py +0 -0
  60. {webscout-3.0b0 → webscout-3.1}/webscout/exceptions.py +0 -0
  61. {webscout-3.0b0 → webscout-3.1}/webscout/g4f.py +0 -0
  62. {webscout-3.0b0 → webscout-3.1}/webscout/models.py +0 -0
  63. {webscout-3.0b0 → webscout-3.1}/webscout/tempid.py +0 -0
  64. {webscout-3.0b0 → webscout-3.1}/webscout/transcriber.py +0 -0
  65. {webscout-3.0b0 → webscout-3.1}/webscout/utils.py +0 -0
  66. {webscout-3.0b0 → webscout-3.1}/webscout/voice.py +0 -0
  67. {webscout-3.0b0 → webscout-3.1}/webscout/webai.py +0 -0
  68. {webscout-3.0b0 → webscout-3.1}/webscout/webscout_search.py +0 -0
  69. {webscout-3.0b0 → webscout-3.1}/webscout/webscout_search_async.py +0 -0
  70. {webscout-3.0b0 → webscout-3.1}/webscout.egg-info/dependency_links.txt +0 -0
  71. {webscout-3.0b0 → webscout-3.1}/webscout.egg-info/entry_points.txt +0 -0
  72. {webscout-3.0b0 → webscout-3.1}/webscout.egg-info/requires.txt +0 -0
  73. {webscout-3.0b0 → webscout-3.1}/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.0b0
3
+ Version: 3.1
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
5
5
  Author: OEvortex
6
6
  Author-email: helpingai5@gmail.com
@@ -142,6 +142,8 @@ Search for anything using Google, DuckDuckGo, phind.com, Contains AI models, can
142
142
  - [16. `BasedGPT` - chat with GPT](#16-basedgpt---chat-with-gpt)
143
143
  - [`LLM`](#llm)
144
144
  - [`Local-LLM` webscout can now run GGUF models](#local-llm-webscout-can-now-run-gguf-models)
145
+ - [`Function-calling-local-llm`](#function-calling-local-llm)
146
+ - [`Local-rawdog`](#local-rawdog)
145
147
  - [`LLM` with internet](#llm-with-internet)
146
148
  - [LLM with deepwebs](#llm-with-deepwebs)
147
149
  - [`Webai` - terminal gpt and a open interpeter](#webai---terminal-gpt-and-a-open-interpeter)
@@ -1244,6 +1246,7 @@ while True:
1244
1246
  print("AI: ", response)
1245
1247
  ```
1246
1248
  ### `Local-LLM` webscout can now run GGUF models
1249
+ Local LLM's some functions are taken from easy-llama
1247
1250
  ```python
1248
1251
  from webscout.Local.utils import download_model
1249
1252
  from webscout.Local.model import Model
@@ -1262,6 +1265,165 @@ thread = Thread(model, formats.phi3)
1262
1265
 
1263
1266
  # 4. Start interacting with the model
1264
1267
  thread.interact()
1268
+ ```
1269
+ ### `Function-calling-local-llm`
1270
+ ```python
1271
+ from webscout.Local import Model, Thread, formats
1272
+ from webscout import DeepWEBS
1273
+ from webscout.Local.utils import download_model
1274
+ from webscout.Local.model import Model
1275
+ from webscout.Local.thread import Thread
1276
+ from webscout.Local import formats
1277
+ from webscout.Local.samplers import SamplerSettings
1278
+ def deepwebs_search(query, max_results=5):
1279
+ """Performs a web search using DeepWEBS and returns results as JSON."""
1280
+ deepwebs = DeepWEBS()
1281
+ search_config = DeepWEBS.DeepSearch(
1282
+ queries=[query],
1283
+ max_results=max_results,
1284
+ extract_webpage=False,
1285
+ safe=False,
1286
+ types=["web"],
1287
+ overwrite_query_html=True,
1288
+ overwrite_webpage_html=True,
1289
+ )
1290
+ search_results = deepwebs.queries_to_search_results(search_config)
1291
+ formatted_results = []
1292
+ for result in search_results[0]: # Assuming only one query
1293
+ formatted_results.append(f"Title: {result['title']}\nURL: {result['url']}\n")
1294
+ return "\n".join(formatted_results)
1295
+
1296
+ # Load your model
1297
+ repo_id = "OEvortex/HelpingAI-9B"
1298
+ filename = "helpingai-9b.Q4_0.gguf"
1299
+ model_path = download_model(repo_id, filename, token='')
1300
+
1301
+ # 2. Load the model
1302
+ model = Model(model_path, n_gpu_layers=10)
1303
+
1304
+ # Create a Thread
1305
+ system_prompt = "You are a helpful AI assistant. Respond to user queries concisely. If a user asks for information that requires a web search, use the `deepwebs_search` tool. Do not call the tool if it is not necessary."
1306
+ sampler = SamplerSettings(temp=0.7, top_p=0.9) # Adjust these values as needed
1307
+ # 4. Create a custom chatml format with your system prompt
1308
+ custom_chatml = formats.chatml.copy()
1309
+ custom_chatml['system_content'] = system_prompt
1310
+ thread = Thread(model, custom_chatml, sampler=sampler)
1311
+ # Add the deepwebs_search tool
1312
+ thread.add_tool({
1313
+ "type": "function",
1314
+ "function": {
1315
+ "name": "deepwebs_search",
1316
+ "description": "Performs a web search using DeepWEBS and returns the title and URLs of the results.",
1317
+ "execute": deepwebs_search,
1318
+ "parameters": {
1319
+ "type": "object",
1320
+ "properties": {
1321
+ "query": {
1322
+ "type": "string",
1323
+ "description": "The query to search on the web",
1324
+ },
1325
+ "max_results": {
1326
+ "type": "integer",
1327
+ "description": "Maximum number of search results (default: 5)",
1328
+ },
1329
+ },
1330
+ "required": ["query"],
1331
+ },
1332
+ },
1333
+ })
1334
+
1335
+ # Start interacting with the model
1336
+ while True:
1337
+ user_input = input("You: ")
1338
+ response = thread.send(user_input)
1339
+ print("Bot: ", response)
1340
+ ```
1341
+ ### `Local-rawdog`
1342
+ ```python
1343
+ import webscout.Local as ws
1344
+ from webscout.Local.rawdog import RawDog
1345
+ from webscout.Local.samplers import DefaultSampling
1346
+ from webscout.Local.formats import chatml, AdvancedFormat
1347
+ from webscout.Local.utils import download_model
1348
+ import datetime
1349
+ import sys
1350
+ import os
1351
+
1352
+ repo_id = "YorkieOH10/granite-8b-code-instruct-Q8_0-GGUF"
1353
+ filename = "granite-8b-code-instruct.Q8_0.gguf"
1354
+ model_path = download_model(repo_id, filename, token='')
1355
+
1356
+ # Load the model using the downloaded path
1357
+ model = ws.Model(model_path, n_gpu_layers=10)
1358
+
1359
+ rawdog = RawDog()
1360
+
1361
+ # Create an AdvancedFormat and modify the system content
1362
+ # Use a lambda to generate the prompt dynamically:
1363
+ chat_format = AdvancedFormat(chatml)
1364
+ # **Pre-format the intro_prompt string:**
1365
+ system_content = f"""
1366
+ You are a command-line coding assistant called Rawdog that generates and auto-executes Python scripts.
1367
+
1368
+ A typical interaction goes like this:
1369
+ 1. The user gives you a natural language PROMPT.
1370
+ 2. You:
1371
+ i. Determine what needs to be done
1372
+ ii. Write a short Python SCRIPT to do it
1373
+ iii. Communicate back to the user by printing to the console in that SCRIPT
1374
+ 3. The compiler extracts the script and then runs it using exec(). If there will be an exception raised,
1375
+ it will be send back to you starting with "PREVIOUS SCRIPT EXCEPTION:".
1376
+ 4. In case of exception, regenerate error free script.
1377
+
1378
+ If you need to review script outputs before completing the task, you can print the word "CONTINUE" at the end of your SCRIPT.
1379
+ This can be useful for summarizing documents or technical readouts, reading instructions before
1380
+ deciding what to do, or other tasks that require multi-step reasoning.
1381
+ A typical 'CONTINUE' interaction looks like this:
1382
+ 1. The user gives you a natural language PROMPT.
1383
+ 2. You:
1384
+ i. Determine what needs to be done
1385
+ ii. Determine that you need to see the output of some subprocess call to complete the task
1386
+ iii. Write a short Python SCRIPT to print that and then print the word "CONTINUE"
1387
+ 3. The compiler
1388
+ i. Checks and runs your SCRIPT
1389
+ ii. Captures the output and appends it to the conversation as "LAST SCRIPT OUTPUT:"
1390
+ iii. Finds the word "CONTINUE" and sends control back to you
1391
+ 4. You again:
1392
+ i. Look at the original PROMPT + the "LAST SCRIPT OUTPUT:" to determine what needs to be done
1393
+ ii. Write a short Python SCRIPT to do it
1394
+ iii. Communicate back to the user by printing to the console in that SCRIPT
1395
+ 5. The compiler...
1396
+
1397
+ Please follow these conventions carefully:
1398
+ - Decline any tasks that seem dangerous, irreversible, or that you don't understand.
1399
+ - Always review the full conversation prior to answering and maintain continuity.
1400
+ - If asked for information, just print the information clearly and concisely.
1401
+ - If asked to do something, print a concise summary of what you've done as confirmation.
1402
+ - If asked a question, respond in a friendly, conversational way. Use programmatically-generated and natural language responses as appropriate.
1403
+ - If you need clarification, return a SCRIPT that prints your question. In the next interaction, continue based on the user's response.
1404
+ - Assume the user would like something concise. For example rather than printing a massive table, filter or summarize it to what's likely of interest.
1405
+ - Actively clean up any temporary processes or files you use.
1406
+ - When looking through files, use git as available to skip files, and skip hidden files (.env, .git, etc) by default.
1407
+ - You can plot anything with matplotlib.
1408
+ - ALWAYS Return your SCRIPT inside of a single pair of ``` delimiters. Only the console output of the first such SCRIPT is visible to the user, so make sure that it's complete and don't bother returning anything else.
1409
+ """
1410
+ chat_format.override('system_content', lambda: system_content)
1411
+
1412
+ thread = ws.Thread(model, format=chat_format, sampler=DefaultSampling)
1413
+
1414
+ while True:
1415
+ prompt = input(">: ")
1416
+ if prompt.lower() == "q":
1417
+ break
1418
+
1419
+ response = thread.send(prompt)
1420
+
1421
+ # Process the response using RawDog
1422
+ script_output = rawdog.main(response)
1423
+
1424
+ if script_output:
1425
+ print(script_output)
1426
+
1265
1427
  ```
1266
1428
  ### `LLM` with internet
1267
1429
  ```python
@@ -1427,41 +1589,316 @@ if __name__ == "__main__":
1427
1589
  ## `Webai` - terminal gpt and a open interpeter
1428
1590
 
1429
1591
  ```python
1430
- from webscout.webai import Main
1592
+ import time
1593
+ import uuid
1594
+ from typing import Dict, Any, Optional, AsyncGenerator
1595
+ from rich.console import Console
1596
+ from rich.markdown import Markdown
1597
+ from rich.panel import Panel
1598
+ from rich.style import Style
1599
+ import webscout
1600
+ import webscout.AIutel
1601
+ import g4f
1602
+ from webscout.g4f import *
1603
+ from webscout.async_providers import mapper as async_provider_map
1431
1604
 
1432
- def use_rawdog_with_webai(prompt):
1605
+ class TaskExecutor:
1433
1606
  """
1434
- Wrap the webscout default method in a try-except block to catch any unhandled
1435
- exceptions and print a helpful message.
1607
+ Manages an interactive chat session, handling user input, AI responses,
1608
+ and optional features like web search, code execution, and text-to-speech.
1436
1609
  """
1437
- try:
1438
- webai_bot = Main(
1439
- max_tokens=500,
1440
- provider="cohere",
1441
- temperature=0.7,
1442
- top_k=40,
1443
- top_p=0.95,
1444
- model="command-r-plus", # Replace with your desired model
1445
- auth=None, # Replace with your auth key/value (if needed)
1446
- timeout=30,
1447
- disable_conversation=True,
1448
- filepath=None,
1449
- update_file=True,
1450
- intro=None,
1451
- rawdog=True,
1452
- history_offset=10250,
1453
- awesome_prompt=None,
1454
- proxy_path=None,
1455
- quiet=True
1610
+
1611
+ def __init__(self) -> None:
1612
+ """Initializes the conversational assistant with default settings."""
1613
+ self._console: Console = Console()
1614
+
1615
+ # Session configuration
1616
+ self._selected_provider: str = "phind"
1617
+ self._selected_model: str = "Phind Model"
1618
+ self._conversation_enabled: bool = True
1619
+ self._max_tokens: int = 600
1620
+ self._temperature: float = 0.2
1621
+ self._top_k: int = -1
1622
+ self._top_p: float = 0.999
1623
+ self._timeout: int = 30
1624
+ self._auth_token: str = None # API key, if required
1625
+ self._chat_completion_enabled: bool = True # g4fauto
1626
+ self._ignore_working: bool = False # Ignore working status of providers
1627
+ self._proxy_path: str = None # Path to proxy configuration
1628
+
1629
+ # History Management
1630
+ self._history_filepath: str = None
1631
+ self._update_history_file: bool = True
1632
+ self._history_offset: int = 10250
1633
+
1634
+ # Prompt Engineering
1635
+ self._initial_prompt: str = None
1636
+ self._awesome_prompt_content: str = None
1637
+
1638
+ # Optional Features
1639
+ self._web_search_enabled: bool = False # Enable web search
1640
+ self._rawdog_enabled: bool = True
1641
+ self._internal_script_execution_enabled: bool = False
1642
+ self._script_confirmation_required: bool = False
1643
+ self._selected_interpreter: str = "python"
1644
+ self._selected_optimizer: str = "code"
1645
+ self._suppress_output: bool = False # Suppress verbose output
1646
+
1647
+ # AI provider mapping
1648
+ self._ai_provider_mapping: Dict[str, Any] = {
1649
+ "phind": webscout.PhindSearch,
1650
+ "opengpt": webscout.OPENGPT,
1651
+ "koboldai": webscout.KOBOLDAI,
1652
+ "blackboxai": webscout.BLACKBOXAI,
1653
+ "llama2": webscout.LLAMA2,
1654
+ "yepchat": webscout.YEPCHAT,
1655
+ "leo": webscout.LEO,
1656
+ "groq": webscout.GROQ,
1657
+ "openai": webscout.OPENAI,
1658
+ "perplexity": webscout.PERPLEXITY,
1659
+ "you": webscout.YouChat,
1660
+ "xjai": webscout.Xjai,
1661
+ "cohere": webscout.Cohere,
1662
+ "reka": webscout.REKA,
1663
+ "thinkany": webscout.ThinkAnyAI,
1664
+ "gemini": webscout.GEMINI,
1665
+ "berlin4h": webscout.Berlin4h,
1666
+ "chatgptuk": webscout.ChatGPTUK,
1667
+ "poe": webscout.POE,
1668
+ "basedgpt": webscout.BasedGPT,
1669
+ }
1670
+
1671
+ # Initialize Rawdog if enabled
1672
+ if self._rawdog_enabled:
1673
+ self._rawdog_instance: webscout.AIutel.RawDog = webscout.AIutel.RawDog(
1674
+ quiet=self._suppress_output,
1675
+ internal_exec=self._internal_script_execution_enabled,
1676
+ confirm_script=self._script_confirmation_required,
1677
+ interpreter=self._selected_interpreter,
1678
+ )
1679
+
1680
+ self._initial_prompt = self._rawdog_instance.intro_prompt
1681
+
1682
+ # Initialize the selected AI model
1683
+ self._ai_model = self._get_ai_model()
1684
+
1685
+ def _get_ai_model(self):
1686
+ """
1687
+ Determines the appropriate AI model based on the selected provider,
1688
+ including automatic provider selection and g4fauto support.
1689
+ """
1690
+ if self._selected_provider == "g4fauto":
1691
+ # Automatically select the best provider from g4f
1692
+ test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
1693
+ g4fauto = test.best if not self._ignore_working else test.auto
1694
+ if isinstance(g4fauto, str):
1695
+ self._selected_provider = "g4fauto+" + g4fauto
1696
+ self._ai_model = self._create_g4f_model(g4fauto)
1697
+ else:
1698
+ raise Exception(
1699
+ "No working g4f provider found. "
1700
+ "Consider running 'webscout.webai gpt4free test -y' first"
1701
+ )
1702
+ else:
1703
+ # Use the specified provider
1704
+ self._ai_model = self._ai_provider_mapping[self._selected_provider](
1705
+ is_conversation=self._conversation_enabled,
1706
+ max_tokens=self._max_tokens,
1707
+ timeout=self._timeout,
1708
+ intro=self._initial_prompt,
1709
+ filepath=self._history_filepath,
1710
+ update_file=self._update_history_file,
1711
+ proxies={}, # Load proxies from config if needed
1712
+ history_offset=self._history_offset,
1713
+ act=self._awesome_prompt_content,
1714
+ model=self._selected_model,
1715
+ quiet=self._suppress_output,
1716
+ # auth=self._auth_token, # Pass API key if required
1717
+ )
1718
+ return self._ai_model
1719
+
1720
+ def _create_g4f_model(self, provider: str):
1721
+ """
1722
+ Creates a g4f model instance using the provided provider and webscout.WEBS for web search.
1723
+ """
1724
+ return webscout.g4f.GPT4FREE(
1725
+ provider=provider,
1726
+ auth=self._auth_token,
1727
+ max_tokens=self._max_tokens,
1728
+ chat_completion=self._chat_completion_enabled,
1729
+ ignore_working=self._ignore_working,
1730
+ timeout=self._timeout,
1731
+ intro=self._initial_prompt,
1732
+ filepath=self._history_filepath,
1733
+ update_file=self._update_history_file,
1734
+ proxies={}, # Load proxies from config if needed
1735
+ history_offset=self._history_offset,
1736
+ act=self._awesome_prompt_content,
1456
1737
  )
1457
- webai_response = webai_bot.default(prompt)
1458
- except Exception as e:
1459
- print("Unexpected error:", e)
1460
1738
 
1739
+ def process_query(self, query: str) -> None:
1740
+ """
1741
+ Processes a user query, potentially enhancing it with web search results,
1742
+ passing it to the AI model, and handling the response.
1743
+
1744
+ Args:
1745
+ query: The user's text input.
1746
+
1747
+ Returns:
1748
+ None
1749
+ """
1750
+ if self._web_search_enabled:
1751
+ query = self._augment_query_with_web_search(query)
1752
+
1753
+ # Apply code optimization if configured
1754
+ if self._selected_optimizer == "code":
1755
+ query = webscout.AIutel.Optimizers.code(query)
1756
+
1757
+ try:
1758
+ response: str = self._ai_model.chat(query)
1759
+ except webscout.exceptions.FailedToGenerateResponseError as e:
1760
+ self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
1761
+ return
1762
+
1763
+ # Handle Rawdog responses if enabled
1764
+ if self._rawdog_enabled:
1765
+ self._handle_rawdog_response(response)
1766
+ else:
1767
+ self._console.print(Markdown(f"LLM: {response}"))
1768
+
1769
+ def _augment_query_with_web_search(self, query: str) -> str:
1770
+ """Performs a web search and appends the results to the query.
1771
+
1772
+ Args:
1773
+ query: The user's text input.
1774
+
1775
+ Returns:
1776
+ str: The augmented query with web search results.
1777
+ """
1778
+ web_search_results = webscout.WEBS().text(query, max_results=3)
1779
+ if web_search_results:
1780
+ formatted_results = "\n".join(
1781
+ f"{i+1}. {result['title']} - {result['href']}\n\nBody: {result['body']}"
1782
+ for i, result in enumerate(web_search_results)
1783
+ )
1784
+ query += f"\n\n## Web Search Results are:\n\n{formatted_results}"
1785
+ return query
1786
+
1787
+ def _handle_rawdog_response(self, response: str) -> None:
1788
+ """Handles AI responses, potentially executing them as code with Rawdog.
1789
+
1790
+ Args:
1791
+ response: The AI model's response.
1792
+
1793
+ Returns:
1794
+ None
1795
+ """
1796
+ try:
1797
+ is_feedback = self._rawdog_instance.main(response)
1798
+ except Exception as e:
1799
+ self._console.print(Markdown(f"LLM: [red]Error: {e}[/red]"))
1800
+ return
1801
+ if is_feedback:
1802
+ self._console.print(Markdown(f"LLM: {is_feedback}"))
1803
+ else:
1804
+ self._console.print(Markdown("LLM: (Script executed successfully)"))
1805
+
1806
+ async def process_async_query(self, query: str) -> None:
1807
+ """
1808
+ Asynchronously processes a user query, potentially enhancing it with web search results,
1809
+ passing it to the AI model, and handling the response.
1810
+
1811
+ Args:
1812
+ query: The user's text input.
1813
+
1814
+ Returns:
1815
+ None
1816
+ """
1817
+ if self._web_search_enabled:
1818
+ query = self._augment_query_with_web_search(query)
1819
+
1820
+ # Apply code optimization if configured
1821
+ if self._selected_optimizer == "code":
1822
+ query = webscout.AIutel.Optimizers.code(query)
1823
+
1824
+ async_model = self._get_async_ai_model()
1825
+
1826
+ try:
1827
+ async for response in async_model.chat(query, stream=True):
1828
+ self._console.print(Markdown(f"LLM: {response}"), end="")
1829
+ except webscout.exceptions.FailedToGenerateResponseError as e:
1830
+ self._console.print(Markdown(f"LLM: [red]{e}[/red]"))
1831
+ return
1832
+
1833
+ # Handle Rawdog responses if enabled
1834
+ if self._rawdog_enabled:
1835
+ self._handle_rawdog_response(response)
1836
+ else:
1837
+ self._console.print(Markdown(f"LLM: {response}"))
1838
+
1839
+ def _get_async_ai_model(self):
1840
+ """
1841
+ Determines the appropriate asynchronous AI model based on the selected provider.
1842
+ """
1843
+ if self._selected_provider == "g4fauto":
1844
+ # Automatically select the best provider from g4f
1845
+ test = TestProviders(quiet=self._suppress_output, timeout=self._timeout)
1846
+ g4fauto = test.best if not self._ignore_working else test.auto
1847
+ if isinstance(g4fauto, str):
1848
+ self._selected_provider = "g4fauto+" + g4fauto
1849
+ self._ai_model = self._create_async_g4f_model(g4fauto)
1850
+ else:
1851
+ raise Exception(
1852
+ "No working g4f provider found. "
1853
+ "Consider running 'webscout gpt4free test -y' first"
1854
+ )
1855
+ else:
1856
+ # Use the specified provider
1857
+ if self._selected_provider in async_provider_map:
1858
+ self._ai_model = async_provider_map[self._selected_provider](
1859
+ is_conversation=self._conversation_enabled,
1860
+ max_tokens=self._max_tokens,
1861
+ timeout=self._timeout,
1862
+ intro=self._initial_prompt,
1863
+ filepath=self._history_filepath,
1864
+ update_file=self._update_history_file,
1865
+ proxies={}, # Load proxies from config if needed
1866
+ history_offset=self._history_offset,
1867
+ act=self._awesome_prompt_content,
1868
+ model=self._selected_model,
1869
+ quiet=self._suppress_output,
1870
+ auth=self._auth_token, # Pass API key if required
1871
+ )
1872
+ else:
1873
+ raise Exception(
1874
+ f"Asynchronous provider '{self._selected_provider}' is not yet supported"
1875
+ )
1876
+ return self._ai_model
1877
+
1878
+ def _create_async_g4f_model(self, provider: str):
1879
+ """
1880
+ Creates an asynchronous g4f model instance using the provided provider and webscout.WEBS for web search.
1881
+ """
1882
+ return webscout.g4f.AsyncGPT4FREE(
1883
+ provider=provider,
1884
+ auth=self._auth_token,
1885
+ max_tokens=self._max_tokens,
1886
+ chat_completion=self._chat_completion_enabled,
1887
+ ignore_working=self._ignore_working,
1888
+ timeout=self._timeout,
1889
+ intro=self._initial_prompt,
1890
+ filepath=self._history_filepath,
1891
+ update_file=self._update_history_file,
1892
+ proxies={}, # Load proxies from config if needed
1893
+ history_offset=self._history_offset,
1894
+ act=self._awesome_prompt_content,
1895
+ )
1461
1896
 
1462
1897
  if __name__ == "__main__":
1463
- user_prompt = input("Enter your prompt: ")
1464
- use_rawdog_with_webai(user_prompt)
1898
+ assistant = TaskExecutor()
1899
+ while True:
1900
+ input_query = input("Enter your query: ")
1901
+ assistant.process_query(input_query)
1465
1902
 
1466
1903
  ```
1467
1904
  ```shell