lfoppiano commited on
Commit
0a79409
·
verified ·
1 Parent(s): 667de45

Upload folder using huggingface_hub

Browse files
document_qa/custom_embeddings.py CHANGED
@@ -47,28 +47,24 @@ class ModalEmbeddings(Embeddings):
47
  # Newlines degrade embedding quality for most models
48
  cleaned_text = [t.replace("\n", " ") for t in text]
49
 
50
- headers = {
51
- "Content-Type": "application/json"
52
- }
53
 
 
54
  if self.api_key:
55
- headers["Authorization"] = f"Bearer {self.api_key}"
56
 
57
  response = requests.post(
58
- f"{self.url}/embeddings",
59
- json={
60
- "model": self.model_name,
61
- "input": cleaned_text
62
- },
63
  headers=headers
64
  )
65
-
66
  response.raise_for_status()
67
 
68
- data = response.json()["data"]
69
- return [item["embedding"] for item in data]
70
 
71
- def embed_documents(self, text: List[str]) -> List[List[float]]:
72
  """Embed multiple documents (LangChain interface).
73
 
74
  Args:
@@ -79,7 +75,7 @@ class ModalEmbeddings(Embeddings):
79
  """
80
  return self.embed(text)
81
 
82
- def embed_query(self, text: str) -> List[float]:
83
  """Embed a single query string (LangChain interface).
84
 
85
  Args:
 
47
  # Newlines degrade embedding quality for most models
48
  cleaned_text = [t.replace("\n", " ") for t in text]
49
 
50
+ payload = {'text': "\n".join(cleaned_text)}
 
 
51
 
52
+ headers = {}
53
  if self.api_key:
54
+ headers = {'x-api-key': self.api_key}
55
 
56
  response = requests.post(
57
+ self.url,
58
+ data=payload,
59
+ files=[],
 
 
60
  headers=headers
61
  )
 
62
  response.raise_for_status()
63
 
64
+ # print(response.text)
65
+ return response.json()
66
 
67
+ def embed_documents(self, text: List[str]) -> List[List[str]]:
68
  """Embed multiple documents (LangChain interface).
69
 
70
  Args:
 
75
  """
76
  return self.embed(text)
77
 
78
+ def embed_query(self, text: str) -> List[List[str]]:
79
  """Embed a single query string (LangChain interface).
80
 
81
  Args:
document_qa/grobid_processors.py CHANGED
@@ -194,10 +194,14 @@ class GrobidProcessor(BaseProcessor):
194
  raise GrobidServiceError("Grobid service did not respond.") from exc
195
 
196
  if status != 200:
197
- raise GrobidServiceError(
198
- f"Grobid service returned status {status}.",
199
- status_code=status
200
- )
 
 
 
 
201
 
202
  # Grobid can answer 200 with an empty body (e.g. it gave up on the PDF).
203
  if not text or not text.strip():
 
194
  raise GrobidServiceError("Grobid service did not respond.") from exc
195
 
196
  if status != 200:
197
+ # Grobid attaches a human-readable reason to error responses
198
+ # (e.g. a 500 body explaining what went wrong). Surface it
199
+ # alongside the status code instead of discarding it.
200
+ reason = text.strip() if text else ""
201
+ message = f"Grobid service returned status {status}."
202
+ if reason:
203
+ message += f" {reason}"
204
+ raise GrobidServiceError(message, status_code=status)
205
 
206
  # Grobid can answer 200 with an empty body (e.g. it gave up on the PDF).
207
  if not text or not text.strip():