19 lines
741 B
Python
19 lines
741 B
Python
import requests
|
|
|
|
class EmbeddedClient:
|
|
def __init__(self, authorization: str, url: str = "https://openrouter.ai/api/v1/embeddings", model: str = "qwen/qwen3-embedding-8b") -> None:
|
|
self.url = url
|
|
self.authorization = authorization
|
|
self.model = model
|
|
|
|
def embed(self, text: str) -> list[float]:
|
|
print(f"Embedding text {text}...")
|
|
response = requests.post(
|
|
f"{self.url}",
|
|
headers={"Authorization": self.authorization, "Content-Type": "application/json"},
|
|
json={"input": text, "model": self.model},
|
|
timeout=60
|
|
)
|
|
response.raise_for_status()
|
|
embedding = response.json()["data"][0]["embedding"]
|
|
return embedding |