Refactor PollinationsAI model alias handling for improved string conversion; add audio_tokens field to CompletionTokenDetails; update data structure in Backend_Api for user data handling.

This commit is contained in:
hlohaus
2025-10-04 00:48:46 +02:00
parent 6b210f44f9
commit 1fb8b7e4c9
4 changed files with 4 additions and 2 deletions

View File

@@ -110,7 +110,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
alias = model.get("aliases")[0]
elif alias in cls.swap_model_aliases:
alias = cls.swap_model_aliases[alias]
return alias.replace("-instruct", "").replace("qwen-", "qwen").replace("qwen", "qwen-")
return str(alias).replace("-instruct", "").replace("qwen-", "qwen").replace("qwen", "qwen-")
if not cls._models_loaded:
try:

View File

@@ -6,6 +6,7 @@ class Custom(OpenaiTemplate):
label = "Custom Provider"
working = True
needs_auth = False
models_needs_auth = False
api_base = "http://localhost:8080/v1"
sort_models = False

View File

@@ -40,6 +40,7 @@ class PromptTokenDetails(BaseModel):
class CompletionTokenDetails(BaseModel):
reasoning_tokens: int
image_tokens: int
audio_tokens: int
class UsageModel(BaseModel):
prompt_tokens: int

View File

@@ -239,7 +239,7 @@ class Backend_Api(Api):
cache_dir = Path(get_cookies_dir()) / ".usage"
cache_file = cache_dir / f"{datetime.date.today()}.jsonl"
cache_dir.mkdir(parents=True, exist_ok=True)
data = {**request.json, "user": request.headers.get("x-user", "unknown")}
data = {"user": request.headers.get("x-user", "unknown"), **request.json}
with cache_file.open("a" if cache_file.exists() else "w") as f:
f.write(f"{json.dumps(data)}\n")
return {}