Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

update stepfun model (#7118)

forrestlinfeng07511dfaf48a
diff --git a/api/core/model_runtime/model_providers/stepfun/llm/_position.yaml b/api/core/model_runtime/model_providers/stepfun/llm/_position.yaml
index b34433e1d4d..2bb0c703f4a 100644
--- a/api/core/model_runtime/model_providers/stepfun/llm/_position.yaml
+++ b/api/core/model_runtime/model_providers/stepfun/llm/_position.yaml
@@ -2,5 +2,7 @@
- step-1-32k
- step-1-128k
- step-1-256k
+- step-1-flash
+- step-2-16k
- step-1v-8k
- step-1v-32k
diff --git a/api/core/model_runtime/model_providers/stepfun/llm/step-1-flash.yaml b/api/core/model_runtime/model_providers/stepfun/llm/step-1-flash.yaml
new file mode 100644
index 00000000000..afb880f2a40
--- /dev/null
+++ b/api/core/model_runtime/model_providers/stepfun/llm/step-1-flash.yaml
@@ -0,0 +1,25 @@
+model: step-1-flash
+label:
+ zh_Hans: step-1-flash
+ en_US: step-1-flash
+model_type: llm
+features:
+ - agent-thought
+model_properties:
+ mode: chat
+ context_size: 8000
+parameter_rules:
+ - name: temperature
+ use_template: temperature
+ - name: top_p
+ use_template: top_p
+ - name: max_tokens
+ use_template: max_tokens
+ default: 512
+ min: 1
+ max: 8000
+pricing:
+ input: '0.001'
+ output: '0.004'
+ unit: '0.001'
+ currency: RMB
diff --git a/api/core/model_runtime/model_providers/stepfun/llm/step-1v-32k.yaml b/api/core/model_runtime/model_providers/stepfun/llm/step-1v-32k.yaml
index f878ee3e56e..08d6ad245d2 100644
--- a/api/core/model_runtime/model_providers/stepfun/llm/step-1v-32k.yaml
+++ b/api/core/model_runtime/model_providers/stepfun/llm/step-1v-32k.yaml
@@ -5,6 +5,9 @@ label:
model_type: llm
features:
- vision
+ - tool-call
+ - multi-tool-call
+ - stream-tool-call
model_properties:
mode: chat
context_size: 32000
diff --git a/api/core/model_runtime/model_providers/stepfun/llm/step-1v-8k.yaml b/api/core/model_runtime/model_providers/stepfun/llm/step-1v-8k.yaml
index 6c3cb61d2c6..843d14d9c67 100644
--- a/api/core/model_runtime/model_providers/stepfun/llm/step-1v-8k.yaml
+++ b/api/core/model_runtime/model_providers/stepfun/llm/step-1v-8k.yaml
@@ -5,6 +5,9 @@ label:
model_type: llm
features:
- vision
+ - tool-call
+ - multi-tool-call
+ - stream-tool-call
model_properties:
mode: chat
context_size: 8192
diff --git a/api/core/model_runtime/model_providers/stepfun/llm/step-2-16k.yaml b/api/core/model_runtime/model_providers/stepfun/llm/step-2-16k.yaml
new file mode 100644
index 00000000000..6f2dabbfb0e
--- /dev/null
+++ b/api/core/model_runtime/model_providers/stepfun/llm/step-2-16k.yaml
@@ -0,0 +1,28 @@
+model: step-2-16k
+label:
+ zh_Hans: step-2-16k
+ en_US: step-2-16k
+model_type: llm
+features:
+ - agent-thought
+ - tool-call
+ - multi-tool-call
+ - stream-tool-call
+model_properties:
+ mode: chat
+ context_size: 16000
+parameter_rules:
+ - name: temperature
+ use_template: temperature
+ - name: top_p
+ use_template: top_p
+ - name: max_tokens
+ use_template: max_tokens
+ default: 1024
+ min: 1
+ max: 16000
+pricing:
+ input: '0.038'
+ output: '0.120'
+ unit: '0.001'
+ currency: RMB
diff --git a/api/core/tools/provider/builtin/stepfun/__init__.py b/api/core/tools/provider/builtin/stepfun/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/api/core/tools/provider/builtin/stepfun/_assets/icon.png b/api/core/tools/provider/builtin/stepfun/_assets/icon.png
new file mode 100644
index 00000000000..85b96d0c74c
Binary files /dev/null and b/api/core/tools/provider/builtin/stepfun/_assets/icon.png differ
diff --git a/api/core/tools/provider/builtin/stepfun/stepfun.py b/api/core/tools/provider/builtin/stepfun/stepfun.py
new file mode 100644
index 00000000000..e809b04546a
--- /dev/null
+++ b/api/core/tools/provider/builtin/stepfun/stepfun.py
@@ -0,0 +1,25 @@
+from typing import Any
+
+from core.tools.errors import ToolProviderCredentialValidationError
+from core.tools.provider.builtin.stepfun.tools.image import StepfunTool
+from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
+
+
+class StepfunProvider(BuiltinToolProviderController):
+ def _validate_credentials(self, credentials: dict[str, Any]) -> None:
+ try:
+ StepfunTool().fork_tool_runtime(
+ runtime={
+ "credentials": credentials,
+ }
+ ).invoke(
+ user_id='',
+ tool_parameters={
+ "prompt": "cute girl, blue eyes, white hair, anime style",
+ "size": "1024x1024",
+ "n": 1
+ },
+ )
+ except Exception as e:
+ raise ToolProviderCredentialValidationError(str(e))
+
\ No newline at end of file
diff --git a/api/core/tools/provider/builtin/stepfun/stepfun.yaml b/api/core/tools/provider/builtin/stepfun/stepfun.yaml
new file mode 100644
index 00000000000..1f841ec369b
--- /dev/null
+++ b/api/core/tools/provider/builtin/stepfun/stepfun.yaml
@@ -0,0 +1,46 @@
+identity:
+ author: Stepfun
+ name: stepfun
+ label:
+ en_US: Image-1X
+ zh_Hans: 阶跃星辰绘画
+ pt_BR: Image-1X
+ description:
+ en_US: Image-1X
+ zh_Hans: 阶跃星辰绘画
+ pt_BR: Image-1X
+ icon: icon.png
+ tags:
+ - image
+ - productivity
+credentials_for_provider:
+ stepfun_api_key:
+ type: secret-input
+ required: true
+ label:
+ en_US: Stepfun API key
+ zh_Hans: 阶跃星辰API key
+ pt_BR: Stepfun API key
+ help:
+ en_US: Please input your stepfun API key
+ zh_Hans: 请输入你的阶跃星辰 API key
+ pt_BR: Please input your stepfun API key
+ placeholder:
+ en_US: Please input your stepfun API key
+ zh_Hans: 请输入你的阶跃星辰 API key
+ pt_BR: Please input your stepfun API key
+ stepfun_base_url:
+ type: text-input
+ required: false
+ label:
+ en_US: Stepfun base URL
+ zh_Hans: 阶跃星辰 base URL
+ pt_BR: Stepfun base URL
+ help:
+ en_US: Please input your Stepfun base URL
+ zh_Hans: 请输入你的阶跃星辰 base URL
+ pt_BR: Please input your Stepfun base URL
+ placeholder:
+ en_US: Please input your Stepfun base URL
+ zh_Hans: 请输入你的阶跃星辰 base URL
+ pt_BR: Please input your Stepfun base URL
diff --git a/api/core/tools/provider/builtin/stepfun/tools/image.py b/api/core/tools/provider/builtin/stepfun/tools/image.py
new file mode 100644
index 00000000000..5e544aada63
--- /dev/null
+++ b/api/core/tools/provider/builtin/stepfun/tools/image.py
@@ -0,0 +1,72 @@
+import random
+from typing import Any, Union
+
+from openai import OpenAI
+from yarl import URL
+
+from core.tools.entities.tool_entities import ToolInvokeMessage
+from core.tools.tool.builtin_tool import BuiltinTool
+
+
+class StepfunTool(BuiltinTool):
+ """ Stepfun Image Generation Tool """
+ def _invoke(self,
+ user_id: str,
+ tool_parameters: dict[str, Any],
+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
+ """
+ invoke tools
+ """
+ base_url = self.runtime.credentials.get('stepfun_base_url', None)
+ if not base_url:
+ base_url = None
+ else:
+ base_url = str(URL(base_url) / 'v1')
+
+ client = OpenAI(
+ api_key=self.runtime.credentials['stepfun_api_key'],
+ base_url=base_url,
+ )
+
+ extra_body = {}
+ model = tool_parameters.get('model', 'step-1x-medium')
+ if not model:
+ return self.create_text_message('Please input model name')
+ # prompt
+ prompt = tool_parameters.get('prompt', '')
+ if not prompt:
+ return self.create_text_message('Please input prompt')
+
+ seed = tool_parameters.get('seed', 0)
+ if seed > 0:
+ extra_body['seed'] = seed
+ steps = tool_parameters.get('steps', 0)
+ if steps > 0:
+ extra_body['steps'] = steps
+ negative_prompt = tool_parameters.get('negative_prompt', '')
+ if negative_prompt:
+ extra_body['negative_prompt'] = negative_prompt
+
+ # call openapi stepfun model
+ response = client.images.generate(
+ prompt=prompt,
+ model=model,
+ size=tool_parameters.get('size', '1024x1024'),
+ n=tool_parameters.get('n', 1),
+ extra_body= extra_body
+ )
+ print(response)
+
+ result = []
+ for image in response.data:
+ result.append(self.create_image_message(image=image.url))
+ result.append(self.create_json_message({
+ "url": image.url,
+ }))
+ return result
+
+ @staticmethod
+ def _generate_random_id(length=8):
+ characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
+ random_id = ''.join(random.choices(characters, k=length))
+ return random_id
diff --git a/api/core/tools/provider/builtin/stepfun/tools/image.yaml b/api/core/tools/provider/builtin/stepfun/tools/image.yaml
new file mode 100644
index 00000000000..1e20b157aa1
--- /dev/null
+++ b/api/core/tools/provider/builtin/stepfun/tools/image.yaml
@@ -0,0 +1,158 @@
+identity:
+ name: stepfun
+ author: Stepfun
+ label:
+ en_US: step-1x
+ zh_Hans: 阶跃星辰绘画
+ pt_BR: step-1x
+ description:
+ en_US: step-1x is a powerful drawing tool by stepfun, you can draw the image based on your prompt
+ zh_Hans: step-1x 系列是阶跃星辰提供的强大的绘画工具,它可以根据您的提示词绘制出您想要的图像。
+ pt_BR: step-1x is a powerful drawing tool by stepfun, you can draw the image based on your prompt
+description:
+ human:
+ en_US: step-1x is a text to image tool
+ zh_Hans: step-1x 是一个文本/图像到图像的工具
+ pt_BR: step-1x is a text to image tool
+ llm: step-1x is a tool used to generate images from text or image
+parameters:
+ - name: prompt
+ type: string
+ required: true
+ label:
+ en_US: Prompt
+ zh_Hans: 提示词
+ pt_BR: Prompt
+ human_description:
+ en_US: Image prompt, you can check the official documentation of step-1x
+ zh_Hans: 图像提示词,您可以查看step-1x 的官方文档
+ pt_BR: Image prompt, you can check the official documentation of step-1x
+ llm_description: Image prompt of step-1x you should describe the image you want to generate as a list of words as possible as detailed
+ form: llm
+ - name: model
+ type: select
+ required: false
+ human_description:
+ en_US: used for selecting the model name
+ zh_Hans: 用于选择模型的名字
+ pt_BR: used for selecting the model name
+ label:
+ en_US: Model Name
+ zh_Hans: 模型名字
+ pt_BR: Model Name
+ form: form
+ options:
+ - value: step-1x-turbo
+ label:
+ en_US: turbo
+ zh_Hans: turbo
+ pt_BR: turbo
+ - value: step-1x-medium
+ label:
+ en_US: medium
+ zh_Hans: medium
+ pt_BR: medium
+ - value: step-1x-large
+ label:
+ en_US: large
+ zh_Hans: large
+ pt_BR: large
+ default: step-1x-medium
+ - name: size
+ type: select
+ required: false
+ human_description:
+ en_US: used for selecting the image size
+ zh_Hans: 用于选择图像大小
+ pt_BR: used for selecting the image size
+ label:
+ en_US: Image size
+ zh_Hans: 图像大小
+ pt_BR: Image size
+ form: form
+ options:
+ - value: 256x256
+ label:
+ en_US: 256x256
+ zh_Hans: 256x256
+ pt_BR: 256x256
+ - value: 512x512
+ label:
+ en_US: 512x512
+ zh_Hans: 512x512
+ pt_BR: 512x512
+ - value: 768x768
+ label:
+ en_US: 768x768
+ zh_Hans: 768x768
+ pt_BR: 768x768
+ - value: 1024x1024
+ label:
+ en_US: 1024x1024
+ zh_Hans: 1024x1024
+ pt_BR: 1024x1024
+ - value: 1280x800
+ label:
+ en_US: 1280x800
+ zh_Hans: 1280x800
+ pt_BR: 1280x800
+ - value: 800x1280
+ label:
+ en_US: 800x1280
+ zh_Hans: 800x1280
+ pt_BR: 800x1280
+ default: 1024x1024
+ - name: n
+ type: number
+ required: true
+ human_description:
+ en_US: used for selecting the number of images
+ zh_Hans: 用于选择图像数量
+ pt_BR: used for selecting the number of images
+ label:
+ en_US: Number of images
+ zh_Hans: 图像数量
+ pt_BR: Number of images
+ form: form
+ default: 1
+ min: 1
+ max: 10
+ - name: seed
+ type: number
+ required: false
+ label:
+ en_US: seed
+ zh_Hans: seed
+ pt_BR: seed
+ human_description:
+ en_US: seed
+ zh_Hans: seed
+ pt_BR: seed
+ form: form
+ default: 10
+ - name: steps
+ type: number
+ required: false
+ label:
+ en_US: Steps
+ zh_Hans: Steps
+ pt_BR: Steps
+ human_description:
+ en_US: Steps
+ zh_Hans: Steps
+ pt_BR: Steps
+ form: form
+ default: 10
+ - name: negative_prompt
+ type: string
+ required: false
+ label:
+ en_US: Negative prompt
+ zh_Hans: Negative prompt
+ pt_BR: Negative prompt
+ human_description:
+ en_US: Negative prompt
+ zh_Hans: Negative prompt
+ pt_BR: Negative prompt
+ form: form
+ default: (worst quality:1.3), (nsfw), low quality