Tonic commited on
Commit
d4989bb
1 Parent(s): 0081daf

try a different method to fix the pickle object

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -110,14 +110,19 @@ class EmbeddingGenerator:
110
  matches = pattern.findall(metadata_output)
111
  metadata = {key: value for key, value in matches}
112
  return metadata
113
-
114
 
115
  class MyEmbeddingFunction(EmbeddingFunction):
116
  def __init__(self, model_name: str, token: str, intention_client):
117
- self.embedding_generator = EmbeddingGenerator(model_name, token, intention_client)
 
 
 
 
 
118
 
119
  def __call__(self, input: Documents) -> (Embeddings, list):
120
- embeddings_with_metadata = [self.embedding_generator.compute_embeddings(doc.page_content) for doc in input]
 
121
  embeddings = [item[0] for item in embeddings_with_metadata]
122
  metadata = [item[1] for item in embeddings_with_metadata]
123
  embeddings_flattened = [emb for sublist in embeddings for emb in sublist]
 
110
  matches = pattern.findall(metadata_output)
111
  metadata = {key: value for key, value in matches}
112
  return metadata
 
113
 
114
  class MyEmbeddingFunction(EmbeddingFunction):
115
  def __init__(self, model_name: str, token: str, intention_client):
116
+ self.model_name = model_name
117
+ self.token = token
118
+ self.intention_client = intention_client
119
+
120
+ def create_embedding_generator(self):
121
+ return EmbeddingGenerator(self.model_name, self.token, self.intention_client)
122
 
123
  def __call__(self, input: Documents) -> (Embeddings, list):
124
+ embedding_generator = self.create_embedding_generator()
125
+ embeddings_with_metadata = [embedding_generator.compute_embeddings(doc.page_content) for doc in input]
126
  embeddings = [item[0] for item in embeddings_with_metadata]
127
  metadata = [item[1] for item in embeddings_with_metadata]
128
  embeddings_flattened = [emb for sublist in embeddings for emb in sublist]