Spaces:
Running
Running
Update app/providers.py
Browse files- app/providers.py +11 -3
app/providers.py
CHANGED
|
@@ -147,7 +147,6 @@ class GeminiProvider(BaseProvider):
|
|
| 147 |
try:
|
| 148 |
r.raise_for_status()
|
| 149 |
except httpx.HTTPStatusError as e:
|
| 150 |
-
# safe_url has no key — params are NOT part of safe_url string
|
| 151 |
raise RuntimeError(
|
| 152 |
f"HTTP {e.response.status_code} from {safe_url}"
|
| 153 |
) from None
|
|
@@ -155,7 +154,11 @@ class GeminiProvider(BaseProvider):
|
|
| 155 |
|
| 156 |
|
| 157 |
class OpenRouterProvider(BaseProvider):
|
| 158 |
-
"""OpenRouter API — OpenAI-compatible chat completions endpoint.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
async def complete(self, prompt: str, model: str = None, max_tokens: int = 1024) -> str:
|
| 161 |
data = await self._post(
|
|
@@ -163,6 +166,7 @@ class OpenRouterProvider(BaseProvider):
|
|
| 163 |
headers={
|
| 164 |
"Authorization": f"Bearer {self.key}",
|
| 165 |
"HTTP-Referer": os.getenv("APP_URL", "https://huggingface.co"),
|
|
|
|
| 166 |
"content-type": "application/json",
|
| 167 |
},
|
| 168 |
payload={
|
|
@@ -175,7 +179,11 @@ class OpenRouterProvider(BaseProvider):
|
|
| 175 |
|
| 176 |
|
| 177 |
class HuggingFaceProvider(BaseProvider):
|
| 178 |
-
"""HuggingFace Inference API — chat completions endpoint.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
async def complete(self, prompt: str, model: str = None, max_tokens: int = 512) -> str:
|
| 181 |
m = model or self.model
|
|
|
|
| 147 |
try:
|
| 148 |
r.raise_for_status()
|
| 149 |
except httpx.HTTPStatusError as e:
|
|
|
|
| 150 |
raise RuntimeError(
|
| 151 |
f"HTTP {e.response.status_code} from {safe_url}"
|
| 152 |
) from None
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
class OpenRouterProvider(BaseProvider):
|
| 157 |
+
"""OpenRouter API — OpenAI-compatible chat completions endpoint.
|
| 158 |
+
|
| 159 |
+
Required headers: HTTP-Referer + X-Title (required by OpenRouter for
|
| 160 |
+
free models and rate limit attribution).
|
| 161 |
+
"""
|
| 162 |
|
| 163 |
async def complete(self, prompt: str, model: str = None, max_tokens: int = 1024) -> str:
|
| 164 |
data = await self._post(
|
|
|
|
| 166 |
headers={
|
| 167 |
"Authorization": f"Bearer {self.key}",
|
| 168 |
"HTTP-Referer": os.getenv("APP_URL", "https://huggingface.co"),
|
| 169 |
+
"X-Title": os.getenv("HUB_NAME", "Universal MCP Hub"), # required!
|
| 170 |
"content-type": "application/json",
|
| 171 |
},
|
| 172 |
payload={
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
class HuggingFaceProvider(BaseProvider):
|
| 182 |
+
"""HuggingFace Inference API — chat completions endpoint.
|
| 183 |
+
|
| 184 |
+
Uses /v1/chat/completions (OpenAI-compatible, requires recent models).
|
| 185 |
+
Legacy models (410 Gone) must be removed from .pyfun models list.
|
| 186 |
+
"""
|
| 187 |
|
| 188 |
async def complete(self, prompt: str, model: str = None, max_tokens: int = 512) -> str:
|
| 189 |
m = model or self.model
|