about summary refs log tree commit diff
path: root/gnqa/src/study2/document_operations.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /gnqa/src/study2/document_operations.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to 'gnqa/src/study2/document_operations.py')
-rw-r--r--gnqa/src/study2/document_operations.py32
1 files changed, 31 insertions, 1 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": [],