diff --git a/g4f/Provider/qwen/QwenCode.py b/g4f/Provider/qwen/QwenCode.py index 4df89422..8304aa8b 100644 --- a/g4f/Provider/qwen/QwenCode.py +++ b/g4f/Provider/qwen/QwenCode.py @@ -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 diff --git a/g4f/Provider/qwen/oauthFlow.py b/g4f/Provider/qwen/oauthFlow.py index 0c9695a6..2dd1280b 100644 --- a/g4f/Provider/qwen/oauthFlow.py +++ b/g4f/Provider/qwen/oauthFlow.py @@ -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: diff --git a/g4f/Provider/qwen/qwenOAuth2.py b/g4f/Provider/qwen/qwenOAuth2.py index 779f8150..ac08cefd 100644 --- a/g4f/Provider/qwen/qwenOAuth2.py +++ b/g4f/Provider/qwen/qwenOAuth2.py @@ -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",