abhikamuni commited on
Commit
dcafa2f
·
verified ·
1 Parent(s): 5faf247
Files changed (1) hide show
  1. app/main.py +17 -27
app/main.py CHANGED
@@ -1,10 +1,8 @@
1
  import os
2
- # --- START: FIX FOR ALL CACHE PERMISSION ERRORS ---
3
- # We set the cache for DSPY to /tmp
4
- os.environ["DSPY_CACHE_DIR"] = "/tmp/.dspy_cache"
5
  # We set the HF cache to the folder we create in the Dockerfile
6
  os.environ["HF_HOME"] = "/code/.cache/huggingface"
7
- # --- END: FIX ---
8
 
9
  # --- ALL OTHER IMPORTS MUST BE BELOW THIS FIX ---
10
  import json
@@ -18,7 +16,8 @@ from typing import Dict, Any
18
  # We need to make sure the path is correct
19
  from app.services.guardrails import check_input_guardrail, check_output_guardrail
20
  from app.services.rag_pipeline import generate_solution
21
- from app.services.dspy_feedback import refine_solution_with_dspy
 
22
  from app.schemas import (
23
  AskRequest, AskResponse, FeedbackRequest, FeedbackResponse
24
  )
@@ -61,8 +60,13 @@ async def ask_math_question(request: AskRequest):
61
 
62
  @app.post("/feedback/", response_model=FeedbackResponse, status_code=200)
63
  async def give_feedback(request: FeedbackRequest):
 
 
 
 
64
  print(f"--- HITL: Received Feedback for {request.thread_id} ---")
65
 
 
66
  try:
67
  feedback_entry = request.model_dump()
68
  feedback_entry["timestamp"] = datetime.utcnow().isoformat()
@@ -71,36 +75,22 @@ async def give_feedback(request: FeedbackRequest):
71
  except Exception as e:
72
  print(f"--- HITL: Error logging feedback: {e} ---")
73
 
 
 
 
 
74
  if request.rating == "bad" and request.feedback_text:
75
- print(f"--- HITL: Rating is 'bad'. Generating refinement... ---")
76
- try:
77
- refined_solution = refine_solution_with_dspy(
78
- question=request.question,
79
- original_solution=request.original_solution,
80
- user_feedback=request.feedback_text
81
- )
82
-
83
- is_safe, message = check_output_guardrail(refined_solution)
84
- if not is_safe:
85
- raise HTTPException(status_code=500, detail=f"Refined output blocked: {message}")
86
-
87
- return FeedbackResponse(
88
- solution=message,
89
- source="refined", # New source
90
- thread_id=request.thread_id,
91
- question=request.question
92
- )
93
- except Exception as e:
94
- print(f"--- HITL: Error during refinement: {e} ---")
95
- raise HTTPException(status_code=500, detail="Error processing feedback.")
96
 
97
- print("--- HITL: Rating is 'good'. Logging only. ---")
98
  return FeedbackResponse(
99
  solution=request.original_solution,
100
  source="feedback_logged",
101
  thread_id=request.thread_id,
102
  question=request.question
103
  )
 
104
 
105
  @app.get("/")
106
  def read_root():
 
1
  import os
2
+ # --- KEEP THE SENTENCE-TRANSFORMERS FIX ---
 
 
3
  # We set the HF cache to the folder we create in the Dockerfile
4
  os.environ["HF_HOME"] = "/code/.cache/huggingface"
5
+ # --- REMOVED THE DSPY ENV VAR ---
6
 
7
  # --- ALL OTHER IMPORTS MUST BE BELOW THIS FIX ---
8
  import json
 
16
  # We need to make sure the path is correct
17
  from app.services.guardrails import check_input_guardrail, check_output_guardrail
18
  from app.services.rag_pipeline import generate_solution
19
+ # --- REMOVED THE DSPY IMPORT ---
20
+ # from app.services.dspy_feedback import refine_solution_with_dspy
21
  from app.schemas import (
22
  AskRequest, AskResponse, FeedbackRequest, FeedbackResponse
23
  )
 
60
 
61
  @app.post("/feedback/", response_model=FeedbackResponse, status_code=200)
62
  async def give_feedback(request: FeedbackRequest):
63
+ """
64
+ Endpoint to receive feedback.
65
+ The DSPy refinement has been removed.
66
+ """
67
  print(f"--- HITL: Received Feedback for {request.thread_id} ---")
68
 
69
+ # 1. Log the feedback
70
  try:
71
  feedback_entry = request.model_dump()
72
  feedback_entry["timestamp"] = datetime.utcnow().isoformat()
 
75
  except Exception as e:
76
  print(f"--- HITL: Error logging feedback: {e} ---")
77
 
78
+ # --- START: MODIFIED SECTION ---
79
+ # Since dspy is removed, we just log the feedback and
80
+ # return the original solution, no matter if it's "good" or "bad".
81
+
82
  if request.rating == "bad" and request.feedback_text:
83
+ print(f"--- HITL: Rating is 'bad'. Logging only (refinement disabled). ---")
84
+ else:
85
+ print("--- HITL: Rating is 'good'. Logging only. ---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
 
87
  return FeedbackResponse(
88
  solution=request.original_solution,
89
  source="feedback_logged",
90
  thread_id=request.thread_id,
91
  question=request.question
92
  )
93
+ # --- END: MODIFIED SECTION ---
94
 
95
  @app.get("/")
96
  def read_root():