Skip to content

Commit 0b669ba

Browse files
feat: add Qiniu provider support (#172)
Co-authored-by: JiangZhuo <jiangzhuo@qiniu.com>
1 parent d0cb5df commit 0b669ba

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

openjudge/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from openjudge.models.base_chat_model import BaseChatModel
77
from openjudge.models.minimax_chat_model import MiniMaxChatModel
88
from openjudge.models.openai_chat_model import OpenAIChatModel
9+
from openjudge.models.qiniu_chat_model import QiniuChatModel
910
from openjudge.models.qwen_vl_model import QwenVLModel
1011

1112
__all__ = [
1213
"BaseChatModel",
1314
"MiniMaxChatModel",
1415
"OpenAIChatModel",
16+
"QiniuChatModel",
1517
"QwenVLModel",
1618
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
"""Qiniu Chat Model."""
3+
4+
import os
5+
from typing import Any, Dict
6+
7+
from openjudge.models.openai_chat_model import OpenAIChatModel
8+
9+
# Qiniu-supported default model list
10+
QINIU_MODELS = [
11+
"deepseek-v3",
12+
]
13+
14+
15+
class QiniuChatModel(OpenAIChatModel):
16+
"""Qiniu chat model using the OpenAI-compatible API gateway."""
17+
18+
QINIU_BASE_URL = "https://api.qnaigc.com/v1"
19+
20+
def __init__(
21+
self,
22+
model: str = "deepseek-v3",
23+
api_key: str | None = None,
24+
base_url: str | None = None,
25+
stream: bool = False,
26+
client_args: Dict[str, Any] | None = None,
27+
max_retries: int | None = None,
28+
timeout: float | None = None,
29+
**kwargs: Any,
30+
) -> None:
31+
"""Initialize the qiniu chat model."""
32+
resolved_api_key = api_key or os.getenv("QINIU_API_KEY")
33+
resolved_base_url = base_url or self.QINIU_BASE_URL
34+
35+
super().__init__(
36+
model=model,
37+
api_key=resolved_api_key,
38+
base_url=resolved_base_url,
39+
stream=stream,
40+
client_args=client_args,
41+
max_retries=max_retries,
42+
timeout=timeout,
43+
**kwargs,
44+
)
45+
46+
47+
__all__ = ["QiniuChatModel", "QINIU_MODELS"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""Unit tests for QiniuChatModel."""
4+
5+
import pytest
6+
7+
from openjudge.models import QiniuChatModel
8+
from openjudge.models.qiniu_chat_model import QINIU_MODELS
9+
10+
11+
@pytest.mark.unit
12+
class TestQiniuChatModelInit:
13+
"""Verify constructor defaults and argument handling."""
14+
15+
def test_default_base_url(self):
16+
model = QiniuChatModel(api_key="test-key")
17+
assert model.client.base_url is not None
18+
assert "qnaigc.com" in str(model.client.base_url)
19+
20+
def test_default_model(self):
21+
model = QiniuChatModel(api_key="test-key")
22+
assert model.model == "deepseek-v3"
23+
24+
def test_qiniu_models_contains_deepseek_v3(self):
25+
assert "deepseek-v3" in QINIU_MODELS
26+
27+
def test_api_key_from_env(self, monkeypatch):
28+
monkeypatch.setenv("QINIU_API_KEY", "env-key-123")
29+
model = QiniuChatModel()
30+
assert model.client.api_key == "env-key-123"
31+
32+
def test_explicit_api_key_overrides_env(self, monkeypatch):
33+
monkeypatch.setenv("QINIU_API_KEY", "env-key")
34+
model = QiniuChatModel(api_key="explicit-key")
35+
assert model.client.api_key == "explicit-key"
36+
37+
def test_custom_base_url(self):
38+
model = QiniuChatModel(api_key="k", base_url="https://custom.qnaigc.com/v1")
39+
assert "custom.qnaigc.com" in str(model.client.base_url)
40+
41+
42+
@pytest.mark.unit
43+
class TestQiniuChatModelInheritance:
44+
"""Verify class hierarchy and exported symbols."""
45+
46+
def test_inherits_from_openai_chat_model(self):
47+
from openjudge.models.openai_chat_model import OpenAIChatModel
48+
49+
assert issubclass(QiniuChatModel, OpenAIChatModel)
50+
51+
def test_exported_from_models_package(self):
52+
from openjudge.models import QiniuChatModel as Imported
53+
54+
assert Imported is QiniuChatModel

ui/shared/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"DashScope": "https://dashscope.aliyuncs.com/compatible-mode/v1",
2121
"OpenAI": "https://api.openai.com/v1",
2222
"DeepSeek": "https://api.deepseek.com/v1",
23+
"Qiniu": "https://api.qnaigc.com/v1",
2324
"Custom": "",
2425
}
2526

@@ -39,6 +40,7 @@
3940
"o3-mini",
4041
"o4-mini",
4142
# DeepSeek
43+
"deepseek-v3",
4244
"deepseek-v3.2",
4345
"deepseek-r1",
4446
]

0 commit comments

Comments
 (0)