Skip to content

Commit 5bac1a8

Browse files
committed
Refactor QwenCode and oauthFlow for improved model handling and credential management
1 parent 9bed8da commit 5bac1a8

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

g4f/Provider/qwen/QwenCode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from ...typing import Messages, AsyncResult
4-
from ...errors import MissingAuthError
54
from ..template import OpenaiTemplate
65
from .qwenContentGenerator import QwenContentGenerator
76
from .qwenOAuth2 import QwenOAuth2Client
@@ -15,7 +14,9 @@ class QwenCode(OpenaiTemplate):
1514
needs_auth = True
1615
active_by_default = True
1716
default_model = "qwen3-coder-plus"
18-
models = [default_model]
17+
default_vision_model = "qwen-vl-max-latest"
18+
models = [default_model, default_vision_model]
19+
vision_models = [default_vision_model]
1920
client = QwenContentGenerator(QwenOAuth2Client())
2021

2122
@classmethod

g4f/Provider/qwen/oauthFlow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ async def launch_browser_for_oauth():
7171
print("\nAuthorization successful.")
7272
print("Access Token:", token_response["access_token"])
7373
# Save token_response to a file or config
74-
await client.sharedManager.saveCredentialsToFile(token_response)
74+
credentials = {
75+
"access_token": token_response["access_token"],
76+
"token_type": token_response["token_type"],
77+
"refresh_token": token_response.get("refresh_token"),
78+
"resource_url": token_response.get("resource_url"),
79+
"expiry_date": int(time.time() * 1000) + token_response.get("expires_in", 0) * 1000,
80+
}
81+
await client.sharedManager.saveCredentialsToFile(credentials)
7582
print(f"Credentials saved to: {client.sharedManager.getCredentialFilePath()}")
7683
return
7784
else:

g4f/Provider/qwen/qwenOAuth2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def requestDeviceAuthorization(self, options: dict) -> Union[Dict, ErrorDa
111111
"code_challenge": options["code_challenge"],
112112
"code_challenge_method": options["code_challenge_method"],
113113
}
114-
async with aiohttp.ClientSession() as session:
114+
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
115115
async with session.post(QWEN_OAUTH_DEVICE_CODE_ENDPOINT, headers={
116116
"Content-Type": "application/x-www-form-urlencoded",
117117
"Accept": "application/json",
@@ -133,7 +133,7 @@ async def pollDeviceToken(self, options: dict) -> Union[Dict, ErrorDataDict]:
133133
"device_code": options["device_code"],
134134
"code_verifier": options["code_verifier"],
135135
}
136-
async with aiohttp.ClientSession() as session:
136+
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
137137
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
138138
"Content-Type": "application/x-www-form-urlencoded",
139139
"Accept": "application/json",
@@ -158,7 +158,7 @@ async def refreshAccessToken(self) -> Union[Dict, ErrorDataDict]:
158158
"refresh_token": self.credentials["refresh_token"],
159159
"client_id": QWEN_OAUTH_CLIENT_ID,
160160
}
161-
async with aiohttp.ClientSession() as session:
161+
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
162162
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
163163
"Content-Type": "application/x-www-form-urlencoded",
164164
"Accept": "application/json",

0 commit comments

Comments
 (0)