webscout 6.2b0__py3-none-any.whl → 6.4__py3-none-any.whl

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 (97) hide show
  1. webscout/AIauto.py +191 -176
  2. webscout/AIbase.py +112 -239
  3. webscout/AIutel.py +488 -1130
  4. webscout/Agents/functioncall.py +248 -198
  5. webscout/Bing_search.py +250 -153
  6. webscout/DWEBS.py +454 -178
  7. webscout/Extra/__init__.py +2 -1
  8. webscout/Extra/autocoder/__init__.py +9 -0
  9. webscout/Extra/autocoder/autocoder_utiles.py +121 -0
  10. webscout/Extra/autocoder/rawdog.py +681 -0
  11. webscout/Extra/autollama.py +246 -195
  12. webscout/Extra/gguf.py +441 -226
  13. webscout/Extra/weather.py +172 -67
  14. webscout/LLM.py +442 -100
  15. webscout/Litlogger/__init__.py +681 -0
  16. webscout/Local/formats.py +4 -2
  17. webscout/Provider/Amigo.py +19 -10
  18. webscout/Provider/Andi.py +0 -33
  19. webscout/Provider/Blackboxai.py +4 -204
  20. webscout/Provider/DARKAI.py +1 -1
  21. webscout/Provider/EDITEE.py +1 -1
  22. webscout/Provider/Llama3.py +1 -1
  23. webscout/Provider/Marcus.py +137 -0
  24. webscout/Provider/NinjaChat.py +1 -1
  25. webscout/Provider/PI.py +221 -207
  26. webscout/Provider/Perplexity.py +598 -598
  27. webscout/Provider/RoboCoders.py +206 -0
  28. webscout/Provider/TTI/AiForce/__init__.py +22 -0
  29. webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
  30. webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
  31. webscout/Provider/TTI/Nexra/__init__.py +22 -0
  32. webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
  33. webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
  34. webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
  35. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
  36. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
  37. webscout/Provider/TTI/__init__.py +3 -4
  38. webscout/Provider/TTI/artbit/__init__.py +22 -0
  39. webscout/Provider/TTI/artbit/async_artbit.py +184 -0
  40. webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
  41. webscout/Provider/TTI/blackbox/__init__.py +4 -0
  42. webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
  43. webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
  44. webscout/Provider/TTI/deepinfra/__init__.py +4 -0
  45. webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
  46. webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
  47. webscout/Provider/TTI/huggingface/__init__.py +22 -0
  48. webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
  49. webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
  50. webscout/Provider/TTI/imgninza/__init__.py +4 -0
  51. webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
  52. webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
  53. webscout/Provider/TTI/talkai/__init__.py +4 -0
  54. webscout/Provider/TTI/talkai/async_talkai.py +229 -0
  55. webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
  56. webscout/Provider/__init__.py +146 -132
  57. webscout/Provider/askmyai.py +158 -0
  58. webscout/Provider/cerebras.py +227 -206
  59. webscout/Provider/geminiapi.py +208 -198
  60. webscout/Provider/llama3mitril.py +180 -0
  61. webscout/Provider/llmchat.py +203 -0
  62. webscout/Provider/mhystical.py +176 -0
  63. webscout/Provider/perplexitylabs.py +265 -0
  64. webscout/Provider/talkai.py +196 -0
  65. webscout/Provider/twitterclone.py +251 -244
  66. webscout/Provider/typegpt.py +359 -0
  67. webscout/__init__.py +28 -23
  68. webscout/__main__.py +5 -5
  69. webscout/cli.py +327 -347
  70. webscout/conversation.py +227 -0
  71. webscout/exceptions.py +161 -29
  72. webscout/litagent/__init__.py +172 -0
  73. webscout/litprinter/__init__.py +831 -0
  74. webscout/optimizers.py +270 -0
  75. webscout/prompt_manager.py +279 -0
  76. webscout/swiftcli/__init__.py +810 -0
  77. webscout/transcriber.py +479 -551
  78. webscout/update_checker.py +125 -0
  79. webscout/version.py +1 -1
  80. webscout-6.4.dist-info/LICENSE.md +211 -0
  81. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/METADATA +34 -55
  82. webscout-6.4.dist-info/RECORD +154 -0
  83. webscout/Provider/TTI/AIuncensored.py +0 -103
  84. webscout/Provider/TTI/Nexra.py +0 -120
  85. webscout/Provider/TTI/PollinationsAI.py +0 -138
  86. webscout/Provider/TTI/WebSimAI.py +0 -142
  87. webscout/Provider/TTI/aiforce.py +0 -160
  88. webscout/Provider/TTI/artbit.py +0 -141
  89. webscout/Provider/TTI/deepinfra.py +0 -148
  90. webscout/Provider/TTI/huggingface.py +0 -155
  91. webscout/models.py +0 -23
  92. webscout-6.2b0.dist-info/LICENSE.md +0 -50
  93. webscout-6.2b0.dist-info/RECORD +0 -118
  94. /webscout/{g4f.py → gpt4free.py} +0 -0
  95. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
  96. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
  97. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
@@ -1,198 +1,248 @@
1
- from datetime import date
2
- import json
3
- # import logging
4
- import time
5
- from typing import Any, Dict, Optional
6
- import requests
7
- from webscout import WEBS, GEMINIAPI
8
-
9
- class FunctionCallingAgent:
10
- def __init__(self,
11
- tools: list = None):
12
- self.ai = GEMINIAPI(api_key="Gemini api key", timeout=300, intro=None)
13
- self.tools = tools if tools is not None else []
14
- self.knowledge_cutoff = "September 2022"
15
-
16
- def function_call_handler(self, message_text: str) -> dict:
17
- system_message = self._generate_system_message(message_text)
18
- response = self.ai.chat(system_message)
19
- # logging.info(f"Raw response: {response}")
20
- return self._parse_function_call(response)
21
-
22
- def _generate_system_message(self, user_message: str) -> str:
23
- tools_description = ""
24
- for tool in self.tools:
25
- tools_description += f"- {tool['function']['name']}: {tool['function'].get('description', '')}\n"
26
- tools_description += " Parameters:\n"
27
- for key, value in tool['function']['parameters']['properties'].items():
28
- tools_description += f" - {key}: {value.get('description', '')} ({value.get('type')})\n"
29
-
30
- current_date = date.today().strftime("%B %d, %Y")
31
- return f"""Today is {current_date}. Your knowledge is current up to {self.knowledge_cutoff}.
32
-
33
- You are an advanced AI assistant tasked with analyzing user requests and determining the most appropriate action. You have access to the following tools:
34
-
35
- {tools_description}
36
-
37
- Instructions:
38
- 1. Carefully analyze the user's request.
39
- 2. If the user request is about controlling the web browser (opening websites, searching, playing videos, etc.), ALWAYS use the 'browser_control' tool.
40
- 3. If the user request is something else, determine if any of the other provided tools are necessary to fulfill the request.
41
- 4. If a tool is needed, select the MOST APPROPRIATE one. Do not use a tool if it's not directly relevant to the user's request.
42
- 5. If you decide to use a tool, respond ONLY with a JSON object in this format:
43
- {{
44
- "tool_name": "name_of_the_tool",
45
- "tool_input": {{
46
- "param1": "value1",
47
- "param2": "value2"
48
- }}
49
- }}
50
-
51
- - Use the exact tool name as listed above.
52
- - Include only the necessary parameters for the chosen tool.
53
- - Do not include any explanations or additional text outside the JSON object.
54
-
55
- 6. If no tool is needed and you can answer directly, respond with:
56
- {{
57
- "tool_name": "general_ai",
58
- "tool_input": {{
59
- "question": "user's original question"
60
- }}
61
- }}
62
-
63
- User Request: {user_message}
64
-
65
- Your Response (JSON only):"""
66
-
67
- def _parse_function_call(self, response: str) -> dict:
68
- try:
69
- # Ensure to locate the start and end of the JSON structure
70
- start_idx = response.find("{")
71
- end_idx = response.rfind("}") + 1
72
-
73
- if start_idx == -1 or end_idx == -1:
74
- raise ValueError("No valid JSON structure found in the response.")
75
-
76
- # Extract the JSON string
77
- response_json_str = response[start_idx:end_idx]
78
-
79
- # Load the JSON string
80
- parsed_response = json.loads(response_json_str)
81
-
82
- # Check for the expected format
83
- if "tool_name" in parsed_response and "tool_input" in parsed_response:
84
- return parsed_response
85
-
86
- # If not in the expected format, try to convert
87
- for key, value in parsed_response.items():
88
- if isinstance(value, dict):
89
- return {
90
- "tool_name": key,
91
- "tool_input": value
92
- }
93
-
94
- # If the response structure is still incorrect
95
- raise ValueError("Invalid response structure: missing required fields.")
96
-
97
- except (ValueError, json.JSONDecodeError) as e:
98
- # logging.error(f"Error parsing function call: {e}")
99
- return {"error": str(e)}
100
-
101
-
102
- def execute_function(self, function_call_data: dict) -> str:
103
- function_name = function_call_data.get("tool_name")
104
- arguments = function_call_data.get("tool_input", {})
105
-
106
- if not isinstance(arguments, dict):
107
- # logging.error("Invalid arguments format.")
108
- return "Invalid arguments format."
109
-
110
- # logging.info(f"Executing function: {function_name} with arguments: {arguments}")
111
-
112
-
113
- # Example usage
114
- if __name__ == "__main__":
115
- # Configure logging
116
- # logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
117
-
118
- tools = [
119
- {
120
- "type": "function",
121
- "function": {
122
- "name": "web_search",
123
- "description": "Search the web for current information on a given query",
124
- "parameters": {
125
- "type": "object",
126
- "properties": {
127
- "query": {
128
- "type": "string",
129
- "description": "The search query to be executed"
130
- }
131
- },
132
- "required": ["query"]
133
- }
134
- }
135
- },
136
- {
137
- "type": "function",
138
- "function": {
139
- "name": "get_user_detail",
140
- "description": "Get the user's name and age.",
141
- "parameters": {
142
- "type": "object",
143
- "properties": {
144
- "name": {
145
- "type": "string",
146
- "description": "The user's name."
147
- },
148
- "age": {
149
- "type": "integer",
150
- "description": "The user's age."
151
- }
152
- },
153
- "required": ["name", "age"]
154
- }
155
- }
156
- },
157
- {
158
- "type": "function",
159
- "function": {
160
- "name": "general_ai",
161
- "description": "Use AI to answer general questions or perform tasks not requiring external tools",
162
- "parameters": {
163
- "type": "object",
164
- "properties": {
165
- "question": {
166
- "type": "string",
167
- "description": "The question or task for the AI to process"
168
- }
169
- },
170
- "required": ["question"]
171
- }
172
- }
173
- }
174
- ]
175
-
176
- agent = FunctionCallingAgent(tools=tools)
177
-
178
- # Test cases
179
- test_messages = [
180
- "What's the weather like in New York today?",
181
- "Who won the last FIFA World Cup?",
182
- "Can you explain quantum computing?",
183
- "What are the latest developments in AI?",
184
- "Tell me a joke about programming.",
185
- "What's the meaning of life?",
186
- "Get user details name as John and age as 30"
187
- ]
188
-
189
- for message in test_messages:
190
- print(f"\nProcessing: {message}")
191
- function_call_data = agent.function_call_handler(message)
192
- print(f"Function Call Data: {function_call_data}")
193
-
194
- if "error" not in function_call_data:
195
- result = agent.execute_function(function_call_data)
196
- print(f"Function Execution Result: {result}")
197
- else:
198
- print(f"Error: {function_call_data['error']}")
1
+ from datetime import date
2
+ import json
3
+ import logging
4
+ import time
5
+ from typing import Any, Dict, List, Optional, Union, Callable
6
+ from dataclasses import dataclass
7
+ import asyncio
8
+ import requests
9
+ from jinja2 import Template
10
+ from webscout import WEBS, ChatGPTES
11
+
12
+ @dataclass
13
+ class ToolParameter:
14
+ name: str
15
+ type: str
16
+ description: str
17
+ required: bool = False
18
+
19
+ @dataclass
20
+ class Tool:
21
+ name: str
22
+ description: str
23
+ parameters: Dict[str, ToolParameter]
24
+ function: Callable
25
+ is_async: bool = False
26
+
27
+ class ToolRegistry:
28
+ def __init__(self):
29
+ self._tools: Dict[str, Tool] = {}
30
+
31
+ def register(self, tool: Tool):
32
+ self._tools[tool.name] = tool
33
+
34
+ def get_tool(self, name: str) -> Optional[Tool]:
35
+ return self._tools.get(name)
36
+
37
+ def list_tools(self) -> List[Tool]:
38
+ return list(self._tools.values())
39
+
40
+ def to_schema(self) -> List[Dict]:
41
+ return [
42
+ {
43
+ "type": "function",
44
+ "function": {
45
+ "name": tool.name,
46
+ "description": tool.description,
47
+ "parameters": {
48
+ "type": "object",
49
+ "properties": {
50
+ param.name: {
51
+ "type": param.type,
52
+ "description": param.description
53
+ } for param in tool.parameters.values()
54
+ },
55
+ "required": [
56
+ param.name for param in tool.parameters.values()
57
+ if param.required
58
+ ]
59
+ }
60
+ }
61
+ }
62
+ for tool in self._tools.values()
63
+ ]
64
+
65
+ class FunctionCallingAgent:
66
+ SYSTEM_TEMPLATE = Template("""You are an advanced AI assistant tasked with analyzing user requests and determining the most appropriate action. You have access to the following tools:
67
+
68
+ {{ tools_description }}
69
+
70
+ Instructions:
71
+ 1. Carefully analyze the user's request.
72
+ 2. Determine which tools (if any) are necessary to fulfill the request.
73
+ 3. You can make multiple tool calls if needed to complete the task.
74
+ 4. If you decide to use tool(s), respond ONLY with a JSON array in this format:
75
+ [
76
+ {
77
+ "name": "tool_name",
78
+ "arguments": {
79
+ "param1": "value1",
80
+ "param2": "value2"
81
+ }
82
+ },
83
+ ... (more tool calls as needed)
84
+ ]
85
+
86
+ 5. If no tool is needed, respond with an empty array: []
87
+
88
+ The current date is {{ current_date }}. Your knowledge cutoff is {{ knowledge_cutoff }}.
89
+
90
+ User Request: {{ user_message }}
91
+
92
+ Your Response (JSON array only):""")
93
+
94
+ def __init__(self, registry: ToolRegistry = None):
95
+ self.ai = ChatGPTES(timeout=300, intro=None)
96
+ self.registry = registry or ToolRegistry()
97
+ self.knowledge_cutoff = "September 2022"
98
+ self.logger = logging.getLogger(__name__)
99
+
100
+ def _generate_system_message(self, user_message: str) -> str:
101
+ tools_description = ""
102
+ for tool in self.registry.list_tools():
103
+ tools_description += f"- {tool.name}: {tool.description}\n"
104
+ tools_description += " Parameters:\n"
105
+ for param in tool.parameters.values():
106
+ tools_description += f" - {param.name}: {param.description} ({param.type})\n"
107
+
108
+ current_date = date.today().strftime("%B %d, %Y")
109
+ return self.SYSTEM_TEMPLATE.render(
110
+ tools_description=tools_description,
111
+ current_date=current_date,
112
+ knowledge_cutoff=self.knowledge_cutoff,
113
+ user_message=user_message
114
+ )
115
+
116
+ async def _execute_tool(self, tool_call: Dict[str, Any]) -> Any:
117
+ tool_name = tool_call.get("name")
118
+ arguments = tool_call.get("arguments", {})
119
+
120
+ tool = self.registry.get_tool(tool_name)
121
+ if not tool:
122
+ raise ValueError(f"Unknown tool: {tool_name}")
123
+
124
+ try:
125
+ if tool.is_async:
126
+ return await tool.function(**arguments)
127
+ else:
128
+ return tool.function(**arguments)
129
+ except Exception as e:
130
+ self.logger.error(f"Error executing tool {tool_name}: {str(e)}")
131
+ raise
132
+
133
+ async def process_request(self, message: str) -> List[Any]:
134
+ """Process a user request and execute any necessary tool calls."""
135
+ try:
136
+ system_message = self._generate_system_message(message)
137
+ response = self.ai.chat(system_message)
138
+ self.logger.debug(f"Raw AI response: {response}")
139
+
140
+ tool_calls = self._parse_tool_calls(response)
141
+ if not tool_calls:
142
+ return []
143
+
144
+ results = []
145
+ for tool_call in tool_calls:
146
+ result = await self._execute_tool(tool_call)
147
+ results.append(result)
148
+ return results
149
+
150
+ except Exception as e:
151
+ self.logger.error(f"Error processing request: {str(e)}")
152
+ raise
153
+
154
+ def _parse_tool_calls(self, response: str) -> List[Dict[str, Any]]:
155
+ """Parse the AI response into a list of tool calls."""
156
+ try:
157
+ # Find the JSON array in the response
158
+ start_idx = response.find("[")
159
+ end_idx = response.rfind("]") + 1
160
+
161
+ if start_idx == -1 or end_idx == -1:
162
+ return []
163
+
164
+ # Extract and parse the JSON array
165
+ response_json = json.loads(response[start_idx:end_idx])
166
+
167
+ if not isinstance(response_json, list):
168
+ response_json = [response_json]
169
+
170
+ return response_json
171
+
172
+ except (json.JSONDecodeError, ValueError) as e:
173
+ self.logger.error(f"Error parsing tool calls: {str(e)}")
174
+ return []
175
+
176
+ # Example usage
177
+ if __name__ == "__main__":
178
+ logging.basicConfig(
179
+ level=logging.INFO,
180
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
181
+ )
182
+
183
+ # Create and configure the tool registry
184
+ registry = ToolRegistry()
185
+
186
+ def web_search(query: str) -> str:
187
+ # Implement actual web search logic
188
+ return f"Search results for: {query}"
189
+
190
+ def get_user_detail(name: str, age: int) -> Dict[str, Any]:
191
+ return {"name": name, "age": age}
192
+
193
+ # Register tools
194
+ registry.register(Tool(
195
+ name="web_search",
196
+ description="Search the web for current information",
197
+ parameters={
198
+ "query": ToolParameter(
199
+ name="query",
200
+ type="string",
201
+ description="The search query to execute",
202
+ required=True
203
+ )
204
+ },
205
+ function=web_search
206
+ ))
207
+
208
+ registry.register(Tool(
209
+ name="get_user_detail",
210
+ description="Get user details",
211
+ parameters={
212
+ "name": ToolParameter(
213
+ name="name",
214
+ type="string",
215
+ description="User's name",
216
+ required=True
217
+ ),
218
+ "age": ToolParameter(
219
+ name="age",
220
+ type="integer",
221
+ description="User's age",
222
+ required=True
223
+ )
224
+ },
225
+ function=get_user_detail
226
+ ))
227
+
228
+ # Create agent
229
+ agent = FunctionCallingAgent(registry=registry)
230
+
231
+ # Test cases
232
+ test_messages = [
233
+ "What's the weather like in New York today?",
234
+ "Get user details name as John and age as 30",
235
+ "Search for latest news about AI",
236
+ ]
237
+
238
+ async def run_tests():
239
+ for message in test_messages:
240
+ print(f"\nProcessing: {message}")
241
+ try:
242
+ results = await agent.process_request(message)
243
+ print(f"Results: {results}")
244
+ except Exception as e:
245
+ print(f"Error: {str(e)}")
246
+
247
+ # Run test cases
248
+ asyncio.run(run_tests())