Spaces:
Running
Running
File size: 2,585 Bytes
92bfe31 | 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 | import sys
import os
sys.path.insert(0, 'backend')
# Set required env vars
os.environ['DEEPSEEK_API_KEY'] = os.getenv('DEEPSEEK_API_KEY', '')
os.environ['DEEPSEEK_BASE_URL'] = os.getenv('DEEPSEEK_BASE_URL', 'https://api.deepseek.com')
from rag.curriculum_rag import retrieve_lesson_pdf_context, build_lesson_prompt
from services.inference_client import InferenceClient, InferenceRequest
# Test retrieval
print("Testing retrieval...")
try:
chunks, mode = retrieve_lesson_pdf_context(
topic="Represent real-life relationships as functions and interpret domain/range.",
subject="General Mathematics",
quarter=2,
lesson_title="Represent real-life relationships as functions and interpret domain/range.",
module_id="gen-math",
lesson_id="gm-q2-functions-graphs-l1",
competency_code="GM11-FG-1",
top_k=8,
)
print(f"Retrieved {len(chunks)} chunks, mode={mode}")
except Exception as e:
print(f"Retrieval ERROR: {type(e).__name__}: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
# Test prompt building
print("\nTesting prompt building...")
try:
prompt = build_lesson_prompt(
lesson_title="Represent real-life relationships as functions and interpret domain/range.",
competency="Represent real-life relationships as functions and interpret domain/range.",
grade_level="Grade 11-12",
subject="General Mathematics",
quarter=2,
learner_level="Grade 11-12",
module_unit="n/a",
curriculum_chunks=chunks,
competency_code="GM11-FG-1",
)
print(f"Prompt length: {len(prompt)} chars")
print(f"Prompt preview: {prompt[:200]}...")
except Exception as e:
print(f"Prompt building ERROR: {type(e).__name__}: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
# Test inference (optional - might cost money)
print("\nTesting inference...")
try:
client = InferenceClient()
req = InferenceRequest(
messages=[
{"role": "system", "content": "You are a precise DepEd-aligned curriculum assistant."},
{"role": "user", "content": prompt},
],
task_type="lesson_generation",
max_new_tokens=100, # Small for testing
temperature=0.2,
top_p=0.9,
enable_thinking=True,
)
result = client.generate_from_messages(req)
print(f"Inference result: {result[:200]}...")
print("SUCCESS!")
except Exception as e:
print(f"Inference ERROR: {type(e).__name__}: {e}")
import traceback
traceback.print_exc() |