AI-RESEARCHER-2024 commited on
Commit
d638db5
·
verified ·
1 Parent(s): dac3b68

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chainlit as cl
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain.chains import RetrievalQA
4
+ from langchain.vectorstores import Chroma
5
+ from langchain_community.embeddings import HuggingFaceEmbeddings
6
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
7
+
8
+ llm = llm = ChatOpenAI(
9
+ api_key="ollama",
10
+ model='llama3.2',
11
+ base_url="http://localhost:11434/v1",
12
+ temperature=0
13
+ )
14
+
15
+ # Load the persisted Chroma database
16
+ persist_directory = 'mydb'
17
+ vectordb = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
18
+
19
+ # Create a retriever from the vector store
20
+ retriever = vectordb.as_retriever()
21
+
22
+ # Set up the QA chain
23
+ qa_chain = RetrievalQA.from_chain_type(llm=llm, chain_type='stuff', retriever=retriever)
24
+
25
+ # Define the Chainlit app
26
+ @cl.on_message
27
+ def main(message):
28
+ response = qa_chain.run(message.content)
29
+ cl.Message(content=response).send()