IlyasMoutawwakil HF staff commited on
Commit
4ccb857
β€’
1 Parent(s): 634de42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -85,6 +85,10 @@ def method_timer(method):
85
  class InferenceEndpointTextEmbedder:
86
  @component.output_types(embedding=List[float])
87
  def run(self, text: str):
 
 
 
 
88
  payload = {"text": text, "inputs": ""}
89
  response = post(EMBEDDER_URL, payload)
90
 
@@ -98,6 +102,10 @@ class InferenceEndpointTextEmbedder:
98
  class InferenceEndpointDocumentEmbedder:
99
  @component.output_types(documents=List[Document])
100
  def run(self, documents: List[Document]):
 
 
 
 
101
  documents = [d.to_dict() for d in documents]
102
 
103
  payload = {"documents": documents, "inputs": ""}
@@ -116,6 +124,10 @@ class InferenceEndpointRanker:
116
 
117
  @component.output_types(documents=List[Document])
118
  def run(self, query: str, documents: List[Document]):
 
 
 
 
119
  documents = [d.to_dict() for d in documents]
120
 
121
  payload = {
@@ -145,9 +157,8 @@ if os.path.exists("data/qdrant"):
145
  except Exception:
146
  shutil.rmtree("data/qdrant", ignore_errors=True)
147
 
148
- if document_store is None:
149
- shutil.rmtree("data/qdrant", ignore_errors=True)
150
 
 
151
  document_store = QdrantDocumentStore(
152
  path="./data/qdrant",
153
  return_embedding=True,
 
85
  class InferenceEndpointTextEmbedder:
86
  @component.output_types(embedding=List[float])
87
  def run(self, text: str):
88
+ return self.request(text)
89
+
90
+ @method_timer
91
+ def request(self, text: str):
92
  payload = {"text": text, "inputs": ""}
93
  response = post(EMBEDDER_URL, payload)
94
 
 
102
  class InferenceEndpointDocumentEmbedder:
103
  @component.output_types(documents=List[Document])
104
  def run(self, documents: List[Document]):
105
+ return self.request(documents)
106
+
107
+ @method_timer
108
+ def request(self, documents: List[Document]):
109
  documents = [d.to_dict() for d in documents]
110
 
111
  payload = {"documents": documents, "inputs": ""}
 
124
 
125
  @component.output_types(documents=List[Document])
126
  def run(self, query: str, documents: List[Document]):
127
+ return self.request(query, documents)
128
+
129
+ @method_timer
130
+ def request(self, query: str, documents: List[Document]):
131
  documents = [d.to_dict() for d in documents]
132
 
133
  payload = {
 
157
  except Exception:
158
  shutil.rmtree("data/qdrant", ignore_errors=True)
159
 
 
 
160
 
161
+ if document_store is None:
162
  document_store = QdrantDocumentStore(
163
  path="./data/qdrant",
164
  return_embedding=True,