Skip to content

Commit 0707809

Browse files
committed
fix: refactor check_auth method to use OpenAI client for chat completions
1 parent 29ca6ae commit 0707809

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

apps/models_provider/impl/aliyun_bai_lian_model_provider/model/image.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,22 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
3636
return chat_tong_yi
3737

3838
def check_auth(self, api_key):
39-
chat = ChatTongyi(api_key=api_key, model_name='qwen-max')
40-
chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])])
39+
from openai import OpenAI
40+
41+
client = OpenAI(
42+
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
43+
api_key=api_key,
44+
base_url=self.openai_api_base,
45+
)
46+
client.chat.completions.create(
47+
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
48+
model="qwen-max",
49+
messages=[
50+
{"role": "system", "content": "You are a helpful assistant."},
51+
{"role": "user", "content": gettext('Hello')},
52+
]
53+
54+
)
4155

4256
def get_upload_policy(self, api_key, model_name):
4357
"""获取文件上传凭证"""

apps/models_provider/impl/aliyun_bai_lian_model_provider/model/tti.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,22 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
4646
return chat_tong_yi
4747

4848
def check_auth(self):
49-
chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max')
50-
chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])])
49+
from openai import OpenAI
50+
51+
client = OpenAI(
52+
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
53+
api_key=self.api_key,
54+
base_url=self.api_base,
55+
)
56+
client.chat.completions.create(
57+
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
58+
model="qwen-max",
59+
messages=[
60+
{"role": "system", "content": "You are a helpful assistant."},
61+
{"role": "user", "content": gettext('Hello')},
62+
]
63+
64+
)
5165

5266
def generate_image(self, prompt: str, negative_prompt: str = None):
5367
if self.model_name.startswith("wan2.6") or self.model_name.startswith("z"):

apps/models_provider/impl/aliyun_bai_lian_model_provider/model/ttv.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,22 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
4444
)
4545

4646
def check_auth(self):
47-
chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max')
48-
self._safe_call(chat.invoke, input=[HumanMessage([{"type": "text", "text": gettext('Hello')}])])
47+
from openai import OpenAI
48+
49+
client = OpenAI(
50+
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
51+
api_key=self.api_key,
52+
base_url=self.api_base,
53+
)
54+
client.chat.completions.create(
55+
# 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
56+
model="qwen-max",
57+
messages=[
58+
{"role": "system", "content": "You are a helpful assistant."},
59+
{"role": "user", "content": gettext('Hello')},
60+
]
61+
62+
)
4963

5064
def _safe_call(self, func, **kwargs):
5165
"""带重试的请求封装"""

0 commit comments

Comments
 (0)