Skip to content

Commit

Permalink
V0.5.0-beta (#66)
Browse files Browse the repository at this point in the history
* 添加 Disk Cache
* 添加 TypeAdapter
* 清理过期代码
* 清理冗余
* 修改 readme

---------

Co-authored-by: wangyuxin <wangyuxinwhy@gmail.com>
Co-authored-by: wangyuxin <wangyuxin@mokahr.com>
  • Loading branch information
3 people authored May 23, 2024
1 parent 426f9c4 commit 9ad52cf
Show file tree
Hide file tree
Showing 65 changed files with 1,469 additions and 4,140 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,38 @@
<br>
<br>

# 简介

> [!IMPORTANT]
> generate v0.5.0 版本的设计思路发生较大变化。由于个人精力有限,generate 不再追求支持更多的平台,而是更多的围绕模型的辅助功能进行开发。另外,国内大部分平台已经提供了适配 OpenAI SDK 的 API,如果你只需要基础的文本生成功能,建议直接使用 OpenAI SDK。
# 简介

Generate 允许用户通过统一的 api 访问多平台的生成式模型,当前支持:

| 平台 🤖 | 同步 🔄 | 异步 ⏳ | 流式 🌊 | Vision 👀 | Tools 🛠️ |
| ----------------- | ------- | ------- | ------- | --------- | -------- |
| OpenAI ||||||
| Azure ||||||
| Anthropic ||||||
| 文心 Wenxin ||||||
| 百炼 Bailian ||||||
| 灵积 DashScope ||||||
| 百川智能 Baichuan ||||||
| Minimax ||||||
| 混元 Hunyuan ||||||
| 智谱 Zhipu ||||||
| 月之暗面 Moonshot ||||||
| DeepSeek ||||||
| 零一万物 Yi ||||||
| 阶跃星辰 StepFun ||||||
| 平台 🤖 | 同步 🔄 | 异步 ⏳ | 流式 🌊 | Vision 👀 | Tools 🛠️ |
| ------------------- | ------- | ------- | ------- | --------- | -------- |
| OpenAI ||||||
| Azure ||||||
| Anthropic ||||||
| 文心 Wenxin ||||||
| 灵积/百炼 DashScope ||||||
| 百川智能 Baichuan ||||||
| Minimax ||||||
| 混元 Hunyuan ||||||
| 智谱 Zhipu ||||||
| 月之暗面 Moonshot ||||||
| DeepSeek ||||||
| 零一万物 Yi ||||||
| 阶跃星辰 StepFun ||||||

> v0.5.0-beta 版本中,混元,文心尚未适配
## Features

- **多模态**,支持文本生成,多模态文本生成,结构体生成,图像生成,语音生成...
- **跨平台**,支持 OpenAI,Azure,Minimax,智谱,月之暗面,文心一言 在内的国内外 10+ 平台
- **One API**,统一了不同平台的消息格式,推理参数,接口封装,返回解析,让用户无需关心不同平台的差异
- **异步,流式和并发**,提供流式调用,非流式调用,同步调用,异步调用,异步批量并发调用,适配不同的应用场景
- **自带电池**,提供 chainlit UI,输入检查,参数检查,计费,速率控制,_Agent_, _Tool call_
- **自带电池**,提供 chainlit UI,输入检查,参数检查,计费,速率控制,Disk Cache,_Agent_, _Tool call_
- **轻量**,最小化依赖,不同平台的请求和鉴权逻辑均为原生内置功能
- **高质量代码**,100% typehints,pylance strict, ruff lint & format, test coverage > 85% ...

Expand Down
93 changes: 7 additions & 86 deletions generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,49 @@
AzureChat,
BaichuanChat,
BaichuanChatParameters,
BailianChat,
BailianChatParameters,
ChatCompletionModel,
ChatCompletionOutput,
ChatModelRegistry,
DashScopeChat,
DashScopeChatParameters,
DashScopeMultiModalChat,
DashScopeMultiModalChatParameters,
DeepSeekChat,
DeepSeekChatParameters,
HunyuanChat,
HunyuanChatParameters,
MinimaxChat,
MinimaxChatParameters,
MinimaxLegacyChat,
MinimaxLegacyChatParameters,
MinimaxProChat,
MinimaxProChatParameters,
MoonshotChat,
MoonshotChatParameters,
OpenAIChat,
OpenAIChatParameters,
OpenRouterChat,
OpenRouterChatParameters,
Prompt,
RemoteChatCompletionModel,
StepFunChat,
StepFunChatParameters,
WenxinChat,
WenxinChatParameters,
YiChat,
YiChatParameters,
ZhipuCharacterChat,
ZhipuCharacterChatParameters,
ZhipuChat,
ZhipuChatParameters,
tool,
)
from generate.highlevel import (
generate_image,
generate_speech,
generate_text,
load_chat_model,
load_image_generation_model,
load_speech_model,
)
from generate.image_generation import (
BaiduImageGeneration,
BaiduImageGenerationParameters,
ImageGenerationModel,
ImageGenerationModelRegistry,
ImageGenerationOutput,
OpenAIImageGeneration,
OpenAIImageGenerationParameters,
QianfanImageGeneration,
QianfanImageGenerationParameters,
ZhipuImageGeneration,
)
from generate.highlevel import generate_text, load_chat_model
from generate.modifiers.hook import AfterGenerateContext, BeforeGenerateContext
from generate.platforms import (
AnthropicSettings,
AzureSettings,
BaichuanSettings,
BaiduCreationSettings,
BailianSettings,
DashScopeSettings,
DeepSeekSettings,
HunyuanSettings,
MinimaxSettings,
MoonshotSettings,
OpenAISettings,
OpenRouterSettings,
QianfanSettings,
StepFunSettings,
YiSettings,
ZhipuSettings,
)
from generate.text_to_speech import (
MinimaxProSpeech,
MinimaxProSpeechParameters,
MinimaxSpeech,
MinimaxSpeechParameters,
OpenAISpeech,
OpenAISpeechParameters,
SpeechModelRegistry,
TextToSpeechModel,
TextToSpeechOutput,
)
from generate.version import __version__

__all__ = [
Expand All @@ -100,59 +57,28 @@
'OpenAIChatParameters',
'MinimaxChat',
'MinimaxChatParameters',
'MinimaxProChat',
'MinimaxProChatParameters',
'MinimaxLegacyChat',
'MinimaxLegacyChatParameters',
'ZhipuChat',
'ZhipuChatParameters',
'ZhipuCharacterChat',
'ZhipuCharacterChatParameters',
'StepFunChat',
'StepFunChatParameters',
'StepFunSettings',
'WenxinChat',
'WenxinChatParameters',
'HunyuanChat',
'HunyuanChatParameters',
'BaichuanChat',
'BaichuanChatParameters',
'BailianChat',
'BailianChatParameters',
'DashScopeChat',
'DashScopeChatParameters',
'DashScopeMultiModalChat',
'DashScopeMultiModalChatParameters',
'MoonshotChat',
'MoonshotChatParameters',
'DeepSeekChat',
'DeepSeekChatParameters',
'OpenAISpeech',
'OpenAISpeechParameters',
'OpenRouterChat',
'OpenRouterChatParameters',
'YiChat',
'YiChatParameters',
'AnthropicChat',
'AnthropicChatParameters',
'MinimaxSpeech',
'MinimaxSpeechParameters',
'MinimaxProSpeech',
'MinimaxProSpeechParameters',
'OpenAIImageGeneration',
'OpenAIImageGenerationParameters',
'BaiduImageGeneration',
'BaiduImageGenerationParameters',
'QianfanImageGeneration',
'QianfanImageGenerationParameters',
'ZhipuImageGeneration',
'ImageGenerationModel',
'TextToSpeechModel',
'ImageGenerationModelRegistry',
'Prompt',
'ChatCompletionOutput',
'ImageGenerationOutput',
'TextToSpeechOutput',
'ChatModelRegistry',
'SpeechModelRegistry',
'AzureSettings',
'AnthropicSettings',
'BaichuanSettings',
Expand All @@ -161,20 +87,15 @@
'ZhipuSettings',
'OpenAISettings',
'QianfanSettings',
'BailianSettings',
'HunyuanSettings',
'DashScopeSettings',
'MoonshotSettings',
'DeepSeekSettings',
'OpenRouterSettings',
'YiSettings',
'AfterGenerateContext',
'BeforeGenerateContext',
'tool',
'load_chat_model',
'load_speech_model',
'load_image_generation_model',
'generate_text',
'generate_speech',
'generate_image',
'__version__',
]
40 changes: 5 additions & 35 deletions generate/chat_completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,22 @@
AzureChat,
BaichuanChat,
BaichuanChatParameters,
BailianChat,
BailianChatParameters,
DashScopeChat,
DashScopeChatParameters,
DashScopeMultiModalChat,
DashScopeMultiModalChatParameters,
DeepSeekChat,
DeepSeekChatParameters,
HunyuanChat,
HunyuanChatParameters,
MinimaxChat,
MinimaxChatParameters,
MinimaxLegacyChat,
MinimaxLegacyChatParameters,
MinimaxProChat,
MinimaxProChatParameters,
MoonshotChat,
MoonshotChatParameters,
OpenAIChat,
OpenAIChatParameters,
OpenRouterChat,
OpenRouterChatParameters,
StepFunChat,
StepFunChatParameters,
WenxinChat,
WenxinChatParameters,
YiChat,
YiChatParameters,
ZhipuCharacterChat,
ZhipuCharacterChatParameters,
ZhipuChat,
ZhipuChatParameters,
)
Expand All @@ -60,20 +48,14 @@
(AnthropicChat, AnthropicChatParameters),
(OpenAIChat, OpenAIChatParameters),
(MinimaxChat, MinimaxChatParameters),
(MinimaxProChat, MinimaxProChatParameters),
(MinimaxLegacyChat, MinimaxProChatParameters),
(ZhipuChat, ZhipuChatParameters),
(ZhipuCharacterChat, ZhipuCharacterChatParameters),
(WenxinChat, WenxinChatParameters),
(HunyuanChat, HunyuanChatParameters),
(BaichuanChat, BaichuanChatParameters),
(BailianChat, BailianChatParameters),
(DashScopeChat, DashScopeChatParameters),
(DashScopeMultiModalChat, DashScopeMultiModalChatParameters),
(MoonshotChat, MoonshotChatParameters),
(DeepSeekChat, DashScopeChatParameters),
(StepFunChat, StepFunChatParameters),
(YiChat, YiChatParameters),
(OpenRouterChat, OpenRouterChatParameters),
]

ChatModelRegistry: dict[str, tuple[Type[ChatCompletionModel], Type[ModelParameters]]] = {
Expand All @@ -90,24 +72,12 @@
'AzureChat',
'MinimaxChat',
'MinimaxChatParameters',
'MinimaxProChat',
'MinimaxProChatParameters',
'MinimaxLegacyChat',
'MinimaxLegacyChatParameters',
'OpenAIChat',
'OpenAIChatParameters',
'ZhipuChat',
'ZhipuChatParameters',
'ZhipuCharacterChat',
'ZhipuCharacterChatParameters',
'WenxinChat',
'WenxinChatParameters',
'HunyuanChat',
'HunyuanChatParameters',
'BaichuanChat',
'BaichuanChatParameters',
'BailianChat',
'BailianChatParameters',
'YiChat',
'YiChatParameters',
'StepFunChat',
Expand All @@ -116,12 +86,12 @@
'AnthropicChatParameters',
'DashScopeChat',
'DashScopeChatParameters',
'DashScopeMultiModalChat',
'DashScopeMultiModalChatParameters',
'MoonshotChat',
'MoonshotChatParameters',
'DeepSeekChat',
'DeepSeekChatParameters',
'OpenRouterChat',
'OpenRouterChatParameters',
'MessagePrinter',
'SimpleMessagePrinter',
'get_json_schema',
Expand Down
Loading

0 comments on commit 9ad52cf

Please sign in to comment.