Skip to content

Commit a8a96f9

Browse files
committed
fix: revert regression due to API incompatibility
1 parent 462f271 commit a8a96f9

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

document_qa/custom_embeddings.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,24 @@ def embed(self, text: List[str]) -> List[List[float]]:
4747
# Newlines degrade embedding quality for most models
4848
cleaned_text = [t.replace("\n", " ") for t in text]
4949

50-
headers = {
51-
"Content-Type": "application/json"
52-
}
50+
payload = {'text': "\n".join(cleaned_text)}
5351

52+
headers = {}
5453
if self.api_key:
55-
headers["Authorization"] = f"Bearer {self.api_key}"
54+
headers = {'x-api-key': self.api_key}
5655

5756
response = requests.post(
58-
f"{self.url}/embeddings",
59-
json={
60-
"model": self.model_name,
61-
"input": cleaned_text
62-
},
57+
self.url,
58+
data=payload,
59+
files=[],
6360
headers=headers
6461
)
65-
6662
response.raise_for_status()
6763

68-
data = response.json()["data"]
69-
return [item["embedding"] for item in data]
64+
# print(response.text)
65+
return response.json()
7066

71-
def embed_documents(self, text: List[str]) -> List[List[float]]:
67+
def embed_documents(self, text: List[str]) -> List[List[str]]:
7268
"""Embed multiple documents (LangChain interface).
7369
7470
Args:
@@ -79,7 +75,7 @@ def embed_documents(self, text: List[str]) -> List[List[float]]:
7975
"""
8076
return self.embed(text)
8177

82-
def embed_query(self, text: str) -> List[float]:
78+
def embed_query(self, text: str) -> List[List[str]]:
8379
"""Embed a single query string (LangChain interface).
8480
8581
Args:

0 commit comments

Comments
 (0)