Spaces:
Sleeping
Sleeping
Jose-Maria Segui commited on
Commit ·
4bc4dbf
1
Parent(s): 80dc71e
Fix: Manually implement create_retriever_tool to avoid import errors
Browse files
agent.py
CHANGED
|
@@ -31,12 +31,25 @@ from langchain_huggingface import (
|
|
| 31 |
)
|
| 32 |
from langchain_community.vectorstores import SupabaseVectorStore
|
| 33 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 34 |
-
from langchain_core.tools import tool
|
| 35 |
-
from langchain.tools import create_retriever_tool
|
| 36 |
from supabase.client import Client, create_client
|
| 37 |
|
| 38 |
load_dotenv()
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
### =============== BROWSER TOOLS =============== ###
|
| 41 |
|
| 42 |
|
|
|
|
| 31 |
)
|
| 32 |
from langchain_community.vectorstores import SupabaseVectorStore
|
| 33 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 34 |
+
from langchain_core.tools import tool, Tool
|
|
|
|
| 35 |
from supabase.client import Client, create_client
|
| 36 |
|
| 37 |
load_dotenv()
|
| 38 |
|
| 39 |
+
# Manual implementation of create_retriever_tool to avoid import errors
|
| 40 |
+
def create_retriever_tool(retriever, name: str, description: str) -> Tool:
|
| 41 |
+
"""Create a tool to do retrieval."""
|
| 42 |
+
def retrieve(query: str):
|
| 43 |
+
# Depending on version invoke might return documents directly
|
| 44 |
+
docs = retriever.invoke(query)
|
| 45 |
+
return "\n\n".join([d.page_content for d in docs])
|
| 46 |
+
|
| 47 |
+
return Tool(
|
| 48 |
+
name=name,
|
| 49 |
+
description=description,
|
| 50 |
+
func=retrieve,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
### =============== BROWSER TOOLS =============== ###
|
| 54 |
|
| 55 |
|