mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-05 18:20:35 -08:00
Refactor QwenCode and oauthFlow for improved model handling and credential management
This commit is contained in:
parent
9bed8da354
commit
5bac1a8bfb
3 changed files with 14 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue