Spaces:
Running
Running
daniel.diaz
commited on
Commit
·
07d48e9
1
Parent(s):
1a2949f
Cambio para error
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import faiss
|
|
6 |
import os
|
7 |
from openai import OpenAI
|
8 |
|
9 |
-
# Initialize OpenAI client using custom
|
10 |
client = OpenAI(api_key=os.getenv("POCJujitsu"))
|
11 |
|
12 |
# Load serialized FAISS index and document chunks
|
@@ -20,10 +20,14 @@ def embed_query(text):
|
|
20 |
)
|
21 |
return np.array(response.data[0].embedding, dtype=np.float32).reshape(1, -1)
|
22 |
|
23 |
-
# Semantic search using FAISS
|
24 |
def search(query, k=3):
|
25 |
query_vec = embed_query(query).astype(np.float32)
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
return [chunks[i] for i in labels[0]]
|
28 |
|
29 |
# Chat modes
|
|
|
6 |
import os
|
7 |
from openai import OpenAI
|
8 |
|
9 |
+
# Initialize OpenAI client using custom Hugging Face secret
|
10 |
client = OpenAI(api_key=os.getenv("POCJujitsu"))
|
11 |
|
12 |
# Load serialized FAISS index and document chunks
|
|
|
20 |
)
|
21 |
return np.array(response.data[0].embedding, dtype=np.float32).reshape(1, -1)
|
22 |
|
23 |
+
# Semantic search using FAISS (for older FAISS versions)
|
24 |
def search(query, k=3):
|
25 |
query_vec = embed_query(query).astype(np.float32)
|
26 |
+
|
27 |
+
distances = np.empty((1, k), dtype=np.float32)
|
28 |
+
labels = np.empty((1, k), dtype=np.int64)
|
29 |
+
|
30 |
+
index.search(query_vec, k, distances, labels)
|
31 |
return [chunks[i] for i in labels[0]]
|
32 |
|
33 |
# Chat modes
|