Skip to content

Commit

Permalink
Merge pull request #1000 from RockChinQ/feat/siliconflow
Browse files Browse the repository at this point in the history
feat: siliconflow provider
  • Loading branch information
RockChinQ authored Feb 1, 2025
2 parents 8644f2c + 41a7814 commit f492fee
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
| [LMStudio](https://lmstudio.ai/) || 本地大模型运行平台 |
| [GiteeAI](https://ai.gitee.com/) || 大模型接口聚合平台 |
| [SiliconFlow](https://siliconflow.cn/) || 大模型聚合平台 |
| [阿里云百炼](https://bailian.console.aliyun.com/) || 大模型聚合平台 |

## 😘 社区贡献

Expand Down
27 changes: 27 additions & 0 deletions pkg/core/migrations/m023_siliconflow_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

from .. import migration


@migration.migration_class("siliconflow-config", 23)
class SiliconFlowConfigMigration(migration.Migration):
"""迁移"""

async def need_migrate(self) -> bool:
"""判断当前环境是否需要运行此迁移"""

return 'siliconflow-chat-completions' not in self.ap.provider_cfg.data['requester']

async def run(self):
"""执行迁移"""
self.ap.provider_cfg.data['keys']['siliconflow'] = [
"xxxxxxx"
]

self.ap.provider_cfg.data['requester']['siliconflow-chat-completions'] = {
"base-url": "https://api.siliconflow.cn/v1",
"args": {},
"timeout": 120
}

await self.ap.provider_cfg.dump_config()
2 changes: 1 addition & 1 deletion pkg/core/stages/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_qcg_center_url, m008_ad_fixwin_config_migrate, m009_msg_truncator_cfg
from ..migrations import m010_ollama_requester_config, m011_command_prefix_config, m012_runner_config, m013_http_api_config, m014_force_delay_config
from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_api_timeout_params, m018_xai_config, m019_zhipuai_config
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config


@stage.stage_class("MigrationStage")
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/modelmgr/modelmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ...core import app

from . import token
from .requesters import chatcmpl, anthropicmsgs, moonshotchatcmpl, deepseekchatcmpl, ollamachat, giteeaichatcmpl, xaichatcmpl, zhipuaichatcmpl, lmstudiochatcmpl
from .requesters import chatcmpl, anthropicmsgs, moonshotchatcmpl, deepseekchatcmpl, ollamachat, giteeaichatcmpl, xaichatcmpl, zhipuaichatcmpl, lmstudiochatcmpl, siliconflowchatcmpl

FETCH_MODEL_LIST_URL = "https://api.qchatgpt.rockchin.top/api/v2/fetch/model_list"

Expand Down
21 changes: 21 additions & 0 deletions pkg/provider/modelmgr/requesters/siliconflowchatcmpl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

import openai

from . import chatcmpl
from .. import requester
from ....core import app


@requester.requester_class("siliconflow-chat-completions")
class SiliconFlowChatCompletions(chatcmpl.OpenAIChatCompletions):
"""SiliconFlow 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']['siliconflow-chat-completions']
8 changes: 8 additions & 0 deletions templates/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
],
"zhipuai": [
"xxxxxxx"
],
"siliconflow": [
"xxxxxxx"
]
},
"requester": {
Expand Down Expand Up @@ -71,6 +74,11 @@
"base-url": "http://127.0.0.1:1234/v1",
"args": {},
"timeout": 120
},
"siliconflow-chat-completions": {
"base-url": "https://api.siliconflow.cn/v1",
"args": {},
"timeout": 120
}
},
"model": "gpt-4o",
Expand Down
28 changes: 28 additions & 0 deletions templates/schema/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
"type": "string"
},
"default": []
},
"siliconflow": {
"type": "array",
"title": "SiliconFlow API 密钥",
"items": {
"type": "string"
},
"default": []
}
}
},
Expand Down Expand Up @@ -260,6 +268,26 @@
"default": 120
}
}
},
"siliconflow-chat-completions": {
"type": "object",
"title": "SiliconFlow API 请求配置",
"description": "仅可编辑 URL 和 超时时间,额外请求参数不支持可视化编辑,请到编辑器编辑",
"properties": {
"base-url": {
"type": "string",
"title": "API URL"
},
"args": {
"type": "object",
"default": {}
},
"timeout": {
"type": "number",
"title": "API 请求超时时间",
"default": 120
}
}
}
}
},
Expand Down

0 comments on commit f492fee

Please sign in to comment.