This commit is contained in:
2025-09-23 20:24:15 +08:00
commit bde8c44874
22 changed files with 846 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import logging
from collections.abc import Mapping
from dify_plugin import ModelProvider
logger = logging.getLogger(__name__)
class OpenAIProvider(ModelProvider):
def validate_provider_credentials(self, credentials: Mapping) -> None:
"""
Validate provider credentials
if validate failed, raise exception
:param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
"""
pass

View File

@@ -0,0 +1,276 @@
provider: openai_api_compatible
label:
en_US: OpenAI-API-compatible
description:
en_US: Model providers compatible with OpenAI's API standard, such as LM Studio.
zh_Hans: 兼容 OpenAI API 的模型供应商,例如 LM Studio 。
icon_small:
en_US: icon.svg
supported_model_types:
- llm
- rerank
- text-embedding
- speech2text
- tts
configurate_methods:
- customizable-model
model_credential_schema:
model:
label:
en_US: Model Name
zh_Hans: 模型名称
placeholder:
en_US: Enter full model name
zh_Hans: 输入模型全称
credential_form_schemas:
- variable: display_name
label:
en_US: Model display name
zh_Hans: 模型显示名称
type: text-input
required: false
placeholder:
zh_Hans: 模型在界面的显示名称
en_US: The display name of the model in the interface.
- variable: api_key
label:
en_US: API Key
type: secret-input
required: false
placeholder:
zh_Hans: 在此输入您的 API Key
en_US: Enter your API Key
- variable: endpoint_url
label:
zh_Hans: API endpoint URL
en_US: API endpoint URL
type: text-input
required: true
placeholder:
zh_Hans: Base URL, e.g. https://api.openai.com/v1
en_US: Base URL, e.g. https://api.openai.com/v1
- variable: endpoint_model_name
label:
zh_Hans: API endpoint中的模型名称
en_US: model name for API endpoint
type: text-input
required: false
placeholder:
zh_Hans: endpoint model name, e.g. chatgpt4.0
en_US: endpoint model name, e.g. chatgpt4.0
- variable: mode
show_on:
- variable: __model_type
value: llm
label:
en_US: Completion mode
type: select
required: false
default: chat
placeholder:
zh_Hans: 选择对话类型
en_US: Select completion mode
options:
- value: completion
label:
en_US: Completion
zh_Hans: 补全
- value: chat
label:
en_US: Chat
zh_Hans: 对话
- variable: context_size
label:
zh_Hans: 模型上下文长度
en_US: Model context size
required: true
show_on:
- variable: __model_type
value: llm
type: text-input
default: "4096"
placeholder:
zh_Hans: 在此输入您的模型上下文长度
en_US: Enter your Model context size
- variable: context_size
label:
zh_Hans: 模型上下文长度
en_US: Model context size
required: true
show_on:
- variable: __model_type
value: text-embedding
type: text-input
default: "4096"
placeholder:
zh_Hans: 在此输入您的模型上下文长度
en_US: Enter your Model context size
- variable: context_size
label:
zh_Hans: 模型上下文长度
en_US: Model context size
required: true
show_on:
- variable: __model_type
value: rerank
type: text-input
default: "4096"
placeholder:
zh_Hans: 在此输入您的模型上下文长度
en_US: Enter your Model context size
- variable: max_tokens_to_sample
label:
zh_Hans: 最大 token 上限
en_US: Upper bound for max tokens
show_on:
- variable: __model_type
value: llm
default: "4096"
type: text-input
- variable: agent_though_support
show_on:
- variable: __model_type
value: llm
label:
en_US: Agent Thought
type: select
required: false
default: not_supported
options:
- value: supported
label:
en_US: Support
zh_Hans: 支持
- value: not_supported
label:
en_US: Not Support
zh_Hans: 不支持
- variable: function_calling_type
show_on:
- variable: __model_type
value: llm
label:
en_US: Function calling
type: select
required: false
default: no_call
options:
- value: function_call
label:
en_US: Function Call
zh_Hans: Function Call
- value: tool_call
label:
en_US: Tool Call
zh_Hans: Tool Call
- value: no_call
label:
en_US: Not Support
zh_Hans: 不支持
- variable: stream_function_calling
show_on:
- variable: __model_type
value: llm
label:
en_US: Stream function calling
type: select
required: false
default: not_supported
options:
- value: supported
label:
en_US: Support
zh_Hans: 支持
- value: not_supported
label:
en_US: Not Support
zh_Hans: 不支持
- variable: vision_support
show_on:
- variable: __model_type
value: llm
label:
zh_Hans: Vision 支持
en_US: Vision Support
type: select
required: false
default: no_support
options:
- value: support
label:
en_US: Support
zh_Hans: 支持
- value: no_support
label:
en_US: Not Support
zh_Hans: 不支持
- variable: structured_output_support
show_on:
- variable: __model_type
value: llm
label:
en_US: Structured Output
type: select
required: false
default: not_supported
options:
- value: supported
label:
en_US: Support
zh_Hans: 支持
- value: not_supported
label:
en_US: Not Support
zh_Hans: 不支持
- variable: stream_mode_auth
show_on:
- variable: __model_type
value: llm
label:
en_US: Stream mode auth
type: select
required: false
default: not_use
options:
- value: use
label:
en_US: Use
zh_Hans: 使用
- value: not_use
label:
en_US: Not Use
zh_Hans: 不使用
- variable: stream_mode_delimiter
label:
zh_Hans: 流模式返回结果的分隔符
en_US: Delimiter for streaming results
show_on:
- variable: __model_type
value: llm
default: '\n\n'
type: text-input
- variable: voices
show_on:
- variable: __model_type
value: tts
label:
en_US: Available Voices (comma-separated)
zh_Hans: 可用声音(用英文逗号分隔)
type: text-input
required: false
default: "alloy"
placeholder:
en_US: "alloy,echo,fable,onyx,nova,shimmer"
zh_Hans: "alloy,echo,fable,onyx,nova,shimmer"
help:
en_US: "List voice names separated by commas. First voice will be used as default."
zh_Hans: "用英文逗号分隔的声音列表。第一个声音将作为默认值。"
extra:
python:
provider_source: provider/openai_api_compatible.py
model_sources:
- "models/llm/llm.py"
- "models/text_embedding/text_embedding.py"
- "models/rerank/rerank.py"
- "models/speech2text/speech2text.py"
- "models/tts/tts.py"