webscout 4.3__tar.gz → 4.5__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 (81) hide show
  1. {webscout-4.3/webscout.egg-info → webscout-4.5}/PKG-INFO +17 -25
  2. {webscout-4.3 → webscout-4.5}/README.md +10 -24
  3. {webscout-4.3 → webscout-4.5}/setup.py +8 -2
  4. {webscout-4.3 → webscout-4.5}/webscout/AIauto.py +5 -7
  5. {webscout-4.3 → webscout-4.5}/webscout/AIutel.py +2 -1
  6. webscout-4.5/webscout/Agents/Onlinesearcher.py +175 -0
  7. webscout-4.5/webscout/Agents/__init__.py +2 -0
  8. webscout-4.5/webscout/Agents/functioncall.py +126 -0
  9. {webscout-4.3 → webscout-4.5}/webscout/Extra/autollama.py +20 -9
  10. {webscout-4.3 → webscout-4.5}/webscout/Extra/gguf.py +5 -19
  11. webscout-4.5/webscout/Extra/weather.py +67 -0
  12. {webscout-4.3 → webscout-4.5}/webscout/Extra/weather_ascii.py +5 -0
  13. webscout-4.5/webscout/GoogleS.py +342 -0
  14. webscout-4.5/webscout/Provider/Andi.py +275 -0
  15. {webscout-4.3 → webscout-4.5}/webscout/Provider/__init__.py +3 -1
  16. {webscout-4.3 → webscout-4.5}/webscout/__init__.py +8 -4
  17. {webscout-4.3 → webscout-4.5}/webscout/cli.py +22 -21
  18. {webscout-4.3 → webscout-4.5}/webscout/utils.py +13 -3
  19. {webscout-4.3 → webscout-4.5}/webscout/voice.py +8 -1
  20. {webscout-4.3 → webscout-4.5}/webscout/webai.py +16 -0
  21. {webscout-4.3 → webscout-4.5}/webscout/webscout_search.py +35 -26
  22. webscout-4.5/webscout/websx_search.py +19 -0
  23. {webscout-4.3 → webscout-4.5/webscout.egg-info}/PKG-INFO +17 -25
  24. {webscout-4.3 → webscout-4.5}/webscout.egg-info/SOURCES.txt +5 -0
  25. {webscout-4.3 → webscout-4.5}/webscout.egg-info/requires.txt +6 -0
  26. webscout-4.3/webscout/Extra/weather.py +0 -49
  27. webscout-4.3/webscout/websx_search.py +0 -370
  28. {webscout-4.3 → webscout-4.5}/LICENSE.md +0 -0
  29. {webscout-4.3 → webscout-4.5}/setup.cfg +0 -0
  30. {webscout-4.3 → webscout-4.5}/webscout/AIbase.py +0 -0
  31. {webscout-4.3 → webscout-4.5}/webscout/DWEBS.py +0 -0
  32. {webscout-4.3 → webscout-4.5}/webscout/Extra/__init__.py +0 -0
  33. {webscout-4.3 → webscout-4.5}/webscout/LLM.py +0 -0
  34. {webscout-4.3 → webscout-4.5}/webscout/Local/__init__.py +0 -0
  35. {webscout-4.3 → webscout-4.5}/webscout/Local/_version.py +0 -0
  36. {webscout-4.3 → webscout-4.5}/webscout/Local/formats.py +0 -0
  37. {webscout-4.3 → webscout-4.5}/webscout/Local/model.py +0 -0
  38. {webscout-4.3 → webscout-4.5}/webscout/Local/rawdog.py +0 -0
  39. {webscout-4.3 → webscout-4.5}/webscout/Local/samplers.py +0 -0
  40. {webscout-4.3 → webscout-4.5}/webscout/Local/thread.py +0 -0
  41. {webscout-4.3 → webscout-4.5}/webscout/Local/utils.py +0 -0
  42. {webscout-4.3 → webscout-4.5}/webscout/Provider/BasedGPT.py +0 -0
  43. {webscout-4.3 → webscout-4.5}/webscout/Provider/Berlin4h.py +0 -0
  44. {webscout-4.3 → webscout-4.5}/webscout/Provider/Blackboxai.py +0 -0
  45. {webscout-4.3 → webscout-4.5}/webscout/Provider/ChatGPTUK.py +0 -0
  46. {webscout-4.3 → webscout-4.5}/webscout/Provider/Cohere.py +0 -0
  47. {webscout-4.3 → webscout-4.5}/webscout/Provider/Deepinfra.py +0 -0
  48. {webscout-4.3 → webscout-4.5}/webscout/Provider/Deepseek.py +0 -0
  49. {webscout-4.3 → webscout-4.5}/webscout/Provider/FreeGemini.py +0 -0
  50. {webscout-4.3 → webscout-4.5}/webscout/Provider/Gemini.py +0 -0
  51. {webscout-4.3 → webscout-4.5}/webscout/Provider/Geminiflash.py +0 -0
  52. {webscout-4.3 → webscout-4.5}/webscout/Provider/Geminipro.py +0 -0
  53. {webscout-4.3 → webscout-4.5}/webscout/Provider/Groq.py +0 -0
  54. {webscout-4.3 → webscout-4.5}/webscout/Provider/Koboldai.py +0 -0
  55. {webscout-4.3 → webscout-4.5}/webscout/Provider/Leo.py +0 -0
  56. {webscout-4.3 → webscout-4.5}/webscout/Provider/Llama.py +0 -0
  57. {webscout-4.3 → webscout-4.5}/webscout/Provider/OLLAMA.py +0 -0
  58. {webscout-4.3 → webscout-4.5}/webscout/Provider/OpenGPT.py +0 -0
  59. {webscout-4.3 → webscout-4.5}/webscout/Provider/Openai.py +0 -0
  60. {webscout-4.3 → webscout-4.5}/webscout/Provider/Perplexity.py +0 -0
  61. {webscout-4.3 → webscout-4.5}/webscout/Provider/Phind.py +0 -0
  62. {webscout-4.3 → webscout-4.5}/webscout/Provider/Poe.py +0 -0
  63. {webscout-4.3 → webscout-4.5}/webscout/Provider/Reka.py +0 -0
  64. {webscout-4.3 → webscout-4.5}/webscout/Provider/ThinkAnyAI.py +0 -0
  65. {webscout-4.3 → webscout-4.5}/webscout/Provider/VTLchat.py +0 -0
  66. {webscout-4.3 → webscout-4.5}/webscout/Provider/Xjai.py +0 -0
  67. {webscout-4.3 → webscout-4.5}/webscout/Provider/Yepchat.py +0 -0
  68. {webscout-4.3 → webscout-4.5}/webscout/Provider/Youchat.py +0 -0
  69. {webscout-4.3 → webscout-4.5}/webscout/YTdownloader.py +0 -0
  70. {webscout-4.3 → webscout-4.5}/webscout/__main__.py +0 -0
  71. {webscout-4.3 → webscout-4.5}/webscout/async_providers.py +0 -0
  72. {webscout-4.3 → webscout-4.5}/webscout/exceptions.py +0 -0
  73. {webscout-4.3 → webscout-4.5}/webscout/g4f.py +0 -0
  74. {webscout-4.3 → webscout-4.5}/webscout/models.py +0 -0
  75. {webscout-4.3 → webscout-4.5}/webscout/tempid.py +0 -0
  76. {webscout-4.3 → webscout-4.5}/webscout/transcriber.py +0 -0
  77. {webscout-4.3 → webscout-4.5}/webscout/version.py +0 -0
  78. {webscout-4.3 → webscout-4.5}/webscout/webscout_search_async.py +0 -0
  79. {webscout-4.3 → webscout-4.5}/webscout.egg-info/dependency_links.txt +0 -0
  80. {webscout-4.3 → webscout-4.5}/webscout.egg-info/entry_points.txt +0 -0
  81. {webscout-4.3 → webscout-4.5}/webscout.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webscout
3
- Version: 4.3
3
+ Version: 4.5
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
@@ -34,6 +34,7 @@ Requires-Dist: tqdm
34
34
  Requires-Dist: webdriver-manager
35
35
  Requires-Dist: halo>=0.0.31
36
36
  Requires-Dist: g4f>=0.2.2.3
37
+ Requires-Dist: g4f[webdriver]
37
38
  Requires-Dist: rich
38
39
  Requires-Dist: python-dotenv
39
40
  Requires-Dist: beautifulsoup4
@@ -55,6 +56,11 @@ Requires-Dist: playsound
55
56
  Requires-Dist: poe_api_wrapper
56
57
  Requires-Dist: pyreqwest_impersonate
57
58
  Requires-Dist: ballyregan
59
+ Requires-Dist: nodriver
60
+ Requires-Dist: PyExecJS
61
+ Requires-Dist: ollama
62
+ Requires-Dist: pyfiglet
63
+ Requires-Dist: yaspin
58
64
  Provides-Extra: dev
59
65
  Requires-Dist: ruff>=0.1.6; extra == "dev"
60
66
  Requires-Dist: pytest>=7.4.2; extra == "dev"
@@ -736,30 +742,11 @@ with WEBS() as WEBS:
736
742
  ## usage of WEBSX -- Another Websearch thing
737
743
  ```python
738
744
  from webscout import WEBSX
745
+ s = "Python development tools"
739
746
 
740
- def main():
741
- # Initialize the WEBSX client
742
- search = WEBSX(
743
- k=10,
744
- )
747
+ result = WEBSX(s)
745
748
 
746
- # Example using `run` method - Get a summary
747
- query = "What is the capital of France?"
748
- answer = search.run(query)
749
- print(f"Answer: {answer}\n")
750
-
751
- # Example using `results` method - Get detailed results with metadata
752
- query = "What is the capital of France?"
753
- results = search.results(query, num_results=3)
754
- print("Search Results:")
755
- for result in results:
756
- print(f"Title: {result['title']}")
757
- print(f"Snippet: {result['snippet']}")
758
- print(f"Link: {result['link']}\n")
759
- print(f'Engines: {result["engines"]}')
760
-
761
- if __name__ == "__main__":
762
- main()
749
+ print(result)
763
750
  ```
764
751
  ## ALL acts
765
752
  <details>
@@ -1022,7 +1009,7 @@ ___
1022
1009
  ### 0. `Duckchat` - chat with LLM
1023
1010
  ```python
1024
1011
  from webscout import WEBS as w
1025
- R = w().chat("hello", model='claude-3-haiku') # GPT-3.5 Turbo, mixtral-8x7b, llama-3-70b, claude-3-haiku
1012
+ R = w().chat("Who are you", model='gpt-4o-mini') # GPT-3.5 Turbo, mixtral-8x7b, llama-3-70b, claude-3-haiku, gpt-4o-mini
1026
1013
  print(R)
1027
1014
  ```
1028
1015
  ### 1. `PhindSearch` - Search using Phind.com
@@ -1499,7 +1486,12 @@ llama = LLAMA()
1499
1486
  r = llama.chat("What is the meaning of life?")
1500
1487
  print(r)
1501
1488
  ```
1502
-
1489
+ ### 25. AndiSearch
1490
+ ```python
1491
+ from webscout import AndiSearch
1492
+ a = AndiSearch()
1493
+ print(a.chat("HelpingAI-9B"))
1494
+ ```
1503
1495
  ### `LLM`
1504
1496
  ```python
1505
1497
  from webscout.LLM import LLM
@@ -670,30 +670,11 @@ with WEBS() as WEBS:
670
670
  ## usage of WEBSX -- Another Websearch thing
671
671
  ```python
672
672
  from webscout import WEBSX
673
+ s = "Python development tools"
673
674
 
674
- def main():
675
- # Initialize the WEBSX client
676
- search = WEBSX(
677
- k=10,
678
- )
675
+ result = WEBSX(s)
679
676
 
680
- # Example using `run` method - Get a summary
681
- query = "What is the capital of France?"
682
- answer = search.run(query)
683
- print(f"Answer: {answer}\n")
684
-
685
- # Example using `results` method - Get detailed results with metadata
686
- query = "What is the capital of France?"
687
- results = search.results(query, num_results=3)
688
- print("Search Results:")
689
- for result in results:
690
- print(f"Title: {result['title']}")
691
- print(f"Snippet: {result['snippet']}")
692
- print(f"Link: {result['link']}\n")
693
- print(f'Engines: {result["engines"]}')
694
-
695
- if __name__ == "__main__":
696
- main()
677
+ print(result)
697
678
  ```
698
679
  ## ALL acts
699
680
  <details>
@@ -956,7 +937,7 @@ ___
956
937
  ### 0. `Duckchat` - chat with LLM
957
938
  ```python
958
939
  from webscout import WEBS as w
959
- R = w().chat("hello", model='claude-3-haiku') # GPT-3.5 Turbo, mixtral-8x7b, llama-3-70b, claude-3-haiku
940
+ R = w().chat("Who are you", model='gpt-4o-mini') # GPT-3.5 Turbo, mixtral-8x7b, llama-3-70b, claude-3-haiku, gpt-4o-mini
960
941
  print(R)
961
942
  ```
962
943
  ### 1. `PhindSearch` - Search using Phind.com
@@ -1433,7 +1414,12 @@ llama = LLAMA()
1433
1414
  r = llama.chat("What is the meaning of life?")
1434
1415
  print(r)
1435
1416
  ```
1436
-
1417
+ ### 25. AndiSearch
1418
+ ```python
1419
+ from webscout import AndiSearch
1420
+ a = AndiSearch()
1421
+ print(a.chat("HelpingAI-9B"))
1422
+ ```
1437
1423
  ### `LLM`
1438
1424
  ```python
1439
1425
  from webscout.LLM import LLM
@@ -5,7 +5,7 @@ with open("README.md", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name="webscout",
8
- version="4.3",
8
+ version="4.5",
9
9
  description="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",
10
10
  long_description=README,
11
11
  long_description_content_type="text/markdown",
@@ -38,6 +38,7 @@ setup(
38
38
  "webdriver-manager",
39
39
  "halo>=0.0.31",
40
40
  "g4f>=0.2.2.3",
41
+ "g4f[webdriver]",
41
42
  "rich",
42
43
  "python-dotenv",
43
44
  "beautifulsoup4",
@@ -58,7 +59,12 @@ setup(
58
59
  "playsound",
59
60
  "poe_api_wrapper",
60
61
  "pyreqwest_impersonate",
61
- "ballyregan"
62
+ "ballyregan",
63
+ "nodriver",
64
+ "PyExecJS",
65
+ "ollama",
66
+ "pyfiglet",
67
+ "yaspin",
62
68
  ],
63
69
  entry_points={
64
70
  "console_scripts": [
@@ -1,8 +1,7 @@
1
1
  from webscout.AIbase import Provider, AsyncProvider
2
2
  from webscout.Provider.ThinkAnyAI import ThinkAnyAI
3
3
  from webscout.Provider.Xjai import Xjai
4
- from webscout.Provider.Llama import LLAMA2
5
- from webscout.Provider.Llama import AsyncLLAMA2
4
+ from webscout.Provider.Llama import LLAMA
6
5
  from webscout.Provider.Leo import LEO
7
6
  from webscout.Provider.Leo import AsyncLEO
8
7
  from webscout.Provider.Koboldai import KOBOLDAI
@@ -44,7 +43,7 @@ provider_map: dict[
44
43
  Union[
45
44
  ThinkAnyAI,
46
45
  Xjai,
47
- LLAMA2,
46
+ LLAMA,
48
47
  LEO,
49
48
  KOBOLDAI,
50
49
  OPENGPT,
@@ -69,7 +68,7 @@ provider_map: dict[
69
68
  ] = {
70
69
  "ThinkAnyAI": ThinkAnyAI,
71
70
  "Xjai": Xjai,
72
- "LLAMA2": LLAMA2,
71
+ "LLAMA2": LLAMA,
73
72
  "LEO": LEO,
74
73
  "KOBOLDAI": KOBOLDAI,
75
74
  "OPENGPT": OPENGPT,
@@ -124,7 +123,7 @@ class AUTO(Provider):
124
123
  self.provider: Union[
125
124
  ThinkAnyAI,
126
125
  Xjai,
127
- LLAMA2,
126
+ LLAMA,
128
127
  LEO,
129
128
  KOBOLDAI,
130
129
  OPENGPT,
@@ -353,13 +352,12 @@ class AsyncAUTO(AsyncProvider):
353
352
  AsyncOPENGPT,
354
353
  AsyncKOBOLDAI,
355
354
  AsyncPhindSearch,
356
- AsyncLLAMA2,
357
355
  AsyncBLACKBOXAI,
358
356
  AsyncGPT4FREE,
359
357
  AsyncLEO,
360
358
  ThinkAnyAI,
361
359
  Xjai,
362
- LLAMA2,
360
+ LLAMA,
363
361
  LEO,
364
362
  KOBOLDAI,
365
363
  OPENGPT,
@@ -52,7 +52,8 @@ webai = [
52
52
  "vtlchat",
53
53
  "geminiflash",
54
54
  "geminipro",
55
- "ollama"
55
+ "ollama",
56
+ "andi",
56
57
  ]
57
58
 
58
59
  gpt4free_providers = [
@@ -0,0 +1,175 @@
1
+ import json
2
+ from webscout import WEBS
3
+ import httpx
4
+ from bs4 import BeautifulSoup
5
+ from typing import List, Dict
6
+
7
+ class DeepInfra:
8
+ def __init__(
9
+ self,
10
+ model: str = "meta-llama/Meta-Llama-3.1-70B-Instruct",
11
+ max_tokens: int = 8000,
12
+ timeout: int = 120,
13
+ system_prompt: str = "You are a helpful AI assistant.",
14
+ proxies: dict = {}
15
+ ):
16
+ self.model = model
17
+ self.max_tokens = max_tokens
18
+ self.timeout = timeout
19
+ self.system_prompt = system_prompt
20
+ self.chat_endpoint = "https://api.deepinfra.com/v1/openai/chat/completions"
21
+
22
+ self.headers = {
23
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
24
+ 'Accept-Language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
25
+ 'Cache-Control': 'no-cache',
26
+ 'Connection': 'keep-alive',
27
+ 'Content-Type': 'application/json',
28
+ 'Origin': 'https://deepinfra.com',
29
+ 'Pragma': 'no-cache',
30
+ 'Referer': 'https://deepinfra.com/',
31
+ 'Sec-Fetch-Dest': 'empty',
32
+ 'Sec-Fetch-Mode': 'cors',
33
+ 'Sec-Fetch-Site': 'same-site',
34
+ 'X-Deepinfra-Source': 'web-embed',
35
+ 'accept': 'text/event-stream',
36
+ 'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
37
+ 'sec-ch-ua-mobile': '?0',
38
+ 'sec-ch-ua-platform': '"macOS"'
39
+ }
40
+
41
+ self.client = httpx.Client(proxies=proxies, headers=self.headers)
42
+
43
+ def ask(self, prompt: str, system_prompt: str = None) -> str:
44
+ payload = {
45
+ 'model': self.model,
46
+ 'messages': [
47
+ {"role": "system", "content": system_prompt or self.system_prompt},
48
+ {"role": "user", "content": prompt},
49
+ ],
50
+ 'temperature': 0.7,
51
+ 'max_tokens': self.max_tokens,
52
+ 'stop': []
53
+ }
54
+
55
+ response = self.client.post(self.chat_endpoint, json=payload, timeout=self.timeout)
56
+ if response.status_code != 200:
57
+ raise Exception(f"Failed to generate response - ({response.status_code}, {response.reason_phrase}) - {response.text}")
58
+
59
+ resp = response.json()
60
+ return resp["choices"][0]["message"]["content"]
61
+
62
+ class WebSearchAgent:
63
+
64
+ def __init__(self, model="Qwen/Qwen2-72B-Instruct"):
65
+ self.webs = WEBS()
66
+ self.deepinfra = DeepInfra(model=model)
67
+
68
+ def generate_search_query(self, information):
69
+ prompt = f"""
70
+ Instructions:
71
+ You are a smart online searcher for a large language model.
72
+ Given information, you must create a search query to search the internet for relevant information.
73
+ Your search query must be in the form of a json response.
74
+ Exact json response format must be as follows:
75
+
76
+ {{
77
+ "search_query": "your search query"
78
+ }}
79
+ - You must only provide ONE search query
80
+ - You must provide the BEST search query for the given information
81
+ - The search query must be normal text.
82
+
83
+ Information: {information}
84
+ """
85
+
86
+ response = self.deepinfra.ask(prompt)
87
+ return json.loads(response)["search_query"]
88
+
89
+ def search(self, information, region='wt-wt', safesearch='off', timelimit='y', max_results=5):
90
+ search_query = self.generate_search_query(information)
91
+
92
+ results = []
93
+ with self.webs as webs:
94
+ for result in webs.text(search_query, region=region, safesearch=safesearch, timelimit=timelimit, max_results=max_results):
95
+ results.append(result)
96
+
97
+ return results
98
+
99
+ def extract_urls(self, results):
100
+ urls = []
101
+ for result in results:
102
+ url = result.get('href')
103
+ if url:
104
+ urls.append(url)
105
+ return list(set(urls)) # Remove duplicates
106
+
107
+ def fetch_webpage(self, url: str) -> str:
108
+ try:
109
+ response = httpx.get(url, timeout=120)
110
+ if response.status_code == 200:
111
+ html = response.text
112
+ soup = BeautifulSoup(html, 'html.parser')
113
+
114
+ # Extract text from <p> tags
115
+ paragraphs = soup.find_all('p')
116
+ text = ' '.join([p.get_text() for p in paragraphs])
117
+
118
+ # Limit the text to around 4000 words
119
+ words = text.split()
120
+ if len(words) > 4000:
121
+ text = ' '.join(words[:4000]) + '...'
122
+
123
+ return text
124
+ else:
125
+ return f"Failed to fetch {url}: HTTP {response.status}"
126
+ except Exception as e:
127
+ return f"Error fetching {url}: {str(e)}"
128
+
129
+ def fetch_all_webpages(self, urls: List[str]) -> List[Dict[str, str]]:
130
+ contents = []
131
+ for url in urls:
132
+ content = self.fetch_webpage(url)
133
+ contents.append({"url": url, "content": content})
134
+ return contents
135
+
136
+ class OnlineSearcher:
137
+ def __init__(self, model="meta-llama/Meta-Llama-3.1-405B-Instruct"):
138
+ self.agent = WebSearchAgent(model)
139
+ self.deepinfra = DeepInfra(model="model")
140
+
141
+ def answer_question(self, question: str) -> str:
142
+ # Perform web search
143
+ search_results = self.agent.search(question)
144
+
145
+ # Extract URLs
146
+ urls = self.agent.extract_urls(search_results)
147
+
148
+ # Fetch webpage contents
149
+ webpage_contents = self.agent.fetch_all_webpages(urls)
150
+
151
+ # Prepare context for AI
152
+ context = "Based on the following search results and webpage contents:\n\n"
153
+ for i, result in enumerate(search_results, 1):
154
+ context += f"{i}. Title: {result['title']}\n URL: {result['href']}\n Snippet: {result['body']}\n\n"
155
+
156
+ context += "Extracted webpage contents:\n"
157
+ for i, webpage in enumerate(webpage_contents):
158
+ context += f"{i}. URL: {webpage['url']}\n Content: {webpage['content'][:4000]}...\n\n"
159
+
160
+ # Generate answer using AI
161
+ prompt = f"{context}\n\nQuestion: {question}\n\nPlease provide a comprehensive answer to the question based on the search results and webpage contents above. Include relevant webpage URLs in your answer when appropriate. If the search results and webpage contents don't contain relevant information, please state that and provide the best answer you can based on your general knowledge. [YOUR RESPONSE WITH SOURCE LINKS ([➊](URL))"
162
+
163
+ answer = self.deepinfra.ask(prompt)
164
+ return answer
165
+
166
+ # Usage example
167
+ if __name__ == "__main__":
168
+ assistant = OnlineSearcher()
169
+ while True:
170
+ question = input(">>> ")
171
+ if question.lower() == 'quit':
172
+ break
173
+ answer = assistant.answer_question(question)
174
+ print(answer)
175
+ print("\n" + "-"*50 + "\n")
@@ -0,0 +1,2 @@
1
+ from .Onlinesearcher import *
2
+ from .functioncall import *
@@ -0,0 +1,126 @@
1
+ import json
2
+ import logging
3
+ from webscout import DeepInfra, WEBS
4
+
5
+ class FunctionCallingAgent:
6
+ def __init__(self, model: str = "Qwen/Qwen2-72B-Instruct", system_prompt: str = 'You are a helpful assistant that will always answer what user wants', tools: list = None):
7
+ self.deepinfra = DeepInfra(model=model, system_prompt=system_prompt)
8
+ self.tools = tools if tools is not None else []
9
+ # logging.basicConfig(level=logging.INFO)
10
+ # self.webs = WEBS() # Initialize a WEBS object for web search
11
+
12
+ def function_call_handler(self, message_text: str):
13
+ """Handles function calls based on the provided message text
14
+
15
+ Args:
16
+ message_text (str): The input message text from the user.
17
+
18
+ Returns:
19
+ dict: The extracted function call and arguments.
20
+ """
21
+ system_message = f'[SYSTEM]You are a helpful assistant. You have access to the following functions: \n {str(self.tools)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_2": "value_2", ... }} }} </functioncall> [USER] {message_text}'
22
+
23
+ response = self.deepinfra.chat(system_message)
24
+ # logging.info(f"Raw response: {response}")
25
+
26
+ try:
27
+ # Extract the JSON-like part of the response
28
+ start_idx = response.find("{")
29
+ end_idx = response.rfind("}") + 1
30
+ if start_idx == -1 or end_idx == -1:
31
+ raise ValueError("JSON-like structure not found in the response")
32
+
33
+ response_json_str = response[start_idx:end_idx]
34
+ # Ensure the JSON string is properly formatted
35
+ response_json_str = response_json_str.replace("'", '"') # Replace single quotes with double quotes
36
+ response_json_str = response_json_str.strip()
37
+ response_data = json.loads(response_json_str)
38
+ except (ValueError, json.JSONDecodeError) as e:
39
+ # logging.error(f"An error occurred while parsing response: {e}")
40
+ return {"error": str(e)}
41
+
42
+ return response_data
43
+
44
+ def execute_function(self, function_call_data: dict) -> str:
45
+ """Executes the specified function with the provided arguments.
46
+
47
+ Args:
48
+ function_call_data (dict): A dictionary containing the function name and arguments.
49
+
50
+ Returns:
51
+ str: The result of the function execution.
52
+ """
53
+ function_name = function_call_data.get("name")
54
+ arguments = function_call_data.get("arguments", "{}") # Default to empty dict if not present
55
+
56
+ # Parse the arguments string into a dictionary
57
+ try:
58
+ arguments_dict = json.loads(arguments)
59
+ except json.JSONDecodeError:
60
+ # logging.error("Failed to parse arguments as JSON.")
61
+ return "Invalid arguments format."
62
+
63
+ # logging.info(f"Executing function: {function_name} with arguments: {arguments_dict}")
64
+
65
+ # if function_name == "web_search":
66
+ # query = arguments_dict.get("query")
67
+ # if query:
68
+ # search_results = self.webs.text(query)
69
+ # # You can process the search results here, e.g., extract URLs, summarize, etc.
70
+ # return f"Here's what I found:\n\n{search_results}"
71
+ # else:
72
+ # return "Please provide a search query."
73
+ # else:
74
+ # return f"Function '{function_name}' is not yet implemented."
75
+
76
+ # Example usage
77
+ if __name__ == "__main__":
78
+ tools = [
79
+ {
80
+ "type": "function",
81
+ "function": {
82
+ "name": "UserDetail",
83
+ "parameters": {
84
+ "type": "object",
85
+ "title": "UserDetail",
86
+ "properties": {
87
+ "name": {
88
+ "title": "Name",
89
+ "type": "string"
90
+ },
91
+ "age": {
92
+ "title": "Age",
93
+ "type": "integer"
94
+ }
95
+ },
96
+ "required": ["name", "age"]
97
+ }
98
+ }
99
+ },
100
+ {
101
+ "type": "function",
102
+ "function": {
103
+ "name": "web_search",
104
+ "description": "Search query on google",
105
+ "parameters": {
106
+ "type": "object",
107
+ "properties": {
108
+ "query": {
109
+ "type": "string",
110
+ "description": "web search query"
111
+ }
112
+ },
113
+ "required": ["query"]
114
+ }
115
+ }
116
+ }
117
+ ]
118
+
119
+ agent = FunctionCallingAgent(tools=tools)
120
+ message = "tell me about HelpingAI flash"
121
+ function_call_data = agent.function_call_handler(message)
122
+ print(f"Function Call Data: {function_call_data}")
123
+
124
+ if "error" not in function_call_data:
125
+ result = agent.execute_function(function_call_data)
126
+ # print(f"Function Execution Result: {result}")
@@ -1,6 +1,14 @@
1
1
  import subprocess
2
2
  import argparse
3
3
  import os
4
+ from rich.console import Console
5
+ from rich.panel import Panel
6
+ from rich.progress import track
7
+ from yaspin import yaspin
8
+ from pyfiglet import figlet_format
9
+ import time
10
+
11
+ console = Console()
4
12
 
5
13
  def autollama(model_path, gguf_file):
6
14
  """Manages models with Ollama using the autollama.sh script.
@@ -9,6 +17,7 @@ def autollama(model_path, gguf_file):
9
17
  model_path (str): The path to the Hugging Face model.
10
18
  gguf_file (str): The name of the GGUF file.
11
19
  """
20
+ console.print(f"[bold green]{figlet_format('Autollama')}[/]\n", justify="center")
12
21
 
13
22
  # Check if autollama.sh exists in the current working directory
14
23
  script_path = os.path.join(os.getcwd(), "autollama.sh")
@@ -172,25 +181,27 @@ echo "Use Ollama run $MODEL_NAME"
172
181
  # Execute the command
173
182
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
174
183
 
175
- # Print the output and error in real-time
176
- for line in process.stdout:
177
- print(line, end='')
178
-
179
- for line in process.stderr:
180
- print(line, end='')
184
+ for line in iter(process.stdout.readline, ''):
185
+ console.print(Panel(line.strip(), title="Autollama Output", expand=False))
181
186
 
187
+ for line in iter(process.stderr.readline, ''):
188
+ console.print(Panel(line.strip(), title="Autollama Errors (if any)", expand=False))
189
+
182
190
  process.wait()
191
+ console.print("[green]Model is ready![/]")
183
192
 
184
193
  def main():
185
194
  parser = argparse.ArgumentParser(description='Automatically create and run an Ollama model in Ollama')
186
- parser.add_argument('-m', '--model_path', required=True, help='Set the hunggingface model id to the Hugging Face model')
195
+ parser.add_argument('-m', '--model_path', required=True, help='Set the huggingface model id to the Hugging Face model')
187
196
  parser.add_argument('-g', '--gguf_file', required=True, help='Set the GGUF file name')
188
197
  args = parser.parse_args()
189
198
 
190
199
  try:
191
- autollama(args.model_path, args.gguf_file)
200
+ with yaspin(text="Processing...") as spinner:
201
+ autollama(args.model_path, args.gguf_file)
202
+ spinner.ok("Done!")
192
203
  except Exception as e:
193
- print(f"Error: {e}")
204
+ console.print(f"[red]Error: {e}[/]")
194
205
  exit(1)
195
206
 
196
207
  if __name__ == "__main__":
@@ -1,7 +1,10 @@
1
1
  # webscout/Extra/gguf.py
2
2
  import subprocess
3
- import argparse
4
3
  import os
4
+ from pyfiglet import figlet_format
5
+ from rich.console import Console
6
+
7
+ console = Console()
5
8
 
6
9
  def convert(model_id, username=None, token=None, quantization_methods="q4_k_m,q5_k_m"):
7
10
  """Converts and quantizes a Hugging Face model to GGUF format.
@@ -17,6 +20,7 @@ def convert(model_id, username=None, token=None, quantization_methods="q4_k_m,q5
17
20
  ValueError: If an invalid quantization method is provided.
18
21
  """
19
22
 
23
+ console.print(f"[bold green]{figlet_format('GGUF Converter')}[/]\n", justify="center")
20
24
  # List of valid quantization methods
21
25
  valid_methods = [
22
26
  "q2_k", "q3_k_l", "q3_k_m", "q3_k_s",
@@ -220,21 +224,3 @@ echo "Script completed."
220
224
  process.wait()
221
225
 
222
226
 
223
- def main():
224
- parser = argparse.ArgumentParser(description='Convert and quantize model using gguf.sh')
225
- parser.add_argument('-m', '--model_id', required=True, help='Set the HF model ID (e.g., "google/flan-t5-xl")')
226
- parser.add_argument('-u', '--username', help='Set your Hugging Face username (required for uploads)')
227
- parser.add_argument('-t', '--token', help='Set your Hugging Face API token (required for uploads)')
228
- parser.add_argument('-q', '--quantization_methods', default="q4_k_m,q5_k_m",
229
- help='Comma-separated quantization methods (default: q4_k_m,q5_k_m). Valid methods: q2_k, q3_k_l, q3_k_m, q3_k_s, q4_0, q4_1, q4_k_m, q4_k_s, q5_0, q5_1, q5_k_m, q5_k_s, q6_k, q8_0')
230
-
231
- args = parser.parse_args()
232
-
233
- try:
234
- convert(args.model_id, args.username, args.token, args.quantization_methods)
235
- except ValueError as e:
236
- print(e)
237
- exit(1)
238
-
239
- if __name__ == "__main__":
240
- main()