webscout 3.0b0__py3-none-any.whl → 3.1__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/Local/__init__.py +1 -0
- webscout/Local/_version.py +1 -1
- webscout/Local/model.py +33 -35
- webscout/Local/rawdog.py +946 -0
- webscout/Local/thread.py +4 -7
- webscout/Provider/BasedGPT.py +225 -225
- webscout/Provider/Berlin4h.py +210 -210
- webscout/Provider/Blackboxai.py +439 -439
- webscout/Provider/ChatGPTUK.py +213 -213
- webscout/Provider/Cohere.py +222 -222
- webscout/Provider/Gemini.py +216 -216
- webscout/Provider/Groq.py +511 -511
- webscout/Provider/Koboldai.py +401 -401
- webscout/Provider/Leo.py +468 -468
- webscout/Provider/Llama2.py +436 -436
- webscout/Provider/OpenGPT.py +486 -486
- webscout/Provider/Openai.py +510 -510
- webscout/Provider/Perplexity.py +229 -229
- webscout/Provider/Phind.py +517 -517
- webscout/Provider/Poe.py +207 -207
- webscout/Provider/Reka.py +225 -225
- webscout/Provider/Xjai.py +230 -230
- webscout/Provider/Yepchat.py +477 -477
- webscout/Provider/Youchat.py +220 -220
- webscout/Provider/__init__.py +61 -61
- webscout/version.py +1 -1
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/METADATA +466 -29
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/RECORD +32 -31
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/LICENSE.md +0 -0
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/WHEEL +0 -0
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/entry_points.txt +0 -0
- {webscout-3.0b0.dist-info → webscout-3.1.dist-info}/top_level.txt +0 -0
webscout/Local/__init__.py
CHANGED
webscout/Local/_version.py
CHANGED
webscout/Local/model.py
CHANGED
|
@@ -27,6 +27,8 @@ class ModelUnloadedException(Exception):
|
|
|
27
27
|
"""Exception raised when trying to use a Model that has been unloaded"""
|
|
28
28
|
def __init__(self, message):
|
|
29
29
|
self.message = message
|
|
30
|
+
self.tool_code_start = "```tool_code\n" # Define tool code markers
|
|
31
|
+
self.tool_code_end = "\n```tool_code```"
|
|
30
32
|
super().__init__(self.message)
|
|
31
33
|
self.add_note('Are you trying to use a Model that has been unloaded?')
|
|
32
34
|
|
|
@@ -271,51 +273,41 @@ class Model:
|
|
|
271
273
|
print_verbose(f" gguf: rope_freq_base_train == {rope_freq_base_train}")
|
|
272
274
|
print_verbose(f"param: rope_freq_base == {rope_freq_base}")
|
|
273
275
|
def register_tool(self, name: str, function: Callable):
|
|
274
|
-
"""
|
|
275
|
-
Registers a tool for function calling.
|
|
276
|
-
|
|
277
|
-
Args:
|
|
278
|
-
name: The name of the tool.
|
|
279
|
-
function: The Python function to execute when the tool is called.
|
|
280
|
-
"""
|
|
276
|
+
"""Registers a tool for function calling."""
|
|
281
277
|
self.tools[name] = function
|
|
282
278
|
|
|
283
279
|
def _extract_tool_code(self, text: str) -> dict:
|
|
284
|
-
"""
|
|
285
|
-
Extracts tool code from the model's output using the chatml-function-calling format.
|
|
286
|
-
|
|
287
|
-
Args:
|
|
288
|
-
text: The model's generated text.
|
|
289
|
-
|
|
290
|
-
Returns:
|
|
291
|
-
A dictionary containing the tool name and arguments, or None if no tool call is found.
|
|
292
|
-
"""
|
|
280
|
+
"""Extracts tool code from the model's output."""
|
|
293
281
|
try:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
end = text.find("\n```tool_code```")
|
|
282
|
+
start = text.find(self.tool_code_start) + len(self.tool_code_start)
|
|
283
|
+
end = text.find(self.tool_code_end)
|
|
297
284
|
tool_code_json = text[start:end]
|
|
298
285
|
tool_code = json.loads(tool_code_json)
|
|
299
286
|
return tool_code
|
|
300
287
|
except (ValueError, json.JSONDecodeError):
|
|
301
288
|
return None
|
|
302
|
-
|
|
289
|
+
def _should_call_tool(self, response_text: str) -> bool:
|
|
290
|
+
"""Determines if the model suggests a tool call."""
|
|
291
|
+
# Simple check for tool code markers in response
|
|
292
|
+
return self.tool_code_start in response_text and self.tool_code_end in response_text
|
|
303
293
|
def generate(
|
|
304
294
|
self,
|
|
305
295
|
prompt: Union[str, list[int]],
|
|
306
296
|
stops: list[Union[str, int]] = [],
|
|
307
|
-
sampler: SamplerSettings = DefaultSampling
|
|
297
|
+
sampler: SamplerSettings = DefaultSampling,
|
|
298
|
+
max_iterations: int = 3, # Maximum iterations for tool calls
|
|
308
299
|
) -> str:
|
|
309
300
|
"""
|
|
310
|
-
|
|
301
|
+
Generates text and handles tool calls.
|
|
311
302
|
|
|
312
303
|
Args:
|
|
313
|
-
prompt: The
|
|
314
|
-
stops
|
|
315
|
-
sampler
|
|
304
|
+
prompt (Union[str, list[int]]): The input prompt.
|
|
305
|
+
stops (list[Union[str, int]]): Stop sequences.
|
|
306
|
+
sampler (SamplerSettings): Sampler settings.
|
|
307
|
+
max_iterations (int): Maximum number of tool call iterations.
|
|
316
308
|
|
|
317
309
|
Returns:
|
|
318
|
-
The generated
|
|
310
|
+
str: The generated text.
|
|
319
311
|
"""
|
|
320
312
|
assert_model_is_loaded(self)
|
|
321
313
|
response_text = self.llama.create_completion(
|
|
@@ -331,15 +323,21 @@ class Model:
|
|
|
331
323
|
stop=stops
|
|
332
324
|
)['choices'][0]['text']
|
|
333
325
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
326
|
+
iteration = 0
|
|
327
|
+
while self._should_call_tool(response_text) and iteration < max_iterations:
|
|
328
|
+
tool_code = self._extract_tool_code(response_text)
|
|
329
|
+
if tool_code:
|
|
330
|
+
tool_name = tool_code.get("function", {}).get("name")
|
|
331
|
+
arguments = tool_code.get("function", {}).get("arguments", "")
|
|
332
|
+
if tool_name and arguments and tool_name in self.tools:
|
|
333
|
+
# Execute the tool and append its output
|
|
334
|
+
tool_output = self.tools[tool_name](**json.loads(arguments))
|
|
335
|
+
response_text = response_text.replace(
|
|
336
|
+
f"{self.tool_code_start}{json.dumps(tool_code)}{self.tool_code_end}",
|
|
337
|
+
tool_output
|
|
338
|
+
)
|
|
339
|
+
iteration += 1
|
|
340
|
+
|
|
343
341
|
return response_text
|
|
344
342
|
def __repr__(self) -> str:
|
|
345
343
|
return \
|