update stepfun model (#7118)
Co-authored-by: chenlinfeng <chenlinfeng@step.ai> Co-authored-by: Tfsh <tianfs_fight@163.com>pull/7124/head
parent
7944ce0594
commit
07511dfaf4
@ -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
|
||||||
@ -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
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@ -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))
|
||||||
|
|
||||||
@ -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
|
||||||
@ -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
|
||||||
Loading…
Reference in New Issue