-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
27 lines (23 loc) · 803 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import openai
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
from time import sleep
def main():
#Initialize openAI key
openai.api_key = os.getenv("OPENAI_API_KEY")
#Load db
embedding_function = OpenAIEmbeddings()
db=Chroma(persist_directory="knowledge/", embedding_function=embedding_function)
#Ask your questions:
qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=db.as_retriever())
while True:
query=input('Enter your query and press enter. Press Ctrl+C to exit.\n\n')
response=qa.run(query)
print(response)
print('\n')
sleep.(1)
if __name__ == '__main__':
main()