mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 23:25:56 +08:00
feat: support siliconflow (#5129)
This commit is contained in:
parent
d6fa130cb5
commit
79e8489942
@ -32,3 +32,4 @@
|
|||||||
- openai_api_compatible
|
- openai_api_compatible
|
||||||
- deepseek
|
- deepseek
|
||||||
- hunyuan
|
- hunyuan
|
||||||
|
- siliconflow
|
||||||
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 5.6 KiB |
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="128" height="128" viewBox="0 0 128 128"><g><g style="opacity:0;"><rect x="0" y="0" width="128" height="128" rx="0" fill="#FFFFFF" fill-opacity="1"/></g><g><path d="M100.74,12L93.2335,12C69.21260000000001,12,55.3672,27.3468,55.3672,50.8672L55.3672,54.8988C52.6011,54.1056,49.7377,53.7031,46.8601,53.7031C29.816499999999998,53.7031,16,67.5196,16,84.5632C16,101.6069,29.816499999999998,115.423,46.8601,115.423C63.9037,115.423,77.72030000000001,101.6069,77.72030000000001,84.5632C77.72030000000001,82.4902,77.51140000000001,80.4223,77.0967,78.3911L77.2197,78.3911L100.74,78.3911C106.9654,78.3681,112,73.3151,112,67.08959999999999C112,60.8642,106.9654,55.8111,100.74,55.7882L100.7362,55.7882L100.6985,55.7879L100.6606,55.7882L77.2197,55.7882L77.2195,49.8663C77.2195,40.8584,83.7252,34.352900000000005,93.2335,34.352900000000005L100.5653,34.352900000000005L100.5733,34.352900000000005L100.5812,34.352900000000005L100.74,34.352900000000005L100.74,34.352900000000005C106.8469,34.2605,111.7497,29.284,111.7497,23.1764C111.7497,17.06889,106.8469,12.0923454,100.74,12L100.74,12ZM56.0347,84.5632C56.0347,79.4962,51.9271,75.3885,46.8601,75.3885C41.793099999999995,75.3885,37.6854,79.4962,37.6854,84.5632C37.6854,89.6303,41.793099999999995,93.7378,46.8601,93.7378C51.9271,93.7378,56.0347,89.6303,56.0347,84.5632Z" fill-rule="evenodd" fill="#8358F6" fill-opacity="1"/></g></g></svg>
|
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,8 @@
|
|||||||
|
- deepseek-v2-chat
|
||||||
|
- qwen2-72b-instruct
|
||||||
|
- qwen2-57b-a14b-instruct
|
||||||
|
- qwen2-7b-instruct
|
||||||
|
- yi-1.5-34b-chat
|
||||||
|
- yi-1.5-9b-chat
|
||||||
|
- yi-1.5-6b-chat
|
||||||
|
- glm4-9B-chat
|
@ -0,0 +1,32 @@
|
|||||||
|
model: deepseek-ai/deepseek-v2-chat
|
||||||
|
label:
|
||||||
|
en_US: deepseek-ai/deepseek-v2-chat
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 32768
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '1.33'
|
||||||
|
output: '1.33'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: zhipuai/glm4-9B-chat
|
||||||
|
label:
|
||||||
|
en_US: zhipuai/glm4-9B-chat
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 32768
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '0.6'
|
||||||
|
output: '0.6'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,25 @@
|
|||||||
|
from collections.abc import Generator
|
||||||
|
from typing import Optional, Union
|
||||||
|
|
||||||
|
from core.model_runtime.entities.llm_entities import LLMResult
|
||||||
|
from core.model_runtime.entities.message_entities import PromptMessage, PromptMessageTool
|
||||||
|
from core.model_runtime.model_providers.openai_api_compatible.llm.llm import OAIAPICompatLargeLanguageModel
|
||||||
|
|
||||||
|
|
||||||
|
class SiliconflowLargeLanguageModel(OAIAPICompatLargeLanguageModel):
|
||||||
|
def _invoke(self, model: str, credentials: dict,
|
||||||
|
prompt_messages: list[PromptMessage], model_parameters: dict,
|
||||||
|
tools: Optional[list[PromptMessageTool]] = None, stop: Optional[list[str]] = None,
|
||||||
|
stream: bool = True, user: Optional[str] = None) \
|
||||||
|
-> Union[LLMResult, Generator]:
|
||||||
|
self._add_custom_parameters(credentials)
|
||||||
|
return super()._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream)
|
||||||
|
|
||||||
|
def validate_credentials(self, model: str, credentials: dict) -> None:
|
||||||
|
self._add_custom_parameters(credentials)
|
||||||
|
super().validate_credentials(model, credentials)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _add_custom_parameters(cls, credentials: dict) -> None:
|
||||||
|
credentials['mode'] = 'chat'
|
||||||
|
credentials['endpoint_url'] = 'https://api.siliconflow.cn/v1'
|
@ -0,0 +1,32 @@
|
|||||||
|
model: alibaba/Qwen2-57B-A14B-Instruct
|
||||||
|
label:
|
||||||
|
en_US: alibaba/Qwen2-57B-A14B-Instruct
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 32768
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '1.26'
|
||||||
|
output: '1.26'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: alibaba/Qwen2-72B-Instruct
|
||||||
|
label:
|
||||||
|
en_US: alibaba/Qwen2-72B-Instruct
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 32768
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '4.13'
|
||||||
|
output: '4.13'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: alibaba/Qwen2-7B-Instruct
|
||||||
|
label:
|
||||||
|
en_US: alibaba/Qwen2-7B-Instruct
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 32768
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '0.35'
|
||||||
|
output: '0.35'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: 01-ai/Yi-1.5-34B-Chat
|
||||||
|
label:
|
||||||
|
en_US: 01-ai/Yi-1.5-34B-Chat
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 16384
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '1.26'
|
||||||
|
output: '1.26'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: 01-ai/Yi-1.5-6B-Chat
|
||||||
|
label:
|
||||||
|
en_US: 01-ai/Yi-1.5-6B-Chat
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 4096
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '0.35'
|
||||||
|
output: '0.35'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,32 @@
|
|||||||
|
model: 01-ai/Yi-1.5-9B-Chat
|
||||||
|
label:
|
||||||
|
en_US: 01-ai/Yi-1.5-9B-Chat
|
||||||
|
model_type: llm
|
||||||
|
features:
|
||||||
|
- multi-tool-call
|
||||||
|
- agent-thought
|
||||||
|
- stream-tool-call
|
||||||
|
model_properties:
|
||||||
|
mode: chat
|
||||||
|
context_size: 16384
|
||||||
|
parameter_rules:
|
||||||
|
- name: temperature
|
||||||
|
use_template: temperature
|
||||||
|
- name: max_tokens
|
||||||
|
use_template: max_tokens
|
||||||
|
type: int
|
||||||
|
default: 512
|
||||||
|
min: 1
|
||||||
|
max: 4096
|
||||||
|
help:
|
||||||
|
zh_Hans: 指定生成结果长度的上限。如果生成结果截断,可以调大该参数。
|
||||||
|
en_US: Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.
|
||||||
|
- name: top_p
|
||||||
|
use_template: top_p
|
||||||
|
- name: frequency_penalty
|
||||||
|
use_template: frequency_penalty
|
||||||
|
pricing:
|
||||||
|
input: '0.42'
|
||||||
|
output: '0.42'
|
||||||
|
unit: '0.000001'
|
||||||
|
currency: RMB
|
@ -0,0 +1,29 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from core.model_runtime.entities.model_entities import ModelType
|
||||||
|
from core.model_runtime.errors.validate import CredentialsValidateFailedError
|
||||||
|
from core.model_runtime.model_providers.__base.model_provider import ModelProvider
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class SiliconflowProvider(ModelProvider):
|
||||||
|
|
||||||
|
def validate_provider_credentials(self, credentials: dict) -> None:
|
||||||
|
"""
|
||||||
|
Validate provider credentials
|
||||||
|
if validate failed, raise exception
|
||||||
|
|
||||||
|
:param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
model_instance = self.get_model_instance(ModelType.LLM)
|
||||||
|
|
||||||
|
model_instance.validate_credentials(
|
||||||
|
model='deepseek-ai/deepseek-v2-chat',
|
||||||
|
credentials=credentials
|
||||||
|
)
|
||||||
|
except CredentialsValidateFailedError as ex:
|
||||||
|
raise ex
|
||||||
|
except Exception as ex:
|
||||||
|
logger.exception(f'{self.get_provider_schema().provider} credentials validate failed')
|
||||||
|
raise ex
|
@ -0,0 +1,29 @@
|
|||||||
|
provider: siliconflow
|
||||||
|
label:
|
||||||
|
zh_Hans: 硅基流动
|
||||||
|
en_US: SiliconFlow
|
||||||
|
icon_small:
|
||||||
|
en_US: siliconflow_square.svg
|
||||||
|
icon_large:
|
||||||
|
en_US: siliconflow.svg
|
||||||
|
background: "#ffecff"
|
||||||
|
help:
|
||||||
|
title:
|
||||||
|
en_US: Get your API Key from SiliconFlow
|
||||||
|
zh_Hans: 从 SiliconFlow 获取 API Key
|
||||||
|
url:
|
||||||
|
en_US: https://cloud.siliconflow.cn/keys
|
||||||
|
supported_model_types:
|
||||||
|
- llm
|
||||||
|
configurate_methods:
|
||||||
|
- predefined-model
|
||||||
|
provider_credential_schema:
|
||||||
|
credential_form_schemas:
|
||||||
|
- variable: api_key
|
||||||
|
label:
|
||||||
|
en_US: API Key
|
||||||
|
type: secret-input
|
||||||
|
required: true
|
||||||
|
placeholder:
|
||||||
|
zh_Hans: 在此输入您的 API Key
|
||||||
|
en_US: Enter your API Key
|
Loading…
x
Reference in New Issue
Block a user