Spaces:
Runtime error
Runtime error
File size: 3,331 Bytes
c69ba8c |
1 2 3 4 5 6 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 |
#!/usr/bin/env python3
"""
Simple test of SmoLagent functionality
"""
import pandas as pd
from smolagents import CodeAgent, DuckDuckGoSearchTool
import warnings
warnings.filterwarnings('ignore')
def test_basic_smolagent():
"""Test basic SmoLagent setup"""
print("π§ͺ Testing SmoLagent Setup...")
try:
# Test 1: Import check
print("β
Imports successful")
# Test 2: Create agent without model (should fail gracefully)
try:
agent = CodeAgent(tools=[DuckDuckGoSearchTool()])
print("β
Agent created without model")
except Exception as e:
print(f"β Agent creation failed: {e}")
print("π‘ This is expected - CodeAgent needs a model parameter")
# Test 3: Try with a simple model setup
try:
from smolagents import HfApiModel
print("π Trying HuggingFace model...")
model = HfApiModel(model_id="microsoft/DialoGPT-medium")
agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=model
)
print("β
Agent created successfully with HuggingFace model!")
# Test a simple query
response = agent.run("What is 2 + 2?")
print(f"π€ Agent response: {response}")
except Exception as e:
print(f"β HuggingFace model failed: {e}")
# Test 4: Try Ollama
try:
from smolagents import OllamaModel
print("π Trying Ollama model...")
model = OllamaModel(model_id="llama2", base_url="http://localhost:11434")
agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=model
)
print("β
Agent created successfully with Ollama!")
# Test a simple query
response = agent.run("What is 2 + 2?")
print(f"π€ Agent response: {response}")
except Exception as e:
print(f"β Ollama model failed: {e}")
print("π‘ Make sure Ollama is running with: ollama serve")
except Exception as e:
print(f"β Test failed: {e}")
def test_with_data():
"""Test SmoLagent with actual CSV data"""
csv_file_path = "C:/Users/Cosmo/Desktop/NTU Peak Singtel/outsystems_sample_logs_6months.csv"
try:
# Load data
print("\nπ Loading CSV data...")
df = pd.read_csv(csv_file_path)
print(f"β
Data loaded: {df.shape[0]} rows, {df.shape[1]} columns")
print(f"π Columns: {list(df.columns)}")
# Basic analysis
error_count = df[df['LogLevel'] == 'Error'].shape[0]
print(f"π¨ Error entries: {error_count}")
return df
except Exception as e:
print(f"β Data loading failed: {e}")
return None
if __name__ == "__main__":
print("=" * 50)
print("π€ SMOLAGENT TEST SUITE")
print("=" * 50)
# Test basic functionality
test_basic_smolagent()
# Test with data
df = test_with_data()
print("\n" + "=" * 50)
print("β
Test completed!")
print("=" * 50)
|