Spaces:
Sleeping
Sleeping
Ankush Rana
commited on
Commit
·
a4b79b1
1
Parent(s):
0057ac1
fix bug on vector store
Browse files- requirements.txt +7 -6
- tools.py +7 -5
requirements.txt
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
gradio==5.
|
| 2 |
-
openai==1.
|
| 3 |
-
python-dotenv==1.0
|
| 4 |
-
langchain-community==0.
|
| 5 |
-
langchain-core==0.
|
| 6 |
faiss-cpu==1.10.0
|
| 7 |
-
|
|
|
|
|
|
| 1 |
+
gradio==5.23.0
|
| 2 |
+
openai==1.68.2
|
| 3 |
+
python-dotenv==1.1.0
|
| 4 |
+
langchain-community==0.3.20
|
| 5 |
+
langchain-core==0.3.48
|
| 6 |
faiss-cpu==1.10.0
|
| 7 |
+
faiss-gpu==1.7.2
|
| 8 |
+
sentence-transformers==3.4.1
|
tools.py
CHANGED
|
@@ -10,12 +10,12 @@ import random
|
|
| 10 |
import copy
|
| 11 |
from types import UnionType
|
| 12 |
|
| 13 |
-
from
|
| 14 |
-
from
|
| 15 |
|
| 16 |
class VectorStore:
|
| 17 |
def __init__(self, embeddings_model, vectorstore):
|
| 18 |
-
embeddings = HuggingFaceEmbeddings(model_name=embeddings_model
|
| 19 |
self.vectore_store = FAISS.load_local(vectorstore, embeddings, allow_dangerous_deserialization=True)
|
| 20 |
|
| 21 |
def get_context(self, instruction, number_of_contexts=2):
|
|
@@ -39,6 +39,7 @@ def read_json(data_path: str) -> tuple[list, dict]:
|
|
| 39 |
|
| 40 |
json_data = read_json("data/val_de_nuria.json")
|
| 41 |
reservations = {}
|
|
|
|
| 42 |
class ToolBase(BaseModel, ABC):
|
| 43 |
@abstractmethod
|
| 44 |
def invoke(cls, input: Dict):
|
|
@@ -108,7 +109,7 @@ class ToolBase(BaseModel, ABC):
|
|
| 108 |
|
| 109 |
tools: Dict[str, ToolBase] = {}
|
| 110 |
oitools = []
|
| 111 |
-
|
| 112 |
|
| 113 |
def tool_register(cls: BaseModel):
|
| 114 |
oaitool = cls.to_openai_tool()
|
|
@@ -128,6 +129,7 @@ The hotel features **two dining options**, serving traditional Catalan cuisine a
|
|
| 128 |
For an unforgettable stay, guests can choose from **special packages**, including family-friendly stays, romantic getaways, ski adventures, and relaxation retreats. Outdoor enthusiasts can explore **hiking trails, ski slopes, and fishing spots** in the surrounding natural beauty.
|
| 129 |
Whether for relaxation or adventure, **Nou Vall de Núria** promises a unique and memorable experience."""
|
| 130 |
|
|
|
|
| 131 |
@tool_register
|
| 132 |
class get_documents(ToolBase):
|
| 133 |
"""
|
|
@@ -142,7 +144,7 @@ class get_documents(ToolBase):
|
|
| 142 |
return "Missing required argument: query."
|
| 143 |
|
| 144 |
# return "We are currently working on it. You can't use this tool right now—please try again later. Thank you for your patience!"
|
| 145 |
-
|
| 146 |
|
| 147 |
# @tool_register
|
| 148 |
class hotel_facilities(ToolBase):
|
|
|
|
| 10 |
import copy
|
| 11 |
from types import UnionType
|
| 12 |
|
| 13 |
+
from langchain_community.vectorstores import FAISS
|
| 14 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 15 |
|
| 16 |
class VectorStore:
|
| 17 |
def __init__(self, embeddings_model, vectorstore):
|
| 18 |
+
embeddings = HuggingFaceEmbeddings(model_name=embeddings_model)
|
| 19 |
self.vectore_store = FAISS.load_local(vectorstore, embeddings, allow_dangerous_deserialization=True)
|
| 20 |
|
| 21 |
def get_context(self, instruction, number_of_contexts=2):
|
|
|
|
| 39 |
|
| 40 |
json_data = read_json("data/val_de_nuria.json")
|
| 41 |
reservations = {}
|
| 42 |
+
|
| 43 |
class ToolBase(BaseModel, ABC):
|
| 44 |
@abstractmethod
|
| 45 |
def invoke(cls, input: Dict):
|
|
|
|
| 109 |
|
| 110 |
tools: Dict[str, ToolBase] = {}
|
| 111 |
oitools = []
|
| 112 |
+
vector_store = VectorStore(embeddings_model="BAAI/bge-m3", vectorstore="data/vs")
|
| 113 |
|
| 114 |
def tool_register(cls: BaseModel):
|
| 115 |
oaitool = cls.to_openai_tool()
|
|
|
|
| 129 |
For an unforgettable stay, guests can choose from **special packages**, including family-friendly stays, romantic getaways, ski adventures, and relaxation retreats. Outdoor enthusiasts can explore **hiking trails, ski slopes, and fishing spots** in the surrounding natural beauty.
|
| 130 |
Whether for relaxation or adventure, **Nou Vall de Núria** promises a unique and memorable experience."""
|
| 131 |
|
| 132 |
+
|
| 133 |
@tool_register
|
| 134 |
class get_documents(ToolBase):
|
| 135 |
"""
|
|
|
|
| 144 |
return "Missing required argument: query."
|
| 145 |
|
| 146 |
# return "We are currently working on it. You can't use this tool right now—please try again later. Thank you for your patience!"
|
| 147 |
+
return vector_store.get_context(query)
|
| 148 |
|
| 149 |
# @tool_register
|
| 150 |
class hotel_facilities(ToolBase):
|