Spaces:
Sleeping
Sleeping
Update api/openrouter.py
Browse files- api/openrouter.py +5 -3
api/openrouter.py
CHANGED
|
@@ -10,8 +10,8 @@ class OpenRouterClient:
|
|
| 10 |
self.headers = {
|
| 11 |
"Authorization": f"Bearer {self.api_key}",
|
| 12 |
"Content-Type": "application/json",
|
| 13 |
-
"HTTP-Referer": "https://huggingface.co/spaces",
|
| 14 |
-
"X-Title": "OpenRouter AI Hub"
|
| 15 |
}
|
| 16 |
|
| 17 |
def chat_completion(
|
|
@@ -44,6 +44,7 @@ class OpenRouterClient:
|
|
| 44 |
f"{self.base_url}/chat/completions",
|
| 45 |
headers=self.headers,
|
| 46 |
data=json.dumps(payload)
|
|
|
|
| 47 |
|
| 48 |
response.raise_for_status()
|
| 49 |
return response.json()
|
|
@@ -57,7 +58,8 @@ class OpenRouterClient:
|
|
| 57 |
try:
|
| 58 |
response = requests.get(
|
| 59 |
f"{self.base_url}/models",
|
| 60 |
-
headers=self.headers
|
|
|
|
| 61 |
|
| 62 |
response.raise_for_status()
|
| 63 |
return response.json().get("data", [])
|
|
|
|
| 10 |
self.headers = {
|
| 11 |
"Authorization": f"Bearer {self.api_key}",
|
| 12 |
"Content-Type": "application/json",
|
| 13 |
+
"HTTP-Referer": "https://huggingface.co/spaces",
|
| 14 |
+
"X-Title": "OpenRouter AI Hub"
|
| 15 |
}
|
| 16 |
|
| 17 |
def chat_completion(
|
|
|
|
| 44 |
f"{self.base_url}/chat/completions",
|
| 45 |
headers=self.headers,
|
| 46 |
data=json.dumps(payload)
|
| 47 |
+
)
|
| 48 |
|
| 49 |
response.raise_for_status()
|
| 50 |
return response.json()
|
|
|
|
| 58 |
try:
|
| 59 |
response = requests.get(
|
| 60 |
f"{self.base_url}/models",
|
| 61 |
+
headers=self.headers
|
| 62 |
+
)
|
| 63 |
|
| 64 |
response.raise_for_status()
|
| 65 |
return response.json().get("data", [])
|