Spaces:
Build error
Build error
File size: 6,505 Bytes
bd2d447 | 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 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | #!/usr/bin/env python3
"""
Groq-Specific Reasoning Test
Tests Groq model with reasoning=True, both with and without Headroom.
This isolates whether the issue is Groq-specific or Headroom-specific.
"""
import json
import os
import sys
import traceback
# Enable Agno debugging
os.environ["AGNO_DEBUG"] = "true"
from agno.agent import Agent
from agno.models.groq import Groq
from agno.tools import tool
# Check for API key
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
if not GROQ_API_KEY:
print("ERROR: GROQ_API_KEY environment variable required")
sys.exit(1)
# =============================================================================
# SIMPLE TOOLS
# =============================================================================
@tool(name="get_weather")
def get_weather(city: str) -> str:
"""Get weather for a city.
Args:
city: City name
Returns:
Weather information as JSON
"""
print(f"[TOOL] get_weather called with: {city}")
return json.dumps(
{"city": city, "temperature": "72°F", "conditions": "Sunny", "humidity": "45%"}
)
@tool(name="get_time")
def get_time(timezone: str = "UTC") -> str:
"""Get current time in a timezone.
Args:
timezone: Timezone name
Returns:
Current time
"""
print(f"[TOOL] get_time called with: {timezone}")
return json.dumps({"timezone": timezone, "time": "14:30:00", "date": "2025-01-19"})
# =============================================================================
# TEST FUNCTIONS
# =============================================================================
def test_groq(use_headroom: bool, use_reasoning: bool, model_id: str = "llama-3.3-70b-versatile"):
"""Test Groq with specific configuration."""
label = f"Groq {'+ Headroom' if use_headroom else 'Direct'}, reasoning={use_reasoning}, model={model_id}"
print(f"\n{'#' * 70}")
print(f"# TEST: {label}")
print(f"{'#' * 70}")
try:
# Create the model
if use_headroom:
from headroom.integrations.agno import HeadroomAgnoModel
base_model = Groq(id=model_id)
model = HeadroomAgnoModel(wrapped_model=base_model)
print("[SETUP] Created HeadroomAgnoModel wrapping Groq")
else:
model = Groq(id=model_id)
print("[SETUP] Created Groq model directly")
# Create the agent
agent = Agent(
model=model,
tools=[get_weather, get_time],
reasoning=use_reasoning,
markdown=True,
debug_mode=True,
)
print(f"[SETUP] Created Agent with reasoning={use_reasoning}")
# Simple question
question = "What's the weather in San Francisco and what time is it there?"
print(f"[INPUT] Question: {question}")
# Run the agent
print("[RUN] Starting agent.run()...")
response = agent.run(question)
# Extract response
if hasattr(response, "content") and response.content is not None:
response_text = response.content
elif response is not None:
response_text = str(response)
else:
response_text = "(No response content)"
print(f"[OUTPUT] Response length: {len(response_text)} chars")
print(f"[OUTPUT] Response preview: {response_text[:300]}...")
# Get Headroom stats if available
if use_headroom and hasattr(model, "get_savings_summary"):
stats = model.get_savings_summary()
print(f"[HEADROOM] Stats: {stats}")
return {
"success": True,
"label": label,
"response": response_text[:500],
}
except Exception as e:
error_msg = str(e)
tb = traceback.format_exc()
print(f"[ERROR] Exception: {error_msg}")
print(f"[ERROR] Traceback:\n{tb}")
return {
"success": False,
"label": label,
"error": error_msg,
"traceback": tb,
}
def run_all_tests():
"""Run all Groq test combinations."""
print("\n" + "=" * 70)
print("GROQ REASONING TEST")
print("=" * 70)
print(f"GROQ_API_KEY: {'SET' if GROQ_API_KEY else 'NOT SET'}")
print("=" * 70)
results = []
# Test with llama-3.3-70b-versatile (most capable)
model_id = "llama-3.3-70b-versatile"
test_cases = [
# (use_headroom, use_reasoning)
(False, False), # Baseline: Groq direct, no reasoning
(False, True), # Groq direct, with reasoning
(True, False), # Groq + Headroom, no reasoning
(True, True), # Groq + Headroom, with reasoning <-- This is what fails for user
]
for use_headroom, use_reasoning in test_cases:
result = test_groq(use_headroom, use_reasoning, model_id)
results.append(result)
print(f"\nResult: {'✅ SUCCESS' if result['success'] else '❌ FAILED'}")
if not result["success"]:
print(f"Error: {result.get('error', 'Unknown')[:200]}")
# Summary
print("\n" + "=" * 70)
print("SUMMARY")
print("=" * 70)
for result in results:
status = "✅ PASS" if result["success"] else "❌ FAIL"
print(f"{status} - {result['label']}")
if not result["success"]:
print(f" Error: {result.get('error', 'Unknown')[:100]}")
print("\n" + "=" * 70)
# Analysis
print("\nANALYSIS:")
# Check if Groq + reasoning fails without Headroom
groq_direct_reasoning = next(
(r for r in results if "Direct" in r["label"] and "reasoning=True" in r["label"]), None
)
groq_headroom_reasoning = next(
(r for r in results if "Headroom" in r["label"] and "reasoning=True" in r["label"]), None
)
if groq_direct_reasoning and not groq_direct_reasoning["success"]:
print("⚠️ Groq + reasoning=True fails WITHOUT Headroom!")
print(" This is an Agno/Groq bug, NOT a Headroom issue.")
if (
groq_direct_reasoning
and groq_direct_reasoning["success"]
and groq_headroom_reasoning
and not groq_headroom_reasoning["success"]
):
print("⚠️ Groq + reasoning=True works without Headroom but FAILS with Headroom!")
print(" This IS a Headroom issue that needs investigation.")
if all(r["success"] for r in results):
print("✅ All tests passed! No issues found.")
return results
if __name__ == "__main__":
run_all_tests()
|