diff --git a/README.md b/README.md index a6bef97..1822b48 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,12 @@ Generate 允许用户通过统一的 api 访问多平台的生成式模型,当 | 灵积 DashScope | ✅ | ✅ | ✅ | ✅ | ❌ | | 百川智能 Baichuan | ✅ | ✅ | ✅ | ❌ | ❌ | | Minimax | ✅ | ✅ | ✅ | ❌ | ✅ | -| 混元 Hunyuan | ✅ | ✅ | ✅ | ❌ | ✅ | +| 混元 Hunyuan | ✅ | ✅ | ✅ | ❌ | ❌ | | 智谱 Zhipu | ✅ | ✅ | ✅ | ✅ | ✅ | | 月之暗面 Moonshot| ✅ | ✅ | ✅ | ❌ | ❌ | | DeepSeek | ✅ | ✅ | ✅ | ❌ | ❌ | -| 零一万物 Yi | ✅ | ✅ | ✅ | ❌ | ❌ | +| 零一万物 Yi | ✅ | ✅ | ✅ | ✅ | ❌ | +| 阶跃星辰 StepFun | ✅ | ✅ | ✅ | ✅ | ❌ | ## Features diff --git a/generate/__init__.py b/generate/__init__.py index 0a18270..adbebbc 100644 --- a/generate/__init__.py +++ b/generate/__init__.py @@ -29,6 +29,8 @@ OpenAIChatParameters, Prompt, RemoteChatCompletionModel, + StepFunChat, + StepFunChatParameters, WenxinChat, WenxinChatParameters, YiChat, @@ -73,6 +75,7 @@ MoonshotSettings, OpenAISettings, QianfanSettings, + StepFunSettings, YiSettings, ZhipuSettings, ) @@ -105,6 +108,9 @@ 'ZhipuChatParameters', 'ZhipuCharacterChat', 'ZhipuCharacterChatParameters', + 'StepFunChat', + 'StepFunChatParameters', + 'StepFunSettings', 'WenxinChat', 'WenxinChatParameters', 'HunyuanChat', diff --git a/generate/chat_completion/__init__.py b/generate/chat_completion/__init__.py index c179414..3484b73 100644 --- a/generate/chat_completion/__init__.py +++ b/generate/chat_completion/__init__.py @@ -40,6 +40,8 @@ MoonshotChatParameters, OpenAIChat, OpenAIChatParameters, + StepFunChat, + StepFunChatParameters, WenxinChat, WenxinChatParameters, YiChat, @@ -70,6 +72,7 @@ (DashScopeMultiModalChat, DashScopeMultiModalChatParameters), (MoonshotChat, MoonshotChatParameters), (DeepSeekChat, DashScopeChatParameters), + (StepFunChat, StepFunChatParameters), (YiChat, YiChatParameters), ] @@ -107,6 +110,8 @@ 'BailianChatParameters', 'YiChat', 'YiChatParameters', + 'StepFunChat', + 'StepFunChatParameters', 'AnthropicChat', 'AnthropicChatParameters', 'DashScopeChat', diff --git a/generate/chat_completion/models/__init__.py b/generate/chat_completion/models/__init__.py index 246e6f1..44f5a2c 100644 --- a/generate/chat_completion/models/__init__.py +++ b/generate/chat_completion/models/__init__.py @@ -20,6 +20,7 @@ from generate.chat_completion.models.minimax_pro import MinimaxProChat, MinimaxProChatParameters from generate.chat_completion.models.moonshot import MoonshotChat, MoonshotChatParameters from generate.chat_completion.models.openai import OpenAIChat, OpenAIChatParameters +from generate.chat_completion.models.stepfun import StepFunChat, StepFunChatParameters from generate.chat_completion.models.wenxin import WenxinChat, WenxinChatParameters from generate.chat_completion.models.yi import YiChat, YiChatParameters from generate.chat_completion.models.zhipu import ( @@ -49,6 +50,8 @@ 'OpenAIChatParameters', 'WenxinChat', 'WenxinChatParameters', + 'StepFunChat', + 'StepFunChatParameters', 'YiChat', 'YiChatParameters', 'ZhipuChat', diff --git a/generate/chat_completion/models/stepfun.py b/generate/chat_completion/models/stepfun.py new file mode 100644 index 0000000..4f1d8ee --- /dev/null +++ b/generate/chat_completion/models/stepfun.py @@ -0,0 +1,72 @@ +from __future__ import annotations + +from typing import AsyncIterator, ClassVar, Iterator, List, Optional + +from pydantic import Field, PositiveInt +from typing_extensions import Annotated, Unpack, override + +from generate.chat_completion.message import Prompt +from generate.chat_completion.model_output import ChatCompletionOutput, ChatCompletionStreamOutput +from generate.chat_completion.models.openai_like import OpenAILikeChat +from generate.http import HttpClient +from generate.model import ModelParameters, RemoteModelParametersDict +from generate.platforms import StepFunSettings +from generate.types import Probability + +Temperature = Annotated[float, Field(ge=0, le=2)] + + +class StepFunChatParameters(ModelParameters): + temperature: Optional[Temperature] = None + top_p: Optional[Probability] = None + max_tokens: Optional[PositiveInt] = None + presence_penalty: Optional[Annotated[float, Field(ge=-2, le=2)]] = None + frequency_penalty: Optional[Annotated[float, Field(ge=-2, le=2)]] = None + + +class StepFunParametersDict(RemoteModelParametersDict, total=False): + temperature: Optional[Temperature] + top_p: Optional[Probability] + max_tokens: Optional[PositiveInt] + presence_penalty: Optional[float] + frequency_penalty: Optional[float] + + +class StepFunChat(OpenAILikeChat): + model_type: ClassVar[str] = 'stepfun' + available_models: ClassVar[List[str]] = ['step-1-32k', 'step-1v-32k', 'step-1-200k'] + + parameters: StepFunChatParameters + settings: StepFunSettings + + def __init__( + self, + model: str = 'step-1-32k', + parameters: StepFunChatParameters | None = None, + settings: StepFunSettings | None = None, + http_client: HttpClient | None = None, + ) -> None: + parameters = parameters or StepFunChatParameters() + settings = settings or StepFunSettings() # type: ignore + http_client = http_client or HttpClient() + model = model + super().__init__(model=model, parameters=parameters, settings=settings, http_client=http_client) + + @override + def generate(self, prompt: Prompt, **kwargs: Unpack[StepFunParametersDict]) -> ChatCompletionOutput: + return super().generate(prompt, **kwargs) + + @override + async def async_generate(self, prompt: Prompt, **kwargs: Unpack[StepFunParametersDict]) -> ChatCompletionOutput: + return await super().async_generate(prompt, **kwargs) + + @override + def stream_generate(self, prompt: Prompt, **kwargs: Unpack[StepFunParametersDict]) -> Iterator[ChatCompletionStreamOutput]: + yield from super().stream_generate(prompt, **kwargs) + + @override + async def async_stream_generate( + self, prompt: Prompt, **kwargs: Unpack[StepFunParametersDict] + ) -> AsyncIterator[ChatCompletionStreamOutput]: + async for stream_output in super().async_stream_generate(prompt, **kwargs): + yield stream_output diff --git a/generate/platforms/__init__.py b/generate/platforms/__init__.py index 419f133..e548507 100644 --- a/generate/platforms/__init__.py +++ b/generate/platforms/__init__.py @@ -10,6 +10,7 @@ from generate.platforms.minimax import MinimaxSettings from generate.platforms.moonshot import MoonshotSettings from generate.platforms.openai import OpenAISettings +from generate.platforms.stepfun import StepFunSettings from generate.platforms.yi import YiSettings from generate.platforms.zhipu import ZhipuSettings @@ -29,4 +30,5 @@ 'DeepSeekSettings', 'YiSettings', 'PlatformSettings', + 'StepFunSettings', ] diff --git a/generate/platforms/stepfun.py b/generate/platforms/stepfun.py new file mode 100644 index 0000000..93e2d14 --- /dev/null +++ b/generate/platforms/stepfun.py @@ -0,0 +1,12 @@ +from pydantic import SecretStr +from pydantic_settings import SettingsConfigDict + +from generate.platforms.openai_like import OpenAILikeSettings + + +class StepFunSettings(OpenAILikeSettings): + model_config = SettingsConfigDict(extra='ignore', env_prefix='stepfun_', env_file='.env') + + api_key: SecretStr + api_base: str = 'https://api.stepfun.com/v1' + platform_url: str = 'https://platform.stepfun.com/' diff --git a/generate/version.py b/generate/version.py index a987347..908c0bb 100644 --- a/generate/version.py +++ b/generate/version.py @@ -1 +1 @@ -__version__ = '0.4.2' +__version__ = '0.4.3' diff --git a/pyproject.toml b/pyproject.toml index 375a55e..8c87b36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "generate-core" -version = "0.4.2" +version = "0.4.3" description = "文本生成,图像生成,语音生成" authors = ["wangyuxin "] license = "MIT"