aboutsummaryrefslogtreecommitdiff
path: root/gnqa/src/study2
diff options
context:
space:
mode:
Diffstat (limited to 'gnqa/src/study2')
-rw-r--r--gnqa/src/study2/document_operations.py32
-rw-r--r--gnqa/src/study2/run_questions.py19
2 files changed, 42 insertions, 9 deletions
diff --git a/gnqa/src/study2/document_operations.py b/gnqa/src/study2/document_operations.py
index 3112d915..f8ffdefe 100644
--- a/gnqa/src/study2/document_operations.py
+++ b/gnqa/src/study2/document_operations.py
@@ -1,6 +1,8 @@
import os
-#import sys
+import sys
import json
+#import inspect
+from r2r import RAGResponse
#import time
#import configparser
'''
@@ -37,6 +39,7 @@ class DocOps:
def writeDatasetFile(responses, outp_file):
print(outp_file)
output = json.dumps(responses, indent=2)
+
if os.path.exists(outp_file):
with open(outp_file, "a") as the_data:
the_data.write('\n\n' + output)
@@ -44,6 +47,33 @@ class DocOps:
with open(outp_file, "a") as the_data:
the_data.write(output)
+ def jsonifyRAGResponse(resps):
+ for resp in resps:
+ print("Num citations {0}\nAnswer --> {1}\n\t{2}".format(
+ len(resp.citations),
+ resp.generated_answer,
+ resp.metadata))
+
+ def writeRAGResponses(resps, outp_file):
+ print(outp_file)
+ for ndx in resps:
+ resp = resps[ndx]
+ #methods = [attr for attr in dir(obj) if not attr.startswith('_')] # Exclude private methods
+ #print(methods)
+ output = resp.model_dump()
+ output_to_write = resp.model_dump_json()
+ print("The answer --> {0}\nID --> {1}".format(
+ output["results"]["generated_answer"],
+ output["results"]["metadata"]["id"]))
+ if os.path.exists(outp_file):
+ with open(outp_file, "a") as the_data:
+ the_data.write('\n\n' + output_to_write)
+ else:
+ with open(outp_file, "a") as the_data:
+ the_data.write(output_to_write)
+
+
+
def get_r2r_ragas_out_dict():
return { "titles": [],
"extraction_id": [],
diff --git a/gnqa/src/study2/run_questions.py b/gnqa/src/study2/run_questions.py
index 07aee5f0..9bac5a23 100644
--- a/gnqa/src/study2/run_questions.py
+++ b/gnqa/src/study2/run_questions.py
@@ -2,17 +2,19 @@ import json
import sys
import os
-from r2r import R2RClient
-from study2.document_operations import DocOps, QuestionList
+from r2r import R2RClient, RAGResponse
+from document_operations import DocOps, QuestionList
'''
*******************************************************************************
Variables
*******************************************************************************
'''
+rag_gen_cfg = {"model": "openai/gpt-4o-mini", "temperature": 0.0, "use_hybrid_search": True}
rag_response = {}
-client = R2RClient("http://localhost:8000")
-health_resp = client.health()
+#client = R2RClient("http://localhost:8000")
+client = R2RClient("http://localhost:7272")
+#health_resp = client.health()
'''
*******************************************************************************
@@ -20,19 +22,20 @@ Commands
*******************************************************************************
'''
-print("The R2R client's health status is {0}".format(health_resp))
+#print("The R2R client's health status is {0}".format(health_resp))
try:
read_file = str(sys.argv[1])
out_file = str(sys.argv[2])
except:
- exit('Example use "python run_questions.py ../data/questions/human/de/aging.json ../data/responses/human/de/aging_resp.json"')
+ exit('Example use "python run_questions.py ../../data/study2/lists/human-questions.json ../../data/test_study/human/de/aging_resp.json"')
qLst = QuestionList(read_file, 1) # second parameter is for verbose output
ndx = 1
for question in qLst.get("domainexpert","aging"):
print('Getting response for the following question --> {0}'.format(question))
- rag_response[str(ndx)] = client.rag(question)
+ #rag_response[str(ndx)] = client.rag(question)
+ rag_response[str(ndx)] = client.retrieval.rag(question, rag_gen_cfg)
ndx += 1
-DocOps.writeDatasetFile(rag_response, out_file) \ No newline at end of file
+DocOps.writeRAGResponses(rag_response, out_file) \ No newline at end of file