Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -115,8 +115,9 @@ class Chatbot():
|
|
115 |
print('Calculating embeddings')
|
116 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
117 |
embedding_model = "text-embedding-ada-002"
|
118 |
-
#
|
119 |
-
embeddings =
|
|
|
120 |
return embeddings
|
121 |
|
122 |
def search_embeddings(self, embeddings, df, query, n=3, pprint=True):
|
@@ -126,6 +127,7 @@ class Chatbot():
|
|
126 |
query,
|
127 |
engine="text-embedding-ada-002"
|
128 |
)
|
|
|
129 |
# Step 2. Create a FAISS index and add the embeddings
|
130 |
d = embeddings.shape[1]
|
131 |
# Use the L2 distance metric
|
|
|
115 |
print('Calculating embeddings')
|
116 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
117 |
embedding_model = "text-embedding-ada-002"
|
118 |
+
# Get the embeddings for each text element in the dataframe
|
119 |
+
embeddings = df.text.apply([lambda x: get_embedding(x, engine=embedding_model)])
|
120 |
+
embeddings = np.array(embeddings, dtype=np.float32)
|
121 |
return embeddings
|
122 |
|
123 |
def search_embeddings(self, embeddings, df, query, n=3, pprint=True):
|
|
|
127 |
query,
|
128 |
engine="text-embedding-ada-002"
|
129 |
)
|
130 |
+
query_embedding = np.array(query_embedding, dtype=np.float32)
|
131 |
# Step 2. Create a FAISS index and add the embeddings
|
132 |
d = embeddings.shape[1]
|
133 |
# Use the L2 distance metric
|