Private
Public Access
fix(qwen): align with dashscope 1.25.21 API; remove InvalidApiKey monkey-patch
This commit is contained in:
@@ -2390,6 +2390,10 @@ def _ensure_qwen_client() -> None:
|
|||||||
if not api_key:
|
if not api_key:
|
||||||
raise ValueError("Qwen API key not found in credentials.toml")
|
raise ValueError("Qwen API key not found in credentials.toml")
|
||||||
_qwen_region = creds.get("qwen", {}).get("region", "china")
|
_qwen_region = creds.get("qwen", {}).get("region", "china")
|
||||||
|
if _qwen_region == "international":
|
||||||
|
dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1"
|
||||||
|
else:
|
||||||
|
dashscope.base_http_api_url = "https://dashscope.aliyuncs.com/api/v1"
|
||||||
dashscope.api_key = api_key
|
dashscope.api_key = api_key
|
||||||
_qwen_client = dashscope.Generation
|
_qwen_client = dashscope.Generation
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -10,8 +10,6 @@ from dashscope.common.error import (
|
|||||||
)
|
)
|
||||||
from src.ai_client import ProviderError
|
from src.ai_client import ProviderError
|
||||||
|
|
||||||
dashscope.common.error.InvalidApiKey = dashscope.common.error.AuthenticationError
|
|
||||||
|
|
||||||
def build_dashscope_tools(openai_tools: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
def build_dashscope_tools(openai_tools: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||||
out: list[dict[str, Any]] = []
|
out: list[dict[str, Any]] = []
|
||||||
for t in openai_tools:
|
for t in openai_tools:
|
||||||
@@ -29,9 +27,9 @@ def classify_dashscope_error(exc: Exception) -> ProviderError:
|
|||||||
if isinstance(exc, AuthenticationError):
|
if isinstance(exc, AuthenticationError):
|
||||||
return ProviderError(kind="auth", provider="qwen", original=exc)
|
return ProviderError(kind="auth", provider="qwen", original=exc)
|
||||||
if isinstance(exc, TimeoutException):
|
if isinstance(exc, TimeoutException):
|
||||||
return ProviderError(kind="rate_limit", provider="qwen", original=exc)
|
return ProviderError(kind="network", provider="qwen", original=exc)
|
||||||
if isinstance(exc, ServiceUnavailableError):
|
if isinstance(exc, ServiceUnavailableError):
|
||||||
return ProviderError(kind="quota", provider="qwen", original=exc)
|
return ProviderError(kind="network", provider="qwen", original=exc)
|
||||||
if isinstance(exc, InvalidParameter):
|
if isinstance(exc, InvalidParameter):
|
||||||
return ProviderError(kind="quota", provider="qwen", original=exc)
|
return ProviderError(kind="quota", provider="qwen", original=exc)
|
||||||
if isinstance(exc, RequestFailure):
|
if isinstance(exc, RequestFailure):
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ def test_qwen_tool_format_translation() -> None:
|
|||||||
def test_qwen_error_classification() -> None:
|
def test_qwen_error_classification() -> None:
|
||||||
from src.ai_client import ProviderError
|
from src.ai_client import ProviderError
|
||||||
from src.qwen_adapter import classify_dashscope_error
|
from src.qwen_adapter import classify_dashscope_error
|
||||||
import dashscope
|
from dashscope.common.error import AuthenticationError
|
||||||
err = classify_dashscope_error(dashscope.common.error.InvalidApiKey("bad key"))
|
err = classify_dashscope_error(AuthenticationError("bad key"))
|
||||||
assert err.kind == "auth"
|
assert err.kind == "auth"
|
||||||
assert err.provider == "qwen"
|
assert err.provider == "qwen"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user