-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add StepFunChat and StepFunSettings classes * Update version and add new model --------- Co-authored-by: wangyuxin <[email protected]> Co-authored-by: wangyuxin <[email protected]>
- Loading branch information
1 parent
cf78931
commit 452cb46
Showing
9 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.4.2' | ||
__version__ = '0.4.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "generate-core" | ||
version = "0.4.2" | ||
version = "0.4.3" | ||
description = "文本生成,图像生成,语音生成" | ||
authors = ["wangyuxin <[email protected]>"] | ||
license = "MIT" | ||
|