Merge pull request #3184 from xtekky/3mora2-main

Swap model aliases for consistency and enhance model retrieval logic
This commit is contained in:
H Lohaus 2025-09-21 13:37:15 +02:00 committed by GitHub
commit 3e37961b00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 9 deletions

View file

@ -88,7 +88,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
vision_models = [default_vision_model]
_models_loaded = False
model_aliases = {
"openai-fast": "gpt-4.1-nano",
"gpt-4.1-nano": "openai-fast",
"llama-4-scout": "llamascout",
"deepseek-r1": "deepseek-reasoning",
"sdxl-turbo": "turbo",
@ -99,6 +99,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
"flux": "flux",
"flux-kontext": "kontext",
}
swap_model_aliases = {v: k for k, v in model_aliases.items()}
@classmethod
def get_models(cls, **kwargs):
@ -106,8 +107,8 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
alias = model.get("name")
if (model.get("aliases")):
alias = model.get("aliases")[0]
elif alias in cls.model_aliases:
alias = cls.model_aliases[alias]
elif alias in cls.swap_model_aliases:
alias = cls.swap_model_aliases[alias]
return alias.replace("-instruct", "").replace("qwen-", "qwen").replace("qwen", "qwen-")
if not cls._models_loaded:
try:
@ -383,6 +384,9 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
if cls.login_url in str(item):
raise MissingAuthError(item)
raise item
else:
finished += 1
yield Reasoning(label=f"Image {finished}/{n} failed after {time.time() - start:.2f}s: {item}")
else:
finished += 1
yield Reasoning(label=f"Image {finished}/{n} generated in {time.time() - start:.2f}s")

View file

@ -1,7 +1,6 @@
from __future__ import annotations
from ...typing import Messages, AsyncResult
from ...errors import MissingAuthError
from ..template import OpenaiTemplate
from .qwenContentGenerator import QwenContentGenerator
from .qwenOAuth2 import QwenOAuth2Client
@ -15,7 +14,9 @@ class QwenCode(OpenaiTemplate):
needs_auth = True
active_by_default = True
default_model = "qwen3-coder-plus"
models = [default_model]
default_vision_model = "qwen-vl-max-latest"
models = [default_model, default_vision_model]
vision_models = [default_vision_model]
client = QwenContentGenerator(QwenOAuth2Client())
@classmethod

View file

@ -71,7 +71,14 @@ async def launch_browser_for_oauth():
print("\nAuthorization successful.")
print("Access Token:", token_response["access_token"])
# Save token_response to a file or config
await client.sharedManager.saveCredentialsToFile(token_response)
credentials = {
"access_token": token_response["access_token"],
"token_type": token_response["token_type"],
"refresh_token": token_response.get("refresh_token"),
"resource_url": token_response.get("resource_url"),
"expiry_date": int(time.time() * 1000) + token_response.get("expires_in", 0) * 1000,
}
await client.sharedManager.saveCredentialsToFile(credentials)
print(f"Credentials saved to: {client.sharedManager.getCredentialFilePath()}")
return
else:

View file

@ -111,7 +111,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
"code_challenge": options["code_challenge"],
"code_challenge_method": options["code_challenge_method"],
}
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
async with session.post(QWEN_OAUTH_DEVICE_CODE_ENDPOINT, headers={
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
@ -133,7 +133,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
"device_code": options["device_code"],
"code_verifier": options["code_verifier"],
}
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
@ -158,7 +158,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
"refresh_token": self.credentials["refresh_token"],
"client_id": QWEN_OAUTH_CLIENT_ID,
}
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",