webscout 6.2__py3-none-any.whl → 6.3__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.
- webscout/AIbase.py +309 -239
- webscout/Agents/functioncall.py +248 -198
- webscout/DWEBS.py +322 -178
- webscout/Extra/gguf.py +250 -60
- webscout/Extra/weather.py +172 -67
- webscout/LLM.py +279 -100
- webscout/Provider/Amigo.py +19 -10
- webscout/Provider/Andi.py +0 -33
- webscout/Provider/Blackboxai.py +4 -204
- webscout/Provider/Marcus.py +137 -0
- webscout/Provider/TTI/__init__.py +1 -1
- webscout/Provider/__init__.py +7 -3
- webscout/Provider/askmyai.py +158 -0
- webscout/Provider/cerebras.py +1 -1
- webscout/Provider/geminiapi.py +208 -198
- webscout/Provider/llama3mitril.py +181 -0
- webscout/Provider/twitterclone.py +7 -6
- webscout/cli.py +354 -346
- webscout/version.py +1 -1
- webscout-6.3.dist-info/LICENSE.md +211 -0
- {webscout-6.2.dist-info → webscout-6.3.dist-info}/METADATA +2 -3
- {webscout-6.2.dist-info → webscout-6.3.dist-info}/RECORD +26 -23
- webscout-6.2.dist-info/LICENSE.md +0 -50
- /webscout/Provider/TTI/{AIuncensored.py → AIuncensoredimage.py} +0 -0
- {webscout-6.2.dist-info → webscout-6.3.dist-info}/WHEEL +0 -0
- {webscout-6.2.dist-info → webscout-6.3.dist-info}/entry_points.txt +0 -0
- {webscout-6.2.dist-info → webscout-6.3.dist-info}/top_level.txt +0 -0
webscout/Agents/functioncall.py
CHANGED
|
@@ -1,198 +1,248 @@
|
|
|
1
|
-
from datetime import date
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
import time
|
|
5
|
-
from typing import Any, Dict, Optional
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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())
|