Remove unused environment check and verification scripts to clean up the codebase
Browse files- check_env.py +0 -21
- check_env_v2.py +0 -25
- check_questions.py +0 -9
- verify_fallback.py +0 -68
- verify_fixes.py +0 -72
- verify_simple.py +0 -36
check_env.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
|
| 4 |
-
# Try to load .env from current directory
|
| 5 |
-
env_path = os.path.join(os.getcwd(), '.env')
|
| 6 |
-
print(f"Checking for .env at: {env_path}")
|
| 7 |
-
print(f"File exists: {os.path.exists(env_path)}")
|
| 8 |
-
|
| 9 |
-
load_dotenv(env_path)
|
| 10 |
-
|
| 11 |
-
# Print keys (masking values)
|
| 12 |
-
keys = list(os.environ.keys())
|
| 13 |
-
relevant_keys = [k for k in keys if any(x in k for x in ["API_KEY", "TOKEN", "GOOGLE", "GROQ", "NVIDIA", "VERCEL", "OPENROUTER"])]
|
| 14 |
-
print(f"Relevant keys found: {relevant_keys}")
|
| 15 |
-
|
| 16 |
-
# Specifically check the ones we need
|
| 17 |
-
needed = ["NVIDIA_API_KEY", "VERCEL_API_KEY", "OPENROUTER_API_KEY", "GOOGLE_API_KEY", "GROQ_API_KEY"]
|
| 18 |
-
for k in needed:
|
| 19 |
-
val = os.getenv(k)
|
| 20 |
-
status = "PRESENT (length={})".format(len(val)) if val else "MISSING"
|
| 21 |
-
print(f"{k}: {status}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_env_v2.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
|
| 4 |
-
# Try to load .env from current directory with override=True
|
| 5 |
-
env_path = os.path.join(os.getcwd(), '.env')
|
| 6 |
-
print(f"Checking for .env at: {env_path}")
|
| 7 |
-
print(f"File exists: {os.path.exists(env_path)}")
|
| 8 |
-
|
| 9 |
-
load_dotenv(env_path, override=True)
|
| 10 |
-
|
| 11 |
-
# Print keys (case-insensitive check)
|
| 12 |
-
keys = list(os.environ.keys())
|
| 13 |
-
relevant_keys = [k for k in keys if any(x in k.upper() for x in ["API_KEY", "TOKEN", "GOOGLE", "GROQ", "NVIDIA", "VERCEL", "OPENROUTER"])]
|
| 14 |
-
print(f"Relevant keys found: {relevant_keys}")
|
| 15 |
-
|
| 16 |
-
# Check specifically
|
| 17 |
-
needed = ["NVIDIA_API_KEY", "VERCEL_API_KEY", "OPENROUTER_API_KEY", "GOOGLE_API_KEY", "GROQ_API_KEY"]
|
| 18 |
-
for k in needed:
|
| 19 |
-
# Try case-insensitive lookup
|
| 20 |
-
found_key = next((key for key in keys if key.upper() == k), None)
|
| 21 |
-
if found_key:
|
| 22 |
-
val = os.getenv(found_key)
|
| 23 |
-
print(f"{found_key}: PRESENT (length={len(val)})")
|
| 24 |
-
else:
|
| 25 |
-
print(f"{k}: MISSING")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_questions.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
resp = requests.get('https://agents-course-unit4-scoring.hf.space/questions')
|
| 3 |
-
questions = resp.json()
|
| 4 |
-
print(f"Total questions: {len(questions)}")
|
| 5 |
-
for i, q in enumerate(questions):
|
| 6 |
-
print(f"{i+1}. {q.get('question', 'N/A')[:120]}...")
|
| 7 |
-
print(f" File: {q.get('file_name', 'None')}")
|
| 8 |
-
print(f" Task ID: {q.get('task_id', 'N/A')[:20]}...")
|
| 9 |
-
print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_fallback.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
from unittest.mock import MagicMock, patch
|
| 4 |
-
|
| 5 |
-
# Mocking modules that might not be available or needed for this test
|
| 6 |
-
sys.modules['cv2'] = MagicMock()
|
| 7 |
-
sys.modules['whisper'] = MagicMock()
|
| 8 |
-
|
| 9 |
-
# Set dummy env vars BEFORE importing agent
|
| 10 |
-
os.environ["OPENROUTER_API_KEY"] = "dummy"
|
| 11 |
-
os.environ["GOOGLE_API_KEY"] = "dummy"
|
| 12 |
-
os.environ["GROQ_API_KEY"] = "dummy"
|
| 13 |
-
os.environ["NVIDIA_API_KEY"] = "dummy"
|
| 14 |
-
os.environ["VERCEL_API_KEY"] = "dummy"
|
| 15 |
-
|
| 16 |
-
# Add the current directory to path so we can import agent
|
| 17 |
-
sys.path.append(os.getcwd())
|
| 18 |
-
|
| 19 |
-
import agent
|
| 20 |
-
from langchain_core.messages import HumanMessage
|
| 21 |
-
|
| 22 |
-
def test_fallback_logic():
|
| 23 |
-
print("Testing fallback logic...")
|
| 24 |
-
|
| 25 |
-
# Mock the invoke method for each tier's model
|
| 26 |
-
# Tiers: 0:OpenRouter, 1:Gemini, 2:Groq, 3:NVIDIA, 4:Vercel
|
| 27 |
-
|
| 28 |
-
with patch('agent.openrouter_model.invoke') as mock_openrouter, \
|
| 29 |
-
patch('agent.gemini_model.invoke') as mock_gemini, \
|
| 30 |
-
patch('agent.model.invoke') as mock_groq, \
|
| 31 |
-
patch('agent.nvidia_model.invoke') as mock_nvidia, \
|
| 32 |
-
patch('agent.vercel_model.invoke') as mock_vercel:
|
| 33 |
-
|
| 34 |
-
# Simulate failure for all tiers up to NVIDIA
|
| 35 |
-
mock_openrouter.side_effect = Exception("Rate limit (429)")
|
| 36 |
-
mock_gemini.side_effect = Exception("Rate limit (429)")
|
| 37 |
-
mock_groq.side_effect = Exception("Rate limit (429)")
|
| 38 |
-
|
| 39 |
-
# NVIDIA should succeed
|
| 40 |
-
mock_nvidia.return_value = MagicMock(content="NVIDIA response")
|
| 41 |
-
|
| 42 |
-
msgs = [HumanMessage(content="Hello")]
|
| 43 |
-
response, tier_idx = agent.smart_invoke(msgs, use_tools=False)
|
| 44 |
-
|
| 45 |
-
print(f"Response from tier {tier_idx}: {response.content}")
|
| 46 |
-
assert tier_idx == 3
|
| 47 |
-
assert response.content == "NVIDIA response"
|
| 48 |
-
print("Fallback to NVIDIA successful!")
|
| 49 |
-
|
| 50 |
-
# Now simulate failure up to Vercel
|
| 51 |
-
mock_nvidia.side_effect = Exception("Rate limit (429)")
|
| 52 |
-
mock_vercel.return_value = MagicMock(content="Vercel response")
|
| 53 |
-
|
| 54 |
-
response, tier_idx = agent.smart_invoke(msgs, use_tools=False)
|
| 55 |
-
print(f"Response from tier {tier_idx}: {response.content}")
|
| 56 |
-
assert tier_idx == 4
|
| 57 |
-
assert response.content == "Vercel response"
|
| 58 |
-
print("Fallback to Vercel successful!")
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
try:
|
| 62 |
-
test_fallback_logic()
|
| 63 |
-
print("All fallback tests passed!")
|
| 64 |
-
except Exception as e:
|
| 65 |
-
print(f"Test failed: {e}")
|
| 66 |
-
import traceback
|
| 67 |
-
traceback.print_exc()
|
| 68 |
-
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_fixes.py
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
from unittest.mock import MagicMock, patch
|
| 4 |
-
|
| 5 |
-
# Mocking modules
|
| 6 |
-
sys.modules['cv2'] = MagicMock()
|
| 7 |
-
sys.modules['whisper'] = MagicMock()
|
| 8 |
-
|
| 9 |
-
# Set dummy env vars
|
| 10 |
-
os.environ["OPENROUTER_API_KEY"] = "dummy"
|
| 11 |
-
os.environ["GOOGLE_API_KEY"] = "dummy"
|
| 12 |
-
os.environ["GROQ_API_KEY"] = "dummy"
|
| 13 |
-
os.environ["NVIDIA_API_KEY"] = "dummy"
|
| 14 |
-
os.environ["VERCEL_API_KEY"] = "dummy"
|
| 15 |
-
|
| 16 |
-
sys.path.append(os.getcwd())
|
| 17 |
-
|
| 18 |
-
import agent
|
| 19 |
-
from langchain_core.messages import HumanMessage
|
| 20 |
-
|
| 21 |
-
def test_gemini_alternatives_on_rate_limit():
|
| 22 |
-
print("Testing Gemini alternatives on rate limit...")
|
| 23 |
-
|
| 24 |
-
# We need to mock ChatGoogleGenerativeAI to simulate rate limit on one instance but success on another
|
| 25 |
-
# Since they are created inside smart_invoke, we patch the class constructor or just the instances if we can
|
| 26 |
-
|
| 27 |
-
with patch('agent.openrouter_model.invoke') as mock_openrouter, \
|
| 28 |
-
patch('agent.ChatGoogleGenerativeAI') as mock_gemini_class:
|
| 29 |
-
|
| 30 |
-
# OpenRouter fails
|
| 31 |
-
mock_openrouter.side_effect = Exception("Rate limit (429)")
|
| 32 |
-
|
| 33 |
-
# First Gemini call (primary) fails with rate limit
|
| 34 |
-
# Second Gemini call (alternative) succeeds
|
| 35 |
-
mock_primary = MagicMock()
|
| 36 |
-
mock_primary.invoke.side_effect = Exception("Rate limit (429)")
|
| 37 |
-
mock_primary.model = "gemini-2.5-flash"
|
| 38 |
-
|
| 39 |
-
mock_alt = MagicMock()
|
| 40 |
-
mock_alt.invoke.return_value = MagicMock(content="Gemini alternative response")
|
| 41 |
-
mock_alt.model = "gemini-2.5-flash-lite"
|
| 42 |
-
|
| 43 |
-
# Control the sequence of ChatGoogleGenerativeAI creation
|
| 44 |
-
# agent.py creates gemini_model at top level, then potentially more in smart_invoke
|
| 45 |
-
mock_gemini_class.side_effect = [mock_alt] # The one created in the loop
|
| 46 |
-
|
| 47 |
-
# We also need to mock the already created gemini_model
|
| 48 |
-
with patch('agent.gemini_model', mock_primary):
|
| 49 |
-
msgs = [HumanMessage(content="Hello")]
|
| 50 |
-
response, tier_idx = agent.smart_invoke(msgs, use_tools=False)
|
| 51 |
-
|
| 52 |
-
print(f"Response from tier {tier_idx}: {response.content}")
|
| 53 |
-
# Tier 1 is Gemini
|
| 54 |
-
assert tier_idx == 1
|
| 55 |
-
assert response.content == "Gemini alternative response"
|
| 56 |
-
print("Gemini alternative on rate limit successful!")
|
| 57 |
-
|
| 58 |
-
def test_nvidia_name():
|
| 59 |
-
print("Checking NVIDIA model name...")
|
| 60 |
-
assert agent.nvidia_model.model_name == "meta/llama-3.1-405b-instruct"
|
| 61 |
-
print("NVIDIA model name is correct!")
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
try:
|
| 65 |
-
test_gemini_alternatives_on_rate_limit()
|
| 66 |
-
test_nvidia_name()
|
| 67 |
-
print("All fix tests passed!")
|
| 68 |
-
except Exception as e:
|
| 69 |
-
print(f"Test failed: {e}")
|
| 70 |
-
import traceback
|
| 71 |
-
traceback.print_exc()
|
| 72 |
-
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_simple.py
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
from unittest.mock import MagicMock
|
| 4 |
-
|
| 5 |
-
# Mocking modules
|
| 6 |
-
sys.modules['cv2'] = MagicMock()
|
| 7 |
-
sys.modules['whisper'] = MagicMock()
|
| 8 |
-
|
| 9 |
-
# Set dummy env vars
|
| 10 |
-
os.environ["OPENROUTER_API_KEY"] = "dummy"
|
| 11 |
-
os.environ["GOOGLE_API_KEY"] = "dummy"
|
| 12 |
-
os.environ["GROQ_API_KEY"] = "dummy"
|
| 13 |
-
os.environ["NVIDIA_API_KEY"] = "dummy"
|
| 14 |
-
os.environ["VERCEL_API_KEY"] = "dummy"
|
| 15 |
-
|
| 16 |
-
sys.path.append(os.getcwd())
|
| 17 |
-
|
| 18 |
-
import agent
|
| 19 |
-
|
| 20 |
-
def verify_tiers():
|
| 21 |
-
from langchain_core.messages import HumanMessage
|
| 22 |
-
|
| 23 |
-
# We can't easily call smart_invoke without real models unless we mock heavily.
|
| 24 |
-
# Let's just check the tiers list structure in a dummy call.
|
| 25 |
-
# Actually, we can't easily access 'tiers' inside smart_invoke as it's a local variable.
|
| 26 |
-
|
| 27 |
-
# Let's check the global model objects.
|
| 28 |
-
print(f"NVIDIA model initialized: {agent.nvidia_model is not None}")
|
| 29 |
-
print(f"Vercel model initialized: {agent.vercel_model is not None}")
|
| 30 |
-
|
| 31 |
-
# Check if they have invoke (they should)
|
| 32 |
-
print(f"NVIDIA model hasattr invoke: {hasattr(agent.nvidia_model, 'invoke')}")
|
| 33 |
-
print(f"Vercel model hasattr invoke: {hasattr(agent.vercel_model, 'invoke')}")
|
| 34 |
-
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
verify_tiers()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|