Merge pull request #1311 from RockChinQ/feat/ppio

feat: add support for ppio
This commit is contained in:
Junyan Qin (Chin)
2025-04-17 16:36:01 +08:00
committed by GitHub
6 changed files with 95 additions and 3 deletions

View File

@@ -3,9 +3,9 @@ from __future__ import annotations
from .. import migration
@migration.migration_class("modelscope-config-completion", 4)
@migration.migration_class("modelscope-config-completion", 39)
class ModelScopeConfigCompletionMigration(migration.Migration):
"""OpenAI配置迁移
"""ModelScope配置迁移
"""
async def need_migrate(self) -> bool:

View File

@@ -0,0 +1,30 @@
from __future__ import annotations
from .. import migration
@migration.migration_class("ppio-config", 40)
class PPIOConfigMigration(migration.Migration):
"""PPIO配置迁移
"""
async def need_migrate(self) -> bool:
"""判断当前环境是否需要运行此迁移
"""
return 'ppio-chat-completions' not in self.ap.provider_cfg.data['requester'] \
or 'ppio' not in self.ap.provider_cfg.data['keys']
async def run(self):
"""执行迁移
"""
if 'ppio-chat-completions' not in self.ap.provider_cfg.data['requester']:
self.ap.provider_cfg.data['requester']['ppio-chat-completions'] = {
'base-url': 'https://api.ppinfra.com/v3/openai',
'args': {},
'timeout': 120,
}
if 'ppio' not in self.ap.provider_cfg.data['keys']:
self.ap.provider_cfg.data['keys']['ppio'] = []
await self.ap.provider_cfg.dump_config()

View File

@@ -12,7 +12,7 @@ from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_conf
from ..migrations import m026_qqofficial_config, m027_wx_official_account_config, m028_aliyun_requester_config
from ..migrations import m029_dashscope_app_api_config, m030_lark_config_cmpl, m031_dingtalk_config, m032_volcark_config
from ..migrations import m033_dify_thinking_config, m034_gewechat_file_url_config, m035_wxoa_mode, m036_wxoa_loading_message
from ..migrations import m037_mcp_config, m038_tg_dingtalk_markdown, m039_modelscope_cfg_completion
from ..migrations import m037_mcp_config, m038_tg_dingtalk_markdown, m039_modelscope_cfg_completion, m040_ppio_config
@stage.stage_class("MigrationStage")

View File

@@ -0,0 +1,20 @@
from __future__ import annotations
import openai
from . import chatcmpl, modelscopechatcmpl
from .. import requester
from ....core import app
class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
"""欧派云 ChatCompletion API 请求器"""
client: openai.AsyncClient
requester_cfg: dict
def __init__(self, ap: app.Application):
self.ap = ap
self.requester_cfg = self.ap.provider_cfg.data['requester']['ppio-chat-completions']

View File

@@ -0,0 +1,34 @@
apiVersion: v1
kind: LLMAPIRequester
metadata:
name: ppio-chat-completions
label:
en_US: ppio
zh_CN: 派欧云
spec:
config:
- name: base-url
label:
en_US: Base URL
zh_CN: 基础 URL
type: string
required: true
default: "https://api.ppinfra.com/v3/openai"
- name: args
label:
en_US: Args
zh_CN: 附加参数
type: object
required: true
default: {}
- name: timeout
label:
en_US: Timeout
zh_CN: 超时时间
type: int
required: true
default: 120
execution:
python:
path: ./ppiochatcmpl.py
attr: PPIOChatCompletions

View File

@@ -34,6 +34,9 @@
],
"modelscope": [
"xxxxxxxx"
],
"ppio": [
"xxxxxxxx"
]
},
"requester": {
@@ -103,6 +106,11 @@
"base-url": "https://api-inference.modelscope.cn/v1",
"args": {},
"timeout": 120
},
"ppio-chat-completions": {
"base-url": "https://api.ppinfra.com/v3/openai",
"args": {},
"timeout": 120
}
},
"model": "gpt-4o",