(model_name)
| 19 | |
| 20 | |
| 21 | def prompt_source (model_name): |
| 22 | |
| 23 | print(f"\nExample: Parse and Filter Documents Directly in Prompt to LLM") |
| 24 | |
| 25 | # load the llmware sample files |
| 26 | print (f"\nstep 1 - loading the llmware sample files") |
| 27 | sample_files_path = Setup().load_sample_files() |
| 28 | contracts_path = os.path.join(sample_files_path,"Agreements") |
| 29 | |
| 30 | # load bling model which will be used for the inference (will run on local laptop CPU) |
| 31 | # --note: typically requires 16 GB laptop RAM |
| 32 | print (f"step 2 - loading model {model_name}") |
| 33 | |
| 34 | # create prompt object |
| 35 | prompter = Prompt() |
| 36 | prompter.load_model(model_name) |
| 37 | |
| 38 | # this is the question that we will ask to each document |
| 39 | research = {"topic": "base salary", "prompt": "What is the executive's base salary?"} |
| 40 | |
| 41 | for i, contract in enumerate(os.listdir(contracts_path)): |
| 42 | |
| 43 | # (optional) safety check to exclude Mac-specific file artifact |
| 44 | if contract != ".DS_Store": |
| 45 | |
| 46 | print("\nAnalyzing Contract - ", str( i +1), contract) |
| 47 | print("Question: ", research["prompt"]) |
| 48 | |
| 49 | # contract is parsed, text-chunked, and then filtered by "base salary' |
| 50 | # --note: query is optional - if no query, then entire document will be returned and added as source |
| 51 | source = prompter.add_source_document(contracts_path, contract, query=research["topic"]) |
| 52 | |
| 53 | # take a look at the created source |
| 54 | print("Source created from document: ", source) |
| 55 | |
| 56 | # calling the LLM with 'source' information from the contract automatically packaged into the prompt |
| 57 | responses = prompter.prompt_with_source(research["prompt"], prompt_name="default_with_context", temperature=0.3) |
| 58 | |
| 59 | for r, response in enumerate(responses): |
| 60 | print("\nLLM Response: ", response["llm_response"]) |
| 61 | |
| 62 | # We're done with this contract, clear the source from the prompt |
| 63 | # -- note: if looking to aggregate or keep 'running' source, then do not clear |
| 64 | prompter.clear_source_materials() |
| 65 | |
| 66 | return 0 |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
no test coverage detected