Singtel_Use_Case1 / test_smolagent.py
cosmoruler
problems fixed
c69ba8c
#!/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)