-
Notifications
You must be signed in to change notification settings - Fork 684
ff #2239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ff #2239
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,11 +10,50 @@ | |||||
| ModelType, | ||||||
| ParameterRule, | ||||||
| ParameterType, | ||||||
| DefaultParameterName, | ||||||
| ) | ||||||
| from dify_plugin.entities.model.llm import LLMMode, LLMResult | ||||||
| from dify_plugin.entities.model.message import PromptMessage, PromptMessageTool | ||||||
|
|
||||||
|
|
||||||
| class RecommendModelSchema: | ||||||
| """ | ||||||
| This is not a post-patch override. | ||||||
| Parameters manually set by the user have a higher priority than this. | ||||||
| """ | ||||||
|
|
||||||
| @staticmethod | ||||||
| def set_deepseek_v32(entity: AIModelEntity): | ||||||
| pending_features = [ | ||||||
| ModelFeature.TOOL_CALL, | ||||||
| ModelFeature.MULTI_TOOL_CALL, | ||||||
| ModelFeature.STREAM_TOOL_CALL, | ||||||
| ModelFeature.AGENT_THOUGHT, | ||||||
| ] | ||||||
|
Comment on lines
+27
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
|
||||||
| # Add missing features | ||||||
| for feature in pending_features: | ||||||
| if feature not in entity.features: | ||||||
| entity.features.append(feature) | ||||||
|
|
||||||
| # Set JSON schema to default | ||||||
| entity.parameter_rules.append( | ||||||
| ParameterRule( | ||||||
| name=DefaultParameterName.JSON_SCHEMA.value, | ||||||
| use_template=DefaultParameterName.JSON_SCHEMA.value, | ||||||
| ) # type: ignore | ||||||
| ) | ||||||
|
|
||||||
| # Set temperature to 1.0 | ||||||
| for rule in entity.parameter_rules: | ||||||
| if rule.name == DefaultParameterName.TEMPERATURE.value: | ||||||
| rule.default = 1.0 | ||||||
|
|
||||||
| @staticmethod | ||||||
| def patch_siliconflow_default(entity: AIModelEntity): | ||||||
| pass | ||||||
|
|
||||||
|
|
||||||
| class SiliconflowLargeLanguageModel(OAICompatLargeLanguageModel): | ||||||
| def _invoke( | ||||||
| self, | ||||||
|
|
@@ -41,86 +80,90 @@ def validate_credentials(self, model: str, credentials: dict) -> None: | |||||
| def _add_custom_parameters(cls, credentials: dict) -> None: | ||||||
| credentials["mode"] = "chat" | ||||||
| credentials["endpoint_url"] = "https://api.siliconflow.cn/v1" | ||||||
|
|
||||||
| def _add_function_call(self, model: str, credentials: dict) -> None: | ||||||
| model_schema = self.get_model_schema(model, credentials) | ||||||
| if model_schema and {ModelFeature.TOOL_CALL, ModelFeature.MULTI_TOOL_CALL}.intersection( | ||||||
| model_schema.features or [] | ||||||
| ): | ||||||
| credentials["function_calling_type"] = "tool_call" | ||||||
|
|
||||||
| def get_customizable_model_schema( | ||||||
| self, model: str, credentials: dict | ||||||
| ) -> Optional[AIModelEntity]: | ||||||
| return AIModelEntity( | ||||||
| model=model, | ||||||
| label=I18nObject(en_US=model, zh_Hans=model), | ||||||
| model_type=ModelType.LLM, | ||||||
| features=( | ||||||
| [ | ||||||
| ModelFeature.TOOL_CALL, | ||||||
| ModelFeature.MULTI_TOOL_CALL, | ||||||
| ModelFeature.STREAM_TOOL_CALL, | ||||||
| ] | ||||||
| if credentials.get("function_calling_type") == "tool_call" | ||||||
| else [] | ||||||
| ), | ||||||
| fetch_from=FetchFrom.CUSTOMIZABLE_MODEL, | ||||||
| model_properties={ | ||||||
| ModelPropertyKey.CONTEXT_SIZE: int( | ||||||
| credentials.get("context_size", 8000) | ||||||
| ), | ||||||
| ModelPropertyKey.MODE: LLMMode.CHAT.value, | ||||||
| }, | ||||||
| parameter_rules=[ | ||||||
| ParameterRule( | ||||||
| name="temperature", | ||||||
| use_template="temperature", | ||||||
| label=I18nObject(en_US="Temperature", zh_Hans="温度"), | ||||||
| type=ParameterType.FLOAT, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="max_tokens", | ||||||
| use_template="max_tokens", | ||||||
| default=4096, | ||||||
| min=1, | ||||||
| max=int(credentials.get("max_tokens", 16384)), | ||||||
| label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"), | ||||||
| type=ParameterType.INT, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="top_p", | ||||||
| use_template="top_p", | ||||||
| label=I18nObject(en_US="Top P", zh_Hans="Top P"), | ||||||
| type=ParameterType.FLOAT, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="top_k", | ||||||
| use_template="top_k", | ||||||
| label=I18nObject(en_US="Top K", zh_Hans="Top K"), | ||||||
| type=ParameterType.FLOAT, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="frequency_penalty", | ||||||
| use_template="frequency_penalty", | ||||||
| label=I18nObject(en_US="Frequency Penalty", zh_Hans="重复惩罚"), | ||||||
| type=ParameterType.FLOAT, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="enable_thinking", | ||||||
| use_template="enable_thinking", | ||||||
| default=True, | ||||||
| label=I18nObject(en_US="Thinking mode", zh_Hans="启用思考模式"), | ||||||
| type=ParameterType.BOOLEAN, | ||||||
| ), | ||||||
| ParameterRule( | ||||||
| name="thinking_budget", | ||||||
| use_template="thinking_budget", | ||||||
| default=512, | ||||||
| min=1, | ||||||
| max=int(credentials.get("thinking_budget", 8192)), | ||||||
| label=I18nObject(en_US="Thinking budget", zh_Hans="思考长度限制"), | ||||||
| type=ParameterType.INT, | ||||||
| ), | ||||||
| ], | ||||||
| ) | ||||||
| entity = super().get_customizable_model_schema(model, credentials) | ||||||
|
|
||||||
| print(entity) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| if model in ["deepseek-ai/DeepSeek-V3.2", "Pro/deepseek-ai/DeepSeek-V3.2"]: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better maintainability and performance, consider defining these model names as a module-level
Suggested change
|
||||||
| RecommendModelSchema.set_deepseek_v32(entity) | ||||||
| return entity | ||||||
| # return AIModelEntity( | ||||||
| # model=model, | ||||||
| # label=I18nObject(en_US=model, zh_Hans=model), | ||||||
| # model_type=ModelType.LLM, | ||||||
| # features=( | ||||||
| # [ | ||||||
| # ModelFeature.TOOL_CALL, | ||||||
| # ModelFeature.MULTI_TOOL_CALL, | ||||||
| # ModelFeature.STREAM_TOOL_CALL, | ||||||
| # ] | ||||||
| # if credentials.get("function_calling_type") == "tool_call" | ||||||
| # else [] | ||||||
| # ), | ||||||
| # fetch_from=FetchFrom.CUSTOMIZABLE_MODEL, | ||||||
| # model_properties={ | ||||||
| # ModelPropertyKey.CONTEXT_SIZE: int(credentials.get("context_size", 8000)), | ||||||
| # ModelPropertyKey.MODE: LLMMode.CHAT.value, | ||||||
| # }, | ||||||
| # parameter_rules=[ | ||||||
| # ParameterRule( | ||||||
| # name="temperature", | ||||||
| # use_template="temperature", | ||||||
| # label=I18nObject(en_US="Temperature", zh_Hans="温度"), | ||||||
| # type=ParameterType.FLOAT, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="max_tokens", | ||||||
| # use_template="max_tokens", | ||||||
| # default=4096, | ||||||
| # min=1, | ||||||
| # max=int(credentials.get("max_tokens", 16384)), | ||||||
| # label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"), | ||||||
| # type=ParameterType.INT, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="top_p", | ||||||
| # use_template="top_p", | ||||||
| # label=I18nObject(en_US="Top P", zh_Hans="Top P"), | ||||||
| # type=ParameterType.FLOAT, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="top_k", | ||||||
| # use_template="top_k", | ||||||
| # label=I18nObject(en_US="Top K", zh_Hans="Top K"), | ||||||
| # type=ParameterType.FLOAT, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="frequency_penalty", | ||||||
| # use_template="frequency_penalty", | ||||||
| # label=I18nObject(en_US="Frequency Penalty", zh_Hans="重复惩罚"), | ||||||
| # type=ParameterType.FLOAT, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="enable_thinking", | ||||||
| # use_template="enable_thinking", | ||||||
| # default=True, | ||||||
| # label=I18nObject(en_US="Thinking mode", zh_Hans="启用思考模式"), | ||||||
| # type=ParameterType.BOOLEAN, | ||||||
| # ), | ||||||
| # ParameterRule( | ||||||
| # name="thinking_budget", | ||||||
| # use_template="thinking_budget", | ||||||
| # default=512, | ||||||
| # min=1, | ||||||
| # max=int(credentials.get("thinking_budget", 8192)), | ||||||
| # label=I18nObject(en_US="Thinking budget", zh_Hans="思考长度限制"), | ||||||
| # type=ParameterType.INT, | ||||||
| # ), | ||||||
| # ], | ||||||
| # ) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help text for
temperatureappears to be incorrect. It mentions "Gemini 3", but this configuration is for a DeepSeek model. This was likely a copy-paste error and should be corrected to refer to the correct model to avoid confusing users.