Spaces:
Sleeping
Sleeping
structure code langchain
Browse files- .gitignore +10 -0
- =2.0.0 +0 -15
- __pycache__/agent.cpython-312.pyc +0 -0
- __pycache__/app.cpython-312.pyc +0 -0
- test_utils.py +0 -158
.gitignore
CHANGED
|
@@ -1 +1,11 @@
|
|
| 1 |
.env
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
.env
|
| 2 |
+
|
| 3 |
+
pycache/
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.pyc
|
| 6 |
+
*.pyo
|
| 7 |
+
*.pyd
|
| 8 |
+
*.pyw
|
| 9 |
+
*.pyz
|
| 10 |
+
*.pywz
|
| 11 |
+
*.pyzw
|
=2.0.0
DELETED
|
@@ -1,15 +0,0 @@
|
|
| 1 |
-
Collecting torch
|
| 2 |
-
Downloading torch-2.7.1-cp312-none-macosx_11_0_arm64.whl.metadata (29 kB)
|
| 3 |
-
Requirement already satisfied: filelock in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (3.16.1)
|
| 4 |
-
Requirement already satisfied: typing-extensions>=4.10.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (4.13.2)
|
| 5 |
-
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (75.1.0)
|
| 6 |
-
Requirement already satisfied: sympy>=1.13.3 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (1.13.3)
|
| 7 |
-
Requirement already satisfied: networkx in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (3.3)
|
| 8 |
-
Requirement already satisfied: jinja2 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (3.1.4)
|
| 9 |
-
Requirement already satisfied: fsspec in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from torch) (2024.3.1)
|
| 10 |
-
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from sympy>=1.13.3->torch) (1.3.0)
|
| 11 |
-
Requirement already satisfied: MarkupSafe>=2.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from jinja2->torch) (2.1.5)
|
| 12 |
-
Downloading torch-2.7.1-cp312-none-macosx_11_0_arm64.whl (68.6 MB)
|
| 13 |
-
ββββββββββββββββββββββββββββββββββββββββ 68.6/68.6 MB 53.9 MB/s eta 0:00:00
|
| 14 |
-
Installing collected packages: torch
|
| 15 |
-
Successfully installed torch-2.7.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__pycache__/agent.cpython-312.pyc
DELETED
|
Binary file (17 kB)
|
|
|
__pycache__/app.cpython-312.pyc
DELETED
|
Binary file (6.18 kB)
|
|
|
test_utils.py
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test file Δα» kiα»m tra toΓ n bα» utils system
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 8 |
-
|
| 9 |
-
from utils import (
|
| 10 |
-
process_question_with_tools,
|
| 11 |
-
get_agent_state,
|
| 12 |
-
reset_agent_state,
|
| 13 |
-
analyze_question_type,
|
| 14 |
-
reverse_text_if_needed,
|
| 15 |
-
get_system_prompt
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
def test_text_processing():
|
| 19 |
-
"""Test text processing tool"""
|
| 20 |
-
print("=== Testing Text Processing ===")
|
| 21 |
-
|
| 22 |
-
# Test reverse text
|
| 23 |
-
reversed_question = ".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI"
|
| 24 |
-
processed = reverse_text_if_needed(reversed_question)
|
| 25 |
-
print(f"Original: {reversed_question}")
|
| 26 |
-
print(f"Processed: {processed}")
|
| 27 |
-
print()
|
| 28 |
-
|
| 29 |
-
def test_question_analysis():
|
| 30 |
-
"""Test question type analysis"""
|
| 31 |
-
print("=== Testing Question Analysis ===")
|
| 32 |
-
|
| 33 |
-
test_questions = [
|
| 34 |
-
"Who was Marie Curie?",
|
| 35 |
-
"What is in this YouTube video? https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
| 36 |
-
"Can you read this image for me?",
|
| 37 |
-
"What does this audio file say?",
|
| 38 |
-
"Calculate 2+2*3",
|
| 39 |
-
".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw"
|
| 40 |
-
]
|
| 41 |
-
|
| 42 |
-
for question in test_questions:
|
| 43 |
-
q_type = analyze_question_type(question)
|
| 44 |
-
print(f"Question: {question[:50]}...")
|
| 45 |
-
print(f"Type: {q_type}")
|
| 46 |
-
print()
|
| 47 |
-
|
| 48 |
-
def test_state_management():
|
| 49 |
-
"""Test state management"""
|
| 50 |
-
print("=== Testing State Management ===")
|
| 51 |
-
|
| 52 |
-
# Reset state
|
| 53 |
-
reset_agent_state()
|
| 54 |
-
state = get_agent_state()
|
| 55 |
-
|
| 56 |
-
# Start task
|
| 57 |
-
task = state.start_new_task("test_001", "Who is Einstein?")
|
| 58 |
-
print(f"Task created: {task.task_id}")
|
| 59 |
-
print(f"Question: {task.question}")
|
| 60 |
-
|
| 61 |
-
# Update context
|
| 62 |
-
state.update_task_context(question_type="wiki", processed_question="Who is Einstein?")
|
| 63 |
-
print(f"Updated type: {task.question_type}")
|
| 64 |
-
|
| 65 |
-
# Generate summary
|
| 66 |
-
summary = state.generate_context_summary()
|
| 67 |
-
print(f"Context summary:\n{summary}")
|
| 68 |
-
print()
|
| 69 |
-
|
| 70 |
-
def test_prompts():
|
| 71 |
-
"""Test prompt system"""
|
| 72 |
-
print("=== Testing Prompts ===")
|
| 73 |
-
|
| 74 |
-
# System prompt
|
| 75 |
-
system_prompt = get_system_prompt("main_agent")
|
| 76 |
-
print(f"System prompt length: {len(system_prompt)} characters")
|
| 77 |
-
print(f"First 100 chars: {system_prompt[:100]}...")
|
| 78 |
-
print()
|
| 79 |
-
|
| 80 |
-
def test_orchestration():
|
| 81 |
-
"""Test tool orchestration"""
|
| 82 |
-
print("=== Testing Tool Orchestration ===")
|
| 83 |
-
|
| 84 |
-
# Test with Wikipedia question (no external dependencies)
|
| 85 |
-
question = "Who was Albert Einstein?"
|
| 86 |
-
print(f"Processing question: {question}")
|
| 87 |
-
|
| 88 |
-
try:
|
| 89 |
-
result = process_question_with_tools(question)
|
| 90 |
-
print(f"Question type detected: {result['question_type']}")
|
| 91 |
-
print(f"Tools used: {result['tools_used']}")
|
| 92 |
-
print(f"Successful tools: {result['successful_tools']}")
|
| 93 |
-
print(f"Failed tools: {result['failed_tools']}")
|
| 94 |
-
|
| 95 |
-
# Print tool results summary
|
| 96 |
-
if result['tool_results']:
|
| 97 |
-
print("\nTool Results Summary:")
|
| 98 |
-
for tool_result in result['tool_results']:
|
| 99 |
-
status = "β
" if tool_result.success else "β"
|
| 100 |
-
print(f" {status} {tool_result.tool_name}: {tool_result.execution_time:.2f}s")
|
| 101 |
-
if not tool_result.success and tool_result.error_message:
|
| 102 |
-
print(f" Error: {tool_result.error_message}")
|
| 103 |
-
|
| 104 |
-
print("\nCached data keys:", list(result['cached_data'].keys()))
|
| 105 |
-
|
| 106 |
-
except Exception as e:
|
| 107 |
-
print(f"Error in orchestration: {e}")
|
| 108 |
-
import traceback
|
| 109 |
-
traceback.print_exc()
|
| 110 |
-
|
| 111 |
-
print()
|
| 112 |
-
|
| 113 |
-
def test_youtube_detection():
|
| 114 |
-
"""Test YouTube URL detection"""
|
| 115 |
-
print("=== Testing YouTube Detection ===")
|
| 116 |
-
|
| 117 |
-
youtube_question = "What is this video about? https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
| 118 |
-
print(f"Processing YouTube question: {youtube_question}")
|
| 119 |
-
|
| 120 |
-
try:
|
| 121 |
-
result = process_question_with_tools(youtube_question)
|
| 122 |
-
print(f"Question type: {result['question_type']}")
|
| 123 |
-
print(f"Tools to run: {result['tools_used']}")
|
| 124 |
-
|
| 125 |
-
# Check if YouTube tool was attempted
|
| 126 |
-
youtube_results = [r for r in result['tool_results'] if r.tool_name == "youtube_tool"]
|
| 127 |
-
if youtube_results:
|
| 128 |
-
youtube_result = youtube_results[0]
|
| 129 |
-
print(f"YouTube tool status: {'Success' if youtube_result.success else 'Failed'}")
|
| 130 |
-
if youtube_result.success:
|
| 131 |
-
print(f"YouTube content available: {bool(youtube_result.result)}")
|
| 132 |
-
else:
|
| 133 |
-
print(f"YouTube error: {youtube_result.error_message}")
|
| 134 |
-
|
| 135 |
-
except Exception as e:
|
| 136 |
-
print(f"Error testing YouTube: {e}")
|
| 137 |
-
|
| 138 |
-
print()
|
| 139 |
-
|
| 140 |
-
def run_all_tests():
|
| 141 |
-
"""Run all tests"""
|
| 142 |
-
print("π§ͺ Starting Utils System Tests\n")
|
| 143 |
-
|
| 144 |
-
test_text_processing()
|
| 145 |
-
test_question_analysis()
|
| 146 |
-
test_state_management()
|
| 147 |
-
test_prompts()
|
| 148 |
-
test_orchestration()
|
| 149 |
-
test_youtube_detection()
|
| 150 |
-
|
| 151 |
-
print("β
All tests completed!")
|
| 152 |
-
|
| 153 |
-
if __name__ == "__main__":
|
| 154 |
-
# Set environment variables if needed
|
| 155 |
-
os.environ.setdefault("GROQ_API_KEY", "your_groq_key_here")
|
| 156 |
-
os.environ.setdefault("HF_TOKEN", "your_hf_token_here")
|
| 157 |
-
|
| 158 |
-
run_all_tests()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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