diff options
Diffstat (limited to 'gnqa/src/study2/document_operations.py')
-rw-r--r-- | gnqa/src/study2/document_operations.py | 32 |
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": [], |