-
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 moonshot * Update version --------- Co-authored-by: wangyuxin <[email protected]>
- Loading branch information
1 parent
690fbf1
commit 3fbc9a2
Showing
12 changed files
with
110 additions
and
14 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
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,64 @@ | ||
from __future__ import annotations | ||
|
||
from typing import AsyncIterator, ClassVar, Iterator, Optional | ||
|
||
from pydantic import PositiveInt | ||
from typing_extensions import Unpack, override | ||
|
||
from generate.chat_completion.message import Prompt | ||
from generate.chat_completion.model_output import ChatCompletionOutput, ChatCompletionStreamOutput | ||
from generate.chat_completion.models.openai import OpenAIChat | ||
from generate.http import HttpClient | ||
from generate.model import ModelParameters, ModelParametersDict | ||
from generate.platforms import MoonshotSettings | ||
from generate.types import Probability, Temperature | ||
|
||
|
||
class MoonshotParameters(ModelParameters): | ||
temperature: Optional[Temperature] = None | ||
top_p: Optional[Probability] = None | ||
max_tokens: Optional[PositiveInt] = None | ||
|
||
|
||
class MoonshotParametersDict(ModelParametersDict, total=False): | ||
temperature: Temperature | ||
top_p: Probability | ||
max_tokens: PositiveInt | ||
|
||
|
||
class MoonshotChat(OpenAIChat): | ||
model_type: ClassVar[str] = 'moonshot' | ||
|
||
parameters: MoonshotParameters | ||
settings: MoonshotSettings | ||
|
||
def __init__( | ||
self, | ||
model: str = 'moonshot-v1-8k', | ||
parameters: MoonshotParameters | None = None, | ||
settings: MoonshotSettings | None = None, | ||
http_client: HttpClient | None = None, | ||
) -> None: | ||
self.parameters = parameters or MoonshotParameters() | ||
self.settings = settings or MoonshotSettings() # type: ignore | ||
self.http_client = http_client or HttpClient() | ||
self.model = model | ||
|
||
@override | ||
def generate(self, prompt: Prompt, **kwargs: Unpack[MoonshotParametersDict]) -> ChatCompletionOutput: | ||
return super().generate(prompt, **kwargs) | ||
|
||
@override | ||
async def async_generate(self, prompt: Prompt, **kwargs: Unpack[MoonshotParametersDict]) -> ChatCompletionOutput: | ||
return await super().async_generate(prompt, **kwargs) | ||
|
||
@override | ||
def stream_generate(self, prompt: Prompt, **kwargs: Unpack[MoonshotParametersDict]) -> Iterator[ChatCompletionStreamOutput]: | ||
yield from super().stream_generate(prompt, **kwargs) | ||
|
||
@override | ||
async def async_stream_generate( | ||
self, prompt: Prompt, **kwargs: Unpack[MoonshotParametersDict] | ||
) -> AsyncIterator[ChatCompletionStreamOutput]: | ||
async for i in super().async_stream_generate(prompt, **kwargs): | ||
yield i |
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,9 @@ | ||
from pydantic import SecretStr | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class MoonshotSettings(BaseSettings): | ||
model_config = SettingsConfigDict(extra='ignore', env_prefix='moonshot_', env_file='.env') | ||
|
||
api_key: SecretStr | ||
api_base: str = 'https://api.moonshot.cn/v1' |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.3.1' | ||
__version__ = '0.3.2' |
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.3.1" | ||
version = "0.3.2" | ||
description = "文本生成,图像生成,语音生成" | ||
authors = ["wangyuxin <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -40,7 +40,6 @@ select = [ | |
"T", | ||
"PT", | ||
"RET", | ||
"PL", | ||
"TRY", | ||
"PERF", | ||
] | ||
|
@@ -52,10 +51,8 @@ ignore = [ | |
"A003", # shadow builtin | ||
"ANN1", # self and cls | ||
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in | ||
"PLR0913", # Too many arguments in function definition | ||
"TRY003", # Avoid specifying long messages outside the exception class | ||
"PLC0414", # reimport | ||
'PLR0912', # too many branches | ||
] | ||
exclude = ["playground", "api_docs"] | ||
target-version = "py38" | ||
|