|
|
""" |
|
|
Test enhanced function calling with debug mode. |
|
|
|
|
|
This script tests the improved function calling with debug mode enabled |
|
|
to verify that the enhancements work correctly. |
|
|
""" |
|
|
|
|
|
import logging |
|
|
import sys |
|
|
import json |
|
|
import importlib.util |
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
|
level=logging.INFO, |
|
|
format='%(asctime)s - %(levelname)s - %(message)s', |
|
|
handlers=[logging.StreamHandler(sys.stdout)] |
|
|
) |
|
|
|
|
|
|
|
|
def check_module_quietly(module_name): |
|
|
"""Check if a module is available without printing warnings""" |
|
|
is_available = importlib.util.find_spec(module_name) is not None |
|
|
if not is_available: |
|
|
print(f"{module_name} not available: No module named '{module_name}'") |
|
|
return is_available |
|
|
|
|
|
|
|
|
check_module_quietly('bandit') |
|
|
check_module_quietly('torchvision') |
|
|
|
|
|
|
|
|
from atles.ollama_client_enhanced import OllamaFunctionCaller |
|
|
|
|
|
def test_function_call_handling(): |
|
|
"""Test the enhanced function call handling with various formats.""" |
|
|
|
|
|
print("\n=== Testing Enhanced Function Call Handling ===\n") |
|
|
|
|
|
|
|
|
client = OllamaFunctionCaller(debug_mode=True) |
|
|
print(f"Debug mode enabled: {client.get_debug_mode()}") |
|
|
|
|
|
|
|
|
print("Attempting to load debug settings from config...") |
|
|
client.load_debug_settings_from_config() |
|
|
print(f"Debug mode after loading config: {client.get_debug_mode()}") |
|
|
|
|
|
|
|
|
client.set_debug_mode(True) |
|
|
print(f"Debug mode after manual setting: {client.get_debug_mode()}") |
|
|
|
|
|
|
|
|
test_cases = [ |
|
|
|
|
|
"FUNCTION_CALL:web_search:{\"query\": \"ATLES framework capabilities\", \"count\": 3}", |
|
|
|
|
|
|
|
|
"FUNCTION_CALL: web_search : {\"query\": \"ATLES framework capabilities\", \"count\": 3}", |
|
|
|
|
|
|
|
|
"Function_Call:web_search:{\"query\": \"ATLES framework capabilities\", \"count\": 3}", |
|
|
|
|
|
|
|
|
"I think you should search the web. FUNCTION_CALL:web_search:{\"query\": \"ATLES framework capabilities\"} Let me know the results.", |
|
|
|
|
|
|
|
|
"FUNCTION_CALL:web_search:{'query': 'ATLES framework capabilities', 'count': 3}", |
|
|
|
|
|
|
|
|
"""Here's a function call: |
|
|
FUNCTION_CALL:web_search:{ |
|
|
"query": "ATLES framework capabilities", |
|
|
"count": 3 |
|
|
} |
|
|
Let's see what it returns.""", |
|
|
|
|
|
|
|
|
"web_search:{\"query\": \"ATLES framework capabilities\", \"count\": 3}", |
|
|
|
|
|
|
|
|
"FUNCTION_CALL:nonexistent_function:{\"query\": \"test\"}", |
|
|
|
|
|
|
|
|
"FUNCTION_CALL:web_search:{query: \"Missing quotes\", count: 3}", |
|
|
] |
|
|
|
|
|
|
|
|
for i, test_case in enumerate(test_cases): |
|
|
print(f"\n--- Test Case {i+1} ---") |
|
|
print(f"INPUT: {test_case[:50]}{'...' if len(test_case) > 50 else ''}") |
|
|
|
|
|
result = client.handle_function_call(test_case) |
|
|
|
|
|
print(f"OUTPUT: {result[:100]}{'...' if len(result) > 100 else ''}") |
|
|
print("-" * 50) |
|
|
|
|
|
print("\nTesting complete!") |
|
|
|
|
|
def test_web_functions_execution(): |
|
|
"""Test the execution of web functions.""" |
|
|
|
|
|
print("\n=== Testing Web Functions Execution ===\n") |
|
|
|
|
|
client = OllamaFunctionCaller(debug_mode=True) |
|
|
|
|
|
|
|
|
print("Testing web_search function:") |
|
|
result = client.execute_function("web_search", {"query": "ATLES framework capabilities"}) |
|
|
print(json.dumps(result, indent=2)) |
|
|
print("-" * 50) |
|
|
|
|
|
|
|
|
print("\nTesting check_url_accessibility function:") |
|
|
result = client.execute_function("check_url_accessibility", {"url": "https://www.example.com"}) |
|
|
print(json.dumps(result, indent=2)) |
|
|
print("-" * 50) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("Starting function call debug tests...") |
|
|
test_function_call_handling() |
|
|
test_web_functions_execution() |
|
|
|