Spaces:
Build error
Build error
load faiss from azure blb storage
Browse files- agent/test.ipynb +30 -0
- app.py +3 -3
agent/test.ipynb
CHANGED
|
@@ -191,6 +191,36 @@
|
|
| 191 |
"vector_info = str(chunk_size) + \"-\" + tokenizer_name.replace(\"/\",\"-\") + \"-\" + datetime.now().date().isoformat()\n",
|
| 192 |
"KNOWLEDGE_VECTOR_DATABASE.save_local(\"../data/FAISS/{vector_info}\")\n"
|
| 193 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
}
|
| 195 |
],
|
| 196 |
"metadata": {
|
|
|
|
| 191 |
"vector_info = str(chunk_size) + \"-\" + tokenizer_name.replace(\"/\",\"-\") + \"-\" + datetime.now().date().isoformat()\n",
|
| 192 |
"KNOWLEDGE_VECTOR_DATABASE.save_local(\"../data/FAISS/{vector_info}\")\n"
|
| 193 |
]
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"cell_type": "code",
|
| 197 |
+
"execution_count": 1,
|
| 198 |
+
"id": "406da007",
|
| 199 |
+
"metadata": {},
|
| 200 |
+
"outputs": [],
|
| 201 |
+
"source": [
|
| 202 |
+
"import os\n",
|
| 203 |
+
"from azure.storage.blob import BlobServiceClient\n",
|
| 204 |
+
"from langchain_community.vectorstores import FAISS\n",
|
| 205 |
+
"\n",
|
| 206 |
+
"\n",
|
| 207 |
+
"def load_from_azure(container_name, local_dir=\"./index\"):\n",
|
| 208 |
+
" connection_string = os.environ[\"AZURE_CONN_STR\"]\n",
|
| 209 |
+
" blob_service_client = BlobServiceClient.from_connection_string(connection_string)\n",
|
| 210 |
+
" container_client = blob_service_client.get_container_client(container_name)\n",
|
| 211 |
+
"\n",
|
| 212 |
+
" os.makedirs(local_dir, exist_ok=True)\n",
|
| 213 |
+
" \n",
|
| 214 |
+
" # Download all files in the container (index.faiss and index.pkl)\n",
|
| 215 |
+
" blobs = container_client.list_blobs()\n",
|
| 216 |
+
" for blob in blobs:\n",
|
| 217 |
+
" download_file_path = os.path.join(local_dir, blob.name)\n",
|
| 218 |
+
" with open(download_file_path, \"wb\") as file:\n",
|
| 219 |
+
" file.write(container_client.download_blob(blob).readall())\n",
|
| 220 |
+
"\n",
|
| 221 |
+
"# Download files from Azure\n",
|
| 222 |
+
"load_from_azure(\"blobcontaineravatarbot\")"
|
| 223 |
+
]
|
| 224 |
}
|
| 225 |
],
|
| 226 |
"metadata": {
|
app.py
CHANGED
|
@@ -32,10 +32,10 @@ def load_from_azure(container_name, local_dir="./index"):
|
|
| 32 |
with open(download_file_path, "wb") as file:
|
| 33 |
file.write(container_client.download_blob(blob).readall())
|
| 34 |
|
| 35 |
-
#
|
| 36 |
load_from_azure("blobcontaineravatarbot")
|
| 37 |
|
| 38 |
-
#
|
| 39 |
embeddings="intfloat/e5-base-v2"
|
| 40 |
vectorstore = FAISS.load_local("./index", embeddings, allow_dangerous_deserialization=True)
|
| 41 |
|
|
@@ -48,7 +48,7 @@ from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
|
|
| 48 |
from langchain.chat_models import init_chat_model
|
| 49 |
|
| 50 |
|
| 51 |
-
def predict(message, history,request: gr.Request):
|
| 52 |
|
| 53 |
# Get client IP and check rate limit
|
| 54 |
client_ip = request.client.host
|
|
|
|
| 32 |
with open(download_file_path, "wb") as file:
|
| 33 |
file.write(container_client.download_blob(blob).readall())
|
| 34 |
|
| 35 |
+
# Download files from Azure
|
| 36 |
load_from_azure("blobcontaineravatarbot")
|
| 37 |
|
| 38 |
+
# Load into FAISS
|
| 39 |
embeddings="intfloat/e5-base-v2"
|
| 40 |
vectorstore = FAISS.load_local("./index", embeddings, allow_dangerous_deserialization=True)
|
| 41 |
|
|
|
|
| 48 |
from langchain.chat_models import init_chat_model
|
| 49 |
|
| 50 |
|
| 51 |
+
def predict(message, history, request: gr.Request):
|
| 52 |
|
| 53 |
# Get client IP and check rate limit
|
| 54 |
client_ip = request.client.host
|