Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -15,8 +15,12 @@ from langchain_core.tools import tool
|
|
15 |
from langchain.tools.retriever import create_retriever_tool
|
16 |
from supabase.client import Client, create_client
|
17 |
from typing import TypedDict, List, Annotated
|
18 |
-
from langchain.vectorstores.chroma import Chroma
|
19 |
from langchain.agents.agent_toolkits import create_retriever_tool
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
load_dotenv()
|
22 |
|
@@ -124,25 +128,14 @@ sys_msg = SystemMessage(content=system_prompt)
|
|
124 |
|
125 |
|
126 |
def create_retriever_tool(persist_directory="vector_store"):
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
vector_store = Chroma(
|
132 |
-
embedding_function=embeddings,
|
133 |
-
persist_directory=persist_directory # Use the parameter, not hardcoded path
|
134 |
-
)
|
135 |
|
136 |
-
#
|
137 |
-
|
138 |
-
|
139 |
-
name="Question Search",
|
140 |
-
description="A tool to retrieve similar questions from a vector store.",
|
141 |
-
)
|
142 |
-
|
143 |
-
return retriever_tool, vector_store
|
144 |
-
|
145 |
-
tool, store = create_retriever_tool(persist_directory="/home/wendy/Downloads")
|
146 |
|
147 |
tools = [
|
148 |
multiply,
|
|
|
15 |
from langchain.tools.retriever import create_retriever_tool
|
16 |
from supabase.client import Client, create_client
|
17 |
from typing import TypedDict, List, Annotated
|
|
|
18 |
from langchain.agents.agent_toolkits import create_retriever_tool
|
19 |
+
from langchain_community.document_loaders import TextLoader
|
20 |
+
from langchain_community.vectorstores import FAISS
|
21 |
+
from langchain_openai import OpenAIEmbeddings
|
22 |
+
from langchain_text_splitters import CharacterTextSplitter
|
23 |
+
|
24 |
|
25 |
load_dotenv()
|
26 |
|
|
|
128 |
|
129 |
|
130 |
def create_retriever_tool(persist_directory="vector_store"):
|
131 |
+
documents = TextLoader("state_of_the_union.txt").load()
|
132 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
133 |
+
texts = text_splitter.split_documents(documents)
|
134 |
+
retriever = FAISS.from_documents(texts, OpenAIEmbeddings()).as_retriever()
|
|
|
|
|
|
|
|
|
135 |
|
136 |
+
#docs = retriever.invoke("What did the president say about Ketanji Brown Jackson")
|
137 |
+
#pretty_print_docs(docs)
|
138 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
tools = [
|
141 |
multiply,
|