File size: 1,207 Bytes
f6928fa d184447 f6928fa d184447 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | from typing import Dict, Any
from . import Provider
from .. import config
class KiloProvider(Provider):
name = "kilo"
base_url = "https://api.kilo.ai/api/gateway"
def is_available(self) -> bool:
return True
def is_free_model(self, model: Dict[str, Any]) -> bool:
if model.get("isFree", False):
return True
model_id = model.get("id", "")
if ":free" in model_id:
return True
if model.get("isFree") is False:
return False
pricing = model.get("pricing") or {}
prompt_price = str(pricing.get("prompt", "0"))
completion_price = str(pricing.get("completion", "0"))
request_price = str(pricing.get("request", "0"))
return (prompt_price == "0"
and completion_price == "0"
and request_price == "0")
def get_chat_url(self) -> str:
return f"{self.base_url}/chat/completions"
def get_headers(self, model_id: str) -> Dict[str, str]:
headers = {"Content-Type": "application/json"}
api_key = config.get_kilo_api_key()
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
return headers
|