-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapp.py
53 lines (40 loc) · 1.26 KB
/
app.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from dotenv import load_dotenv
import streamlit as st
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
from langchain.vectorstores import Qdrant
from langchain.embeddings.openai import OpenAIEmbeddings
import qdrant_client
import os
def get_vector_store():
client = qdrant_client.QdrantClient(
os.getenv("QDRANT_HOST"),
api_key=os.getenv("QDRANT_API_KEY")
)
embeddings = OpenAIEmbeddings()
vector_store = Qdrant(
client=client,
collection_name=os.getenv("QDRANT_COLLECTION_NAME"),
embeddings=embeddings,
)
return vector_store
def main():
load_dotenv()
st.set_page_config(page_title="Ask Qdrant")
st.header("Ask your remote database 💬")
# create vector store
vector_store = get_vector_store()
# create chain
qa = RetrievalQA.from_chain_type(
llm=OpenAI(),
chain_type="stuff",
retriever=vector_store.as_retriever()
)
# show user input
user_question = st.text_input("Ask a question about your PDF:")
if user_question:
st.write(f"Question: {user_question}")
answer = qa.run(user_question)
st.write(f"Answer: {answer}")
if __name__ == '__main__':
main()