MCPcopy
hub / github.com/llmware-ai/llmware / msa_processing

Function msa_processing

solutions/use_cases/msa_processing.py:22–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22def msa_processing():
23
24 local_path = Setup().load_sample_files()
25 agreements_path = os.path.join(local_path, "AgreementsLarge")
26
27 # create a library with all of the Agreements (~80 contracts)
28 msa_lib = Library().create_new_library("msa_lib503_635")
29 msa_lib.add_files(agreements_path)
30
31 # find the "master service agreements" (MSA)
32 q = Query(msa_lib)
33 query = "master services agreement"
34 results = q.text_search_by_page(query, page_num=1, results_only=False)
35
36 # results_only = False will return a dictionary with 4 keys: {"query", "results", "doc_ID", "file_source"}
37 msa_docs = results["file_source"]
38
39 # load prompt/llm locally
40 model_name = "llmware/dragon-yi-6b-gguf"
41 prompter = Prompt().load_model(model_name)
42
43 # analyze each MSA - "query" & "llm prompt"
44 for i, docs in enumerate(msa_docs):
45
46 print("\n")
47 print (i+1, "Reviewing MSA - ", docs)
48
49 # look for the termination provisions in each document
50 doc_filter = {"file_source": [docs]}
51 termination_provisions = q.text_query_with_document_filter("termination", doc_filter)
52
53 # package the provisions as a source to a prompt
54 sources = prompter.add_source_query_results(termination_provisions)
55
56 print("update: sources - ", sources)
57
58 # call the LLM and ask our question
59 response = prompter.prompt_with_source("What is the notice for termination for convenience?")
60
61 # post processing fact checking
62 stats = prompter.evidence_comparison_stats(response)
63 ev_source = prompter.evidence_check_sources(response)
64
65 for i, resp in enumerate(response):
66 print("update: llm response - ", resp)
67 print("update: compare with evidence- ", stats[i]["comparison_stats"])
68 print("update: sources - ", ev_source[i]["source_review"])
69
70 prompter.clear_source_materials()
71
72 # Save jsonl report with full transaction history to /prompt_history folder
73 print("\nupdate: prompt state saved at: ", os.path.join(LLMWareConfig.get_prompt_path(),prompter.prompt_id))
74
75 prompter.save_state()
76
77 # Generate CSV report for easy Human review in Excel
78 csv_output = HumanInTheLoop(prompter).export_current_interaction_to_csv()
79

Callers 1

msa_processing.pyFile · 0.70

Calls 15

text_search_by_pageMethod · 0.95
SetupClass · 0.90
LibraryClass · 0.90
QueryClass · 0.90
PromptClass · 0.90
HumanInTheLoopClass · 0.90
load_sample_filesMethod · 0.80
create_new_libraryMethod · 0.80
add_filesMethod · 0.80
prompt_with_sourceMethod · 0.80

Tested by

no test coverage detected