Update app/llm.py
Browse files- app/llm.py +17 -9
app/llm.py
CHANGED
|
@@ -17,15 +17,23 @@ from langchain_chroma import Chroma
|
|
| 17 |
from langchain_community.embeddings import GPT4AllEmbeddings
|
| 18 |
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
|
|
|
|
| 17 |
from langchain_community.embeddings import GPT4AllEmbeddings
|
| 18 |
|
| 19 |
|
| 20 |
+
class RagChat:
|
| 21 |
+
def agent(self):
|
| 22 |
+
loader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/")
|
| 23 |
+
data = loader.load()
|
| 24 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
|
| 25 |
+
all_splits = text_splitter.split_documents(data)
|
| 26 |
+
return all_splits
|
| 27 |
+
|
| 28 |
+
def download_embedding(self):
|
| 29 |
+
vectorstore = Chroma.from_documents(documents=self.agent, embedding=GPT4AllEmbeddings())
|
| 30 |
+
return vectorstore
|
| 31 |
+
|
| 32 |
+
def search(self, question):
|
| 33 |
+
docs = vectorstore.similarity_search(question)
|
| 34 |
+
return len(docs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
|
| 38 |
|
| 39 |
|