Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepseek #31

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
DashScopeChatParameters,
DashScopeMultiModalChat,
DashScopeMultiModalChatParameters,
DeepSeekChat,
DeepSeekChatParameters,
HunyuanChat,
HunyuanChatParameters,
MinimaxChat,
MinimaxChatParameters,
MinimaxProChat,
MinimaxProChatParameters,
MoonshotChat,
MoonshotParameters,
MoonshotChatParameters,
OpenAIChat,
OpenAIChatParameters,
RemoteChatCompletionModel,
Expand Down Expand Up @@ -45,8 +47,10 @@
BaiduCreationSettings,
BailianSettings,
DashScopeSettings,
DeepSeekSettings,
HunyuanSettings,
MinimaxSettings,
MoonshotSettings,
OpenAISettings,
QianfanSettings,
ZhipuSettings,
Expand Down Expand Up @@ -98,7 +102,9 @@
'DashScopeMultiModalChat',
'DashScopeMultiModalChatParameters',
'MoonshotChat',
'MoonshotParameters',
'MoonshotChatParameters',
'DeepSeekChat',
'DeepSeekChatParameters',
'OpenAISpeech',
'OpenAISpeechParameters',
'MinimaxSpeech',
Expand All @@ -122,6 +128,8 @@
'BailianSettings',
'HunyuanSettings',
'DashScopeSettings',
'MoonshotSettings',
'DeepSeekSettings',
'function',
'load_chat_model',
'load_speech_model',
Expand Down
11 changes: 8 additions & 3 deletions generate/chat_completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
DashScopeChatParameters,
DashScopeMultiModalChat,
DashScopeMultiModalChatParameters,
DeepSeekChat,
DeepSeekChatParameters,
HunyuanChat,
HunyuanChatParameters,
MinimaxChat,
MinimaxChatParameters,
MinimaxProChat,
MinimaxProChatParameters,
MoonshotChat,
MoonshotParameters,
MoonshotChatParameters,
OpenAIChat,
OpenAIChatParameters,
WenxinChat,
Expand All @@ -48,7 +50,8 @@
(BailianChat, BailianChatParameters),
(DashScopeChat, DashScopeChatParameters),
(DashScopeMultiModalChat, DashScopeMultiModalChatParameters),
(MoonshotChat, MoonshotParameters),
(MoonshotChat, MoonshotChatParameters),
(DeepSeekChat, DashScopeChatParameters),
]

ChatModelRegistry: dict[str, tuple[Type[ChatCompletionModel], Type[ModelParameters]]] = {
Expand Down Expand Up @@ -86,7 +89,9 @@
'DashScopeMultiModalChat',
'DashScopeMultiModalChatParameters',
'MoonshotChat',
'MoonshotParameters',
'MoonshotChatParameters',
'DeepSeekChat',
'DeepSeekChatParameters',
'MessagePrinter',
'SimpleMessagePrinter',
'get_json_schema',
Expand Down
7 changes: 5 additions & 2 deletions generate/chat_completion/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
DashScopeMultiModalChat,
DashScopeMultiModalChatParameters,
)
from generate.chat_completion.models.deepseek import DeepSeekChat, DeepSeekChatParameters
from generate.chat_completion.models.hunyuan import HunyuanChat, HunyuanChatParameters
from generate.chat_completion.models.minimax import MinimaxChat, MinimaxChatParameters
from generate.chat_completion.models.minimax_pro import MinimaxProChat, MinimaxProChatParameters
from generate.chat_completion.models.moonshot import MoonshotChat, MoonshotParameters
from generate.chat_completion.models.moonshot import MoonshotChat, MoonshotChatParameters
from generate.chat_completion.models.openai import OpenAIChat, OpenAIChatParameters
from generate.chat_completion.models.wenxin import WenxinChat, WenxinChatParameters
from generate.chat_completion.models.zhipu import (
Expand Down Expand Up @@ -48,5 +49,7 @@
'DashScopeMultiModalChat',
'DashScopeMultiModalChatParameters',
'MoonshotChat',
'MoonshotParameters',
'MoonshotChatParameters',
'DeepSeekChat',
'DeepSeekChatParameters',
]
70 changes: 70 additions & 0 deletions generate/chat_completion/models/deepseek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import annotations

from typing import AsyncIterator, ClassVar, Iterator, List, Optional, Union

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 import OpenAIChat
from generate.http import HttpClient
from generate.model import ModelParameters, ModelParametersDict
from generate.platforms import DeepSeekSettings
from generate.types import Probability


class DeepSeekChatParameters(ModelParameters):
temperature: Optional[Annotated[float, Field(ge=0, le=2)]] = None
top_p: Optional[Probability] = None
max_tokens: Optional[PositiveInt] = None
frequency_penalty: Optional[Annotated[float, Field(ge=-2, le=2)]] = None
presence_penalty: Optional[Annotated[float, Field(ge=-2, le=2)]] = None
stop: Optional[Union[str, List[str]]] = None


class DeepSeekParametersDict(ModelParametersDict, total=False):
temperature: float
top_p: float
max_tokens: int
frequency_penalty: float
presence_penalty: float
stop: Union[str, List[str]]


class DeepSeekChat(OpenAIChat):
model_type: ClassVar[str] = 'deepseek'

parameters: DeepSeekChatParameters
settings: DeepSeekSettings

def __init__(
self,
model: str = 'deepseek-chat',
parameters: DeepSeekChatParameters | None = None,
settings: DeepSeekSettings | None = None,
http_client: HttpClient | None = None,
) -> None:
self.parameters = parameters or DeepSeekChatParameters()
self.settings = settings or DeepSeekSettings() # type: ignore
self.http_client = http_client or HttpClient()
self.model = model

@override
def generate(self, prompt: Prompt, **kwargs: Unpack[DeepSeekParametersDict]) -> ChatCompletionOutput:
return super().generate(prompt, **kwargs)

@override
async def async_generate(self, prompt: Prompt, **kwargs: Unpack[DeepSeekParametersDict]) -> ChatCompletionOutput:
return await super().async_generate(prompt, **kwargs)

@override
def stream_generate(self, prompt: Prompt, **kwargs: Unpack[DeepSeekParametersDict]) -> Iterator[ChatCompletionStreamOutput]:
yield from super().stream_generate(prompt, **kwargs)

@override
async def async_stream_generate(
self, prompt: Prompt, **kwargs: Unpack[DeepSeekParametersDict]
) -> AsyncIterator[ChatCompletionStreamOutput]:
async for i in super().async_stream_generate(prompt, **kwargs):
yield i
8 changes: 4 additions & 4 deletions generate/chat_completion/models/moonshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from generate.types import Probability, Temperature


class MoonshotParameters(ModelParameters):
class MoonshotChatParameters(ModelParameters):
temperature: Optional[Temperature] = None
top_p: Optional[Probability] = None
max_tokens: Optional[PositiveInt] = None
Expand All @@ -29,17 +29,17 @@ class MoonshotParametersDict(ModelParametersDict, total=False):
class MoonshotChat(OpenAIChat):
model_type: ClassVar[str] = 'moonshot'

parameters: MoonshotParameters
parameters: MoonshotChatParameters
settings: MoonshotSettings

def __init__(
self,
model: str = 'moonshot-v1-8k',
parameters: MoonshotParameters | None = None,
parameters: MoonshotChatParameters | None = None,
settings: MoonshotSettings | None = None,
http_client: HttpClient | None = None,
) -> None:
self.parameters = parameters or MoonshotParameters()
self.parameters = parameters or MoonshotChatParameters()
self.settings = settings or MoonshotSettings() # type: ignore
self.http_client = http_client or HttpClient()
self.model = model
Expand Down
2 changes: 2 additions & 0 deletions generate/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from generate.platforms.baidu import BaiduCreationSettings, QianfanSettings
from generate.platforms.bailian import BailianSettings
from generate.platforms.dashscope import DashScopeSettings
from generate.platforms.deepseek import DeepSeekSettings
from generate.platforms.hunyuan import HunyuanSettings
from generate.platforms.minimax import MinimaxSettings
from generate.platforms.moonshot import MoonshotSettings
Expand All @@ -21,4 +22,5 @@
'HunyuanSettings',
'DashScopeSettings',
'MoonshotSettings',
'DeepSeekSettings',
]
9 changes: 9 additions & 0 deletions generate/platforms/deepseek.py
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 DeepSeekSettings(BaseSettings):
model_config = SettingsConfigDict(extra='ignore', env_prefix='deepseek_', env_file='.env')

api_key: SecretStr
api_base: str = 'https://api.deepseek.com/v1'
2 changes: 2 additions & 0 deletions generate/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_avatars() -> List[Avatar]:
'zhipu': 'https://yuxin-wang.oss-cn-beijing.aliyuncs.com/uPic/HIntEu.png',
'baichuan': 'https://yuxin-wang.oss-cn-beijing.aliyuncs.com/uPic/fODcq1.png',
'moonshot': 'https://yuxin-wang.oss-cn-beijing.aliyuncs.com/uPic/hc2Ygt.png',
'deepseek': 'https://yuxin-wang.oss-cn-beijing.aliyuncs.com/uPic/SgdohV.png',
}
return [Avatar(name=k, url=v) for k, v in avatar_map.items()]

Expand All @@ -77,6 +78,7 @@ def get_generate_settings() -> List[Any]:
'baichuan',
'minimax_pro',
'moonshot',
'deepseek',
],
)
model_id = TextInput(
Expand Down
2 changes: 1 addition & 1 deletion generate/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.2'
__version__ = '0.3.2.post1'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "generate-core"
version = "0.3.2"
version = "0.3.2.post1"
description = "文本生成,图像生成,语音生成"
authors = ["wangyuxin <[email protected]>"]
license = "MIT"
Expand Down