Merge branch 'abhiruka-main'
This commit is contained in:
		
						commit
						fc50eb1b89
					
				|  | @ -81,6 +81,11 @@ Note: you could turn off your internet connection, and the script inference woul | ||||||
| 
 | 
 | ||||||
| Type `exit` to finish the script. | Type `exit` to finish the script. | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | ### Script Arguments | ||||||
|  | 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? | # How does it work? | ||||||
| Selecting the right local models and the power of `LangChain` you can run the entire pipeline locally, without any data leaving your environment, and with reasonable performance. | Selecting the right local models and the power of `LangChain` you can run the entire pipeline locally, without any data leaving your environment, and with reasonable performance. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler | ||||||
| from langchain.vectorstores import Chroma | from langchain.vectorstores import Chroma | ||||||
| from langchain.llms import GPT4All, LlamaCpp | from langchain.llms import GPT4All, LlamaCpp | ||||||
| import os | import os | ||||||
|  | import argparse | ||||||
| 
 | 
 | ||||||
| load_dotenv() | load_dotenv() | ||||||
| 
 | 
 | ||||||
|  | @ -19,11 +20,14 @@ model_n_ctx = os.environ.get('MODEL_N_CTX') | ||||||
| from constants import CHROMA_SETTINGS | from constants import CHROMA_SETTINGS | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|  |     # Parse the command line arguments | ||||||
|  |     args = parse_arguments() | ||||||
|     embeddings = HuggingFaceEmbeddings(model_name=embeddings_model_name) |     embeddings = HuggingFaceEmbeddings(model_name=embeddings_model_name) | ||||||
|     db = Chroma(persist_directory=persist_directory, embedding_function=embeddings, client_settings=CHROMA_SETTINGS) |     db = Chroma(persist_directory=persist_directory, embedding_function=embeddings, client_settings=CHROMA_SETTINGS) | ||||||
|     retriever = db.as_retriever() |     retriever = db.as_retriever() | ||||||
|  |     # activate/deactivate the streaming StdOut callback for LLMs | ||||||
|  |     callbacks = [] if args.mute_stream else [StreamingStdOutCallbackHandler()] | ||||||
|     # Prepare the LLM |     # Prepare the LLM | ||||||
|     callbacks = [StreamingStdOutCallbackHandler()] |  | ||||||
|     match model_type: |     match model_type: | ||||||
|         case "LlamaCpp": |         case "LlamaCpp": | ||||||
|             llm = LlamaCpp(model_path=model_path, n_ctx=model_n_ctx, callbacks=callbacks, verbose=False) |             llm = LlamaCpp(model_path=model_path, n_ctx=model_n_ctx, callbacks=callbacks, verbose=False) | ||||||
|  | @ -32,7 +36,7 @@ def main(): | ||||||
|         case _default: |         case _default: | ||||||
|             print(f"Model {model_type} not supported!") |             print(f"Model {model_type} not supported!") | ||||||
|             exit; |             exit; | ||||||
|     qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True) |     qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents= not args.hide_source) | ||||||
|     # Interactive questions and answers |     # Interactive questions and answers | ||||||
|     while True: |     while True: | ||||||
|         query = input("\nEnter a query: ") |         query = input("\nEnter a query: ") | ||||||
|  | @ -41,7 +45,7 @@ def main(): | ||||||
| 
 | 
 | ||||||
|         # Get the answer from the chain |         # Get the answer from the chain | ||||||
|         res = qa(query) |         res = qa(query) | ||||||
|         answer, docs = res['result'], res['source_documents'] |         answer, docs = res['result'], [] if args.hide_source else res['source_documents'] | ||||||
| 
 | 
 | ||||||
|         # Print the result |         # Print the result | ||||||
|         print("\n\n> Question:") |         print("\n\n> Question:") | ||||||
|  | @ -54,5 +58,18 @@ def main(): | ||||||
|             print("\n> " + document.metadata["source"] + ":") |             print("\n> " + document.metadata["source"] + ":") | ||||||
|             print(document.page_content) |             print(document.page_content) | ||||||
| 
 | 
 | ||||||
|  | def parse_arguments(): | ||||||
|  |     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.') | ||||||
|  | 
 | ||||||
|  |     parser.add_argument("--mute-stream", "-M", | ||||||
|  |                         action='store_true', | ||||||
|  |                         help='Use this flag to disable the streaming StdOut callback for LLMs.') | ||||||
|  | 
 | ||||||
|  |     return parser.parse_args() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     main() |     main() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue