Update as per the feedback.
- moved args parser inside main - assigned empty list to docs. - Updated README.md.
This commit is contained in:
		
							parent
							
								
									9fb7f07e3c
								
							
						
					
					
						commit
						f8805c80f8
					
				
							
								
								
									
										20
									
								
								README.md
								
								
								
								
							
							
						
						
									
										20
									
								
								README.md
								
								
								
								
							|  | @ -83,25 +83,7 @@ Type `exit` to finish the script. | |||
| 
 | ||||
| 
 | ||||
| ### Script Arguments | ||||
| The script also supports optional command-line arguments to modify its behavior: | ||||
| 
 | ||||
| - `--hide-source` or `-S`: Use this flag to disable printing of the source documents used for answers. By default, the source documents are printed. | ||||
|    | ||||
| ```shell | ||||
| python privateGPT.py --hide-source | ||||
| ``` | ||||
| 
 | ||||
| - `--mute-stream` or `-M`: Use this flag to disable LLM standard output streaming response, which by default prints progress to the console. | ||||
| 
 | ||||
| ```shell | ||||
| python privateGPT.py --mute-stream | ||||
| ``` | ||||
| 
 | ||||
| You can combine these options if needed: | ||||
| 
 | ||||
| ```shell | ||||
| python privateGPT.py --hide-source --mute-callback | ||||
| ``` | ||||
| The script also supports optional command-line arguments to modify its behavior. You can see a full list of these arguments by running the command ```python privateGPT.py --help``` in your terminal | ||||
| 
 | ||||
| 
 | ||||
| # How does it work? | ||||
|  |  | |||
|  | @ -18,12 +18,14 @@ model_n_ctx = os.environ.get('MODEL_N_CTX') | |||
| 
 | ||||
| from constants import CHROMA_SETTINGS | ||||
| 
 | ||||
| def main(hide_source=False, mute_stream=False): | ||||
| def main(): | ||||
|     # Parse the command line arguments | ||||
|     args = parse_arguments() | ||||
|     embeddings = HuggingFaceEmbeddings(model_name=embeddings_model_name) | ||||
|     db = Chroma(persist_directory=persist_directory, embedding_function=embeddings, client_settings=CHROMA_SETTINGS) | ||||
|     retriever = db.as_retriever() | ||||
|     # activate/deactivate the streaming StdOut callback for LLMs | ||||
|     callbacks = [] if mute_stream else [StreamingStdOutCallbackHandler()] | ||||
|     callbacks = [] if args.mute_stream else [StreamingStdOutCallbackHandler()] | ||||
|     # Prepare the LLM | ||||
|     match model_type: | ||||
|         case "LlamaCpp": | ||||
|  | @ -33,7 +35,7 @@ def main(hide_source=False, mute_stream=False): | |||
|         case _default: | ||||
|             print(f"Model {model_type} not supported!") | ||||
|             exit; | ||||
|     qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents= not hide_source) | ||||
|     qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents= not args.hide_source) | ||||
|     # Interactive questions and answers | ||||
|     while True: | ||||
|         query = input("\nEnter a query: ") | ||||
|  | @ -42,7 +44,7 @@ def main(hide_source=False, mute_stream=False): | |||
| 
 | ||||
|         # Get the answer from the chain | ||||
|         res = qa(query) | ||||
|         answer, docs = res['result'], None if hide_source else res['source_documents'] | ||||
|         answer, docs = res['result'], [] if args.hide_source else res['source_documents'] | ||||
| 
 | ||||
|         # Print the result | ||||
|         print("\n\n> Question:") | ||||
|  | @ -50,14 +52,14 @@ def main(hide_source=False, mute_stream=False): | |||
|         print("\n> Answer:") | ||||
|         print(answer) | ||||
| 
 | ||||
|         # Print the relevant sources used for the answer, if source is True | ||||
|         if not hide_source and docs: | ||||
|             for document in docs: | ||||
|                 print("\n> " + document.metadata["source"] + ":") | ||||
|                 print(document.page_content) | ||||
|         # Print the relevant sources used for the answer | ||||
|         for document in docs: | ||||
|             print("\n> " + document.metadata["source"] + ":") | ||||
|             print(document.page_content) | ||||
| 
 | ||||
| def parse_arguments(): | ||||
|     parser = argparse.ArgumentParser() | ||||
|     parser = argparse.ArgumentParser(description='privateGPT: Ask questions to your documents without an internet connection, ' | ||||
|                                                  'using the power of LLMs.') | ||||
|     parser.add_argument("--hide-source", "-S", action='store_true', | ||||
|                         help='Use this flag to disable printing of source documents used for answers.') | ||||
| 
 | ||||
|  | @ -69,6 +71,4 @@ def parse_arguments(): | |||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     # Parse the command line arguments | ||||
|     args = parse_arguments() | ||||
|     main(hide_source=args.hide_source, mute_stream=args.mute_stream) | ||||
|     main() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue