webscout 4.4__tar.gz → 4.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.

Files changed (86) hide show
  1. {webscout-4.4/webscout.egg-info → webscout-4.6}/PKG-INFO +21 -37
  2. {webscout-4.4 → webscout-4.6}/README.md +19 -36
  3. {webscout-4.4 → webscout-4.6}/setup.py +2 -1
  4. {webscout-4.4 → webscout-4.6}/webscout/AIutel.py +12 -1
  5. webscout-4.6/webscout/Agents/Onlinesearcher.py +175 -0
  6. webscout-4.6/webscout/Agents/__init__.py +2 -0
  7. webscout-4.6/webscout/Agents/functioncall.py +126 -0
  8. {webscout-4.4 → webscout-4.6}/webscout/Extra/gguf.py +1 -1
  9. webscout-4.6/webscout/Provider/Andi.py +275 -0
  10. {webscout-4.4 → webscout-4.6}/webscout/Provider/BasedGPT.py +38 -36
  11. {webscout-4.4 → webscout-4.6}/webscout/Provider/Blackboxai.py +14 -10
  12. webscout-4.6/webscout/Provider/DARKAI.py +207 -0
  13. webscout-4.6/webscout/Provider/Deepseek.py +212 -0
  14. webscout-4.6/webscout/Provider/Llama3.py +173 -0
  15. webscout-4.6/webscout/Provider/PizzaGPT.py +178 -0
  16. webscout-4.6/webscout/Provider/RUBIKSAI.py +201 -0
  17. {webscout-4.4 → webscout-4.6}/webscout/Provider/__init__.py +13 -3
  18. webscout-4.6/webscout/Provider/koala.py +239 -0
  19. {webscout-4.4 → webscout-4.6}/webscout/__init__.py +5 -3
  20. {webscout-4.4 → webscout-4.6}/webscout/version.py +1 -1
  21. {webscout-4.4 → webscout-4.6}/webscout/voice.py +8 -1
  22. {webscout-4.4 → webscout-4.6}/webscout/webai.py +28 -1
  23. {webscout-4.4 → webscout-4.6}/webscout/webscout_search.py +1 -0
  24. webscout-4.6/webscout/websx_search.py +19 -0
  25. {webscout-4.4 → webscout-4.6/webscout.egg-info}/PKG-INFO +21 -37
  26. {webscout-4.4 → webscout-4.6}/webscout.egg-info/SOURCES.txt +10 -1
  27. {webscout-4.4 → webscout-4.6}/webscout.egg-info/requires.txt +1 -0
  28. webscout-4.4/webscout/Provider/Deepseek.py +0 -266
  29. webscout-4.4/webscout/websx_search.py +0 -370
  30. {webscout-4.4 → webscout-4.6}/LICENSE.md +0 -0
  31. {webscout-4.4 → webscout-4.6}/setup.cfg +0 -0
  32. {webscout-4.4 → webscout-4.6}/webscout/AIauto.py +0 -0
  33. {webscout-4.4 → webscout-4.6}/webscout/AIbase.py +0 -0
  34. {webscout-4.4 → webscout-4.6}/webscout/DWEBS.py +0 -0
  35. {webscout-4.4 → webscout-4.6}/webscout/Extra/__init__.py +0 -0
  36. {webscout-4.4 → webscout-4.6}/webscout/Extra/autollama.py +0 -0
  37. {webscout-4.4 → webscout-4.6}/webscout/Extra/weather.py +0 -0
  38. {webscout-4.4 → webscout-4.6}/webscout/Extra/weather_ascii.py +0 -0
  39. {webscout-4.4 → webscout-4.6}/webscout/GoogleS.py +0 -0
  40. {webscout-4.4 → webscout-4.6}/webscout/LLM.py +0 -0
  41. {webscout-4.4 → webscout-4.6}/webscout/Local/__init__.py +0 -0
  42. {webscout-4.4 → webscout-4.6}/webscout/Local/_version.py +0 -0
  43. {webscout-4.4 → webscout-4.6}/webscout/Local/formats.py +0 -0
  44. {webscout-4.4 → webscout-4.6}/webscout/Local/model.py +0 -0
  45. {webscout-4.4 → webscout-4.6}/webscout/Local/rawdog.py +0 -0
  46. {webscout-4.4 → webscout-4.6}/webscout/Local/samplers.py +0 -0
  47. {webscout-4.4 → webscout-4.6}/webscout/Local/thread.py +0 -0
  48. {webscout-4.4 → webscout-4.6}/webscout/Local/utils.py +0 -0
  49. {webscout-4.4 → webscout-4.6}/webscout/Provider/Berlin4h.py +0 -0
  50. {webscout-4.4 → webscout-4.6}/webscout/Provider/ChatGPTUK.py +0 -0
  51. {webscout-4.4 → webscout-4.6}/webscout/Provider/Cohere.py +0 -0
  52. {webscout-4.4 → webscout-4.6}/webscout/Provider/Deepinfra.py +0 -0
  53. {webscout-4.4 → webscout-4.6}/webscout/Provider/FreeGemini.py +0 -0
  54. {webscout-4.4 → webscout-4.6}/webscout/Provider/Gemini.py +0 -0
  55. {webscout-4.4 → webscout-4.6}/webscout/Provider/Geminiflash.py +0 -0
  56. {webscout-4.4 → webscout-4.6}/webscout/Provider/Geminipro.py +0 -0
  57. {webscout-4.4 → webscout-4.6}/webscout/Provider/Groq.py +0 -0
  58. {webscout-4.4 → webscout-4.6}/webscout/Provider/Koboldai.py +0 -0
  59. {webscout-4.4 → webscout-4.6}/webscout/Provider/Leo.py +0 -0
  60. {webscout-4.4 → webscout-4.6}/webscout/Provider/Llama.py +0 -0
  61. {webscout-4.4 → webscout-4.6}/webscout/Provider/OLLAMA.py +0 -0
  62. {webscout-4.4 → webscout-4.6}/webscout/Provider/OpenGPT.py +0 -0
  63. {webscout-4.4 → webscout-4.6}/webscout/Provider/Openai.py +0 -0
  64. {webscout-4.4 → webscout-4.6}/webscout/Provider/Perplexity.py +0 -0
  65. {webscout-4.4 → webscout-4.6}/webscout/Provider/Phind.py +0 -0
  66. {webscout-4.4 → webscout-4.6}/webscout/Provider/Poe.py +0 -0
  67. {webscout-4.4 → webscout-4.6}/webscout/Provider/Reka.py +0 -0
  68. {webscout-4.4 → webscout-4.6}/webscout/Provider/ThinkAnyAI.py +0 -0
  69. {webscout-4.4 → webscout-4.6}/webscout/Provider/VTLchat.py +0 -0
  70. {webscout-4.4 → webscout-4.6}/webscout/Provider/Xjai.py +0 -0
  71. {webscout-4.4 → webscout-4.6}/webscout/Provider/Yepchat.py +0 -0
  72. {webscout-4.4 → webscout-4.6}/webscout/Provider/Youchat.py +0 -0
  73. {webscout-4.4 → webscout-4.6}/webscout/YTdownloader.py +0 -0
  74. {webscout-4.4 → webscout-4.6}/webscout/__main__.py +0 -0
  75. {webscout-4.4 → webscout-4.6}/webscout/async_providers.py +0 -0
  76. {webscout-4.4 → webscout-4.6}/webscout/cli.py +0 -0
  77. {webscout-4.4 → webscout-4.6}/webscout/exceptions.py +0 -0
  78. {webscout-4.4 → webscout-4.6}/webscout/g4f.py +0 -0
  79. {webscout-4.4 → webscout-4.6}/webscout/models.py +0 -0
  80. {webscout-4.4 → webscout-4.6}/webscout/tempid.py +0 -0
  81. {webscout-4.4 → webscout-4.6}/webscout/transcriber.py +0 -0
  82. {webscout-4.4 → webscout-4.6}/webscout/utils.py +0 -0
  83. {webscout-4.4 → webscout-4.6}/webscout/webscout_search_async.py +0 -0
  84. {webscout-4.4 → webscout-4.6}/webscout.egg-info/dependency_links.txt +0 -0
  85. {webscout-4.4 → webscout-4.6}/webscout.egg-info/entry_points.txt +0 -0
  86. {webscout-4.4 → webscout-4.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: 4.4
3
+ Version: 4.6
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
@@ -61,6 +61,7 @@ Requires-Dist: PyExecJS
61
61
  Requires-Dist: ollama
62
62
  Requires-Dist: pyfiglet
63
63
  Requires-Dist: yaspin
64
+ Requires-Dist: pillow
64
65
  Provides-Extra: dev
65
66
  Requires-Dist: ruff>=0.1.6; extra == "dev"
66
67
  Requires-Dist: pytest>=7.4.2; extra == "dev"
@@ -742,30 +743,11 @@ with WEBS() as WEBS:
742
743
  ## usage of WEBSX -- Another Websearch thing
743
744
  ```python
744
745
  from webscout import WEBSX
746
+ s = "Python development tools"
745
747
 
746
- def main():
747
- # Initialize the WEBSX client
748
- search = WEBSX(
749
- k=10,
750
- )
751
-
752
- # Example using `run` method - Get a summary
753
- query = "What is the capital of France?"
754
- answer = search.run(query)
755
- print(f"Answer: {answer}\n")
756
-
757
- # Example using `results` method - Get detailed results with metadata
758
- query = "What is the capital of France?"
759
- results = search.results(query, num_results=3)
760
- print("Search Results:")
761
- for result in results:
762
- print(f"Title: {result['title']}")
763
- print(f"Snippet: {result['snippet']}")
764
- print(f"Link: {result['link']}\n")
765
- print(f'Engines: {result["engines"]}')
748
+ result = WEBSX(s)
766
749
 
767
- if __name__ == "__main__":
768
- main()
750
+ print(result)
769
751
  ```
770
752
  ## ALL acts
771
753
  <details>
@@ -1028,7 +1010,7 @@ ___
1028
1010
  ### 0. `Duckchat` - chat with LLM
1029
1011
  ```python
1030
1012
  from webscout import WEBS as w
1031
- R = w().chat("hello", model='claude-3-haiku') # GPT-3.5 Turbo, mixtral-8x7b, llama-3-70b, claude-3-haiku
1013
+ 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
1032
1014
  print(R)
1033
1015
  ```
1034
1016
  ### 1. `PhindSearch` - Search using Phind.com
@@ -1387,7 +1369,7 @@ from rich import print
1387
1369
 
1388
1370
  ai = DeepSeek(
1389
1371
  is_conversation=True,
1390
- api_key='', # Watch this video https://youtu.be/Euin6p5Ryks?si=-84JBtyqGwMzvdIq to know from where u can get this key for free
1372
+ api_key='23bfff080d38429c9fbbf3c76f88454c',
1391
1373
  max_tokens=800,
1392
1374
  timeout=30,
1393
1375
  intro=None,
@@ -1399,18 +1381,12 @@ ai = DeepSeek(
1399
1381
  model="deepseek_chat"
1400
1382
  )
1401
1383
 
1402
- # Start an infinite loop for continuous interaction
1403
- while True:
1404
- # Define a prompt to send to the AI
1405
- prompt = input("Enter your prompt: ")
1406
-
1407
- # Check if the user wants to exit the loop
1408
- if prompt.lower() == "exit":
1409
- break
1410
-
1411
- # Use the 'chat' method to send the prompt and receive a response
1412
- r = ai.chat(prompt)
1413
- print(r)
1384
+
1385
+ # Define a prompt to send to the AI
1386
+ prompt = "Tell me about india"
1387
+ # Use the 'chat' method to send the prompt and receive a response
1388
+ r = ai.chat(prompt)
1389
+ print(r)
1414
1390
  ```
1415
1391
  ### 18. `Deepinfra`
1416
1392
  ```python
@@ -1505,7 +1481,15 @@ llama = LLAMA()
1505
1481
  r = llama.chat("What is the meaning of life?")
1506
1482
  print(r)
1507
1483
  ```
1484
+ ### 25. AndiSearch
1485
+ ```python
1486
+ from webscout import AndiSearch
1487
+ a = AndiSearch()
1488
+ print(a.chat("HelpingAI-9B"))
1489
+ ```
1508
1490
 
1491
+ ### 25. LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai
1492
+ code similar to other providers
1509
1493
  ### `LLM`
1510
1494
  ```python
1511
1495
  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
- )
679
-
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"]}')
675
+ result = WEBSX(s)
694
676
 
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
@@ -1315,7 +1296,7 @@ from rich import print
1315
1296
 
1316
1297
  ai = DeepSeek(
1317
1298
  is_conversation=True,
1318
- api_key='', # Watch this video https://youtu.be/Euin6p5Ryks?si=-84JBtyqGwMzvdIq to know from where u can get this key for free
1299
+ api_key='23bfff080d38429c9fbbf3c76f88454c',
1319
1300
  max_tokens=800,
1320
1301
  timeout=30,
1321
1302
  intro=None,
@@ -1327,18 +1308,12 @@ ai = DeepSeek(
1327
1308
  model="deepseek_chat"
1328
1309
  )
1329
1310
 
1330
- # Start an infinite loop for continuous interaction
1331
- while True:
1332
- # Define a prompt to send to the AI
1333
- prompt = input("Enter your prompt: ")
1334
-
1335
- # Check if the user wants to exit the loop
1336
- if prompt.lower() == "exit":
1337
- break
1338
-
1339
- # Use the 'chat' method to send the prompt and receive a response
1340
- r = ai.chat(prompt)
1341
- print(r)
1311
+
1312
+ # Define a prompt to send to the AI
1313
+ prompt = "Tell me about india"
1314
+ # Use the 'chat' method to send the prompt and receive a response
1315
+ r = ai.chat(prompt)
1316
+ print(r)
1342
1317
  ```
1343
1318
  ### 18. `Deepinfra`
1344
1319
  ```python
@@ -1433,7 +1408,15 @@ llama = LLAMA()
1433
1408
  r = llama.chat("What is the meaning of life?")
1434
1409
  print(r)
1435
1410
  ```
1411
+ ### 25. AndiSearch
1412
+ ```python
1413
+ from webscout import AndiSearch
1414
+ a = AndiSearch()
1415
+ print(a.chat("HelpingAI-9B"))
1416
+ ```
1436
1417
 
1418
+ ### 25. LLAMA3, pizzagpt, RUBIKSAI, Koala, Darkai
1419
+ code similar to other providers
1437
1420
  ### `LLM`
1438
1421
  ```python
1439
1422
  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.4",
8
+ version="4.6",
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",
@@ -65,6 +65,7 @@ setup(
65
65
  "ollama",
66
66
  "pyfiglet",
67
67
  "yaspin",
68
+ "pillow",
68
69
  ],
69
70
  entry_points={
70
71
  "console_scripts": [
@@ -52,7 +52,9 @@ webai = [
52
52
  "vtlchat",
53
53
  "geminiflash",
54
54
  "geminipro",
55
- "ollama"
55
+ "ollama",
56
+ "andi",
57
+ "llama3"
56
58
  ]
57
59
 
58
60
  gpt4free_providers = [
@@ -532,6 +534,15 @@ LLM:
532
534
  ```python
533
535
  print("The essay is about...")
534
536
  ```
537
+
538
+ 3. User: Weather in qazigund
539
+
540
+ LLM:
541
+ ```python
542
+ from webscout import weather as w
543
+ weather = w.get("Qazigund")
544
+ w.print_weather(weather)
545
+ ```
535
546
  """
536
547
 
537
548
 
@@ -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}")
@@ -153,7 +153,7 @@ huggingface-cli download "$MODEL_ID" --local-dir "./${MODEL_NAME}" --local-dir-u
153
153
  # Convert to fp16
154
154
  FP16="${MODEL_NAME}/${MODEL_NAME,,}.fp16.bin"
155
155
  echo "Converting the model to fp16..."
156
- python3 llama.cpp/convert-hf-to-gguf.py "$MODEL_NAME" --outtype f16 --outfile "$FP16"
156
+ python3 llama.cpp/convert_hf_to_gguf.py "$MODEL_NAME" --outtype f16 --outfile "$FP16"
157
157
 
158
158
  # Quantize the model
159
159
  echo "Quantizing the model..."