Spaces:
Sleeping
Sleeping
minor changes
Browse files
LLM.py
CHANGED
|
@@ -4,35 +4,6 @@ from config import (
|
|
| 4 |
query_gen_api_key_1, query_gen_api_key_2, query_gen_api_key_3, query_gen_api_key_4
|
| 5 |
)
|
| 6 |
|
| 7 |
-
import json
|
| 8 |
-
import threading
|
| 9 |
-
import datetime
|
| 10 |
-
from pathlib import Path
|
| 11 |
-
|
| 12 |
-
# Thread-safe writer
|
| 13 |
-
_log_lock = threading.Lock()
|
| 14 |
-
LOG_PATH = Path("qa_pipeline_log.jsonl") # adjust path as needed
|
| 15 |
-
|
| 16 |
-
def log_qa_entry(
|
| 17 |
-
original_question: str,
|
| 18 |
-
generated_search_query: str,
|
| 19 |
-
retrieved_context: str,
|
| 20 |
-
final_answer: str,
|
| 21 |
-
extra: dict = None
|
| 22 |
-
):
|
| 23 |
-
entry = {
|
| 24 |
-
"timestamp_utc": datetime.datetime.utcnow().isoformat() + "Z",
|
| 25 |
-
"original_question": original_question,
|
| 26 |
-
"search_query": generated_search_query,
|
| 27 |
-
"context": retrieved_context,
|
| 28 |
-
"answer": final_answer,
|
| 29 |
-
}
|
| 30 |
-
if extra:
|
| 31 |
-
entry.update(extra)
|
| 32 |
-
line = json.dumps(entry, ensure_ascii=False)
|
| 33 |
-
with _log_lock:
|
| 34 |
-
with open(LOG_PATH, "a", encoding="utf-8") as f:
|
| 35 |
-
f.write(line + "\n")
|
| 36 |
|
| 37 |
|
| 38 |
from typing import List
|
|
@@ -153,16 +124,6 @@ def process_user_queries_with_context(user_inputs: List[str]) -> List[str]:
|
|
| 153 |
contexts = get_context_for_questions(search_queries)
|
| 154 |
prompts = construct_prompts(user_inputs, contexts)
|
| 155 |
answers = generate_answers(prompts)
|
| 156 |
-
|
| 157 |
-
# Logging each triplet
|
| 158 |
-
for orig_q, search_q, context, ans in zip(user_inputs, search_queries, contexts, answers):
|
| 159 |
-
log_qa_entry(
|
| 160 |
-
original_question=orig_q,
|
| 161 |
-
generated_search_query=search_q,
|
| 162 |
-
retrieved_context=context,
|
| 163 |
-
final_answer=ans,
|
| 164 |
-
)
|
| 165 |
-
|
| 166 |
return answers
|
| 167 |
|
| 168 |
if __name__=="__main__":
|
|
|
|
| 4 |
query_gen_api_key_1, query_gen_api_key_2, query_gen_api_key_3, query_gen_api_key_4
|
| 5 |
)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
from typing import List
|
|
|
|
| 124 |
contexts = get_context_for_questions(search_queries)
|
| 125 |
prompts = construct_prompts(user_inputs, contexts)
|
| 126 |
answers = generate_answers(prompts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
return answers
|
| 128 |
|
| 129 |
if __name__=="__main__":
|
app.py
CHANGED
|
@@ -79,5 +79,5 @@ async def run_hackrx(
|
|
| 79 |
f"Response ready: path={request.url.path} method={request.method} "
|
| 80 |
f"received_at={received_at.isoformat()}Z sent_at={sent_at.isoformat()}Z duration_s={duration:.3f}"
|
| 81 |
)
|
| 82 |
-
|
| 83 |
return {"answers": answers}
|
|
|
|
| 79 |
f"Response ready: path={request.url.path} method={request.method} "
|
| 80 |
f"received_at={received_at.isoformat()}Z sent_at={sent_at.isoformat()}Z duration_s={duration:.3f}"
|
| 81 |
)
|
| 82 |
+
print(answers)
|
| 83 |
return {"answers": answers}
|