返回提交历史
Modified
g4f/Provider/qwen/QwenCode.py
+3
-2
Modified
g4f/Provider/qwen/oauthFlow.py
+8
-1
Modified
g4f/Provider/qwen/qwenOAuth2.py
+3
-3
XFEstudio/gpt4free
Refactor QwenCode and oauthFlow for improved model handling and credential management
5bac1a8b
代码差异
3 个文件
+14
-6
@@ -1,7 +1,6 @@
1
1
from __future__ import annotations
2
2
3
3
from ...typing import Messages, AsyncResult
4
from ...errors import MissingAuthError
5
4
from ..template import OpenaiTemplate
6
5
from .qwenContentGenerator import QwenContentGenerator
7
6
from .qwenOAuth2 import QwenOAuth2Client
@@ -15,7 +14,9 @@ class QwenCode(OpenaiTemplate):
15
14
needs_auth = True
16
15
active_by_default = True
17
16
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]
19
20
client = QwenContentGenerator(QwenOAuth2Client())
20
21
21
22
@classmethod
@@ -71,7 +71,14 @@ async def launch_browser_for_oauth():
71
71
print("\nAuthorization successful.")
72
72
print("Access Token:", token_response["access_token"])
73
73
# 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)
75
82
print(f"Credentials saved to: {client.sharedManager.getCredentialFilePath()}")
76
83
return
77
84
else:
@@ -111,7 +111,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
111
111
"code_challenge": options["code_challenge"],
112
112
"code_challenge_method": options["code_challenge_method"],
113
113
}
114
async with aiohttp.ClientSession() as session:
114
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
115
115
async with session.post(QWEN_OAUTH_DEVICE_CODE_ENDPOINT, headers={
116
116
"Content-Type": "application/x-www-form-urlencoded",
117
117
"Accept": "application/json",
@@ -133,7 +133,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
133
133
"device_code": options["device_code"],
134
134
"code_verifier": options["code_verifier"],
135
135
}
136
async with aiohttp.ClientSession() as session:
136
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
137
137
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
138
138
"Content-Type": "application/x-www-form-urlencoded",
139
139
"Accept": "application/json",
@@ -158,7 +158,7 @@ class QwenOAuth2Client(IQwenOAuth2Client):
158
158
"refresh_token": self.credentials["refresh_token"],
159
159
"client_id": QWEN_OAUTH_CLIENT_ID,
160
160
}
161
async with aiohttp.ClientSession() as session:
161
async with aiohttp.ClientSession(headers={"user-agent": ""}) as session:
162
162
async with session.post(QWEN_OAUTH_TOKEN_ENDPOINT, headers={
163
163
"Content-Type": "application/x-www-form-urlencoded",
164
164
"Accept": "application/json",