Skip to content

Commit

Permalink
Fix qwen (#32)
Browse files Browse the repository at this point in the history
* Refactor DashScopeMultiModalChat to extract text and result images from content

* Add DeepSeek to list of supported platforms and update version to 0.3.3

---------

Co-authored-by: wangyuxin <[email protected]>
  • Loading branch information
wangyuxinwhy and wangyuxin authored Feb 21, 2024
1 parent c996883 commit 30c7586
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Generate Package 允许用户通过统一的 api 访问跨平台的生成式模
* [百度智能云](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t)
* [智谱](https://open.bigmodel.cn/dev/api)
* [月之暗面](https://platform.moonshot.cn/docs)
* [DeepSeek](https://platform.deepseek.com/usage)
* ...

## Features
Expand Down Expand Up @@ -203,19 +204,21 @@ for stream_output in model.stream_generate('介绍一下唐朝'):
```python
from generate.chat_completion import ChatModelRegistry

print(list(ChatModelRegistry.keys()))
print('\n'.join(list(ChatModelRegistry.keys())))

# ----- Output -----
['azure',
'openai',
'minimax_pro',
'minimax',
'zhipu',
'zhipu_character',
'wenxin',
'hunyuan',
'baichuan',
'bailian',
'dashscope',
'dashscope_multimodal']
azure
openai
minimax_pro
minimax
zhipu
zhipu_character
wenxin
hunyuan
baichuan
bailian
dashscope
dashscope_multimodal
moonshot
deepseek
```
14 changes: 12 additions & 2 deletions generate/chat_completion/models/dashscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,21 @@ def _get_stream_request_parameters(

def _parse_reponse(self, response: ResponseValue) -> ChatCompletionOutput:
choice = response['output']['choices'][0]
content_list = choice['message']['content']
text = ''
result_images = []
for content in content_list:
for k, v in content.items():
if k != 'result_image':
text += v
else:
result_images.append(v)
return ChatCompletionOutput(
model_info=self.model_info,
message=AssistantMessage(content=choice['message']['content'][0]['text']),
finish_reason=choice.get('finish_reason'),
message=AssistantMessage(content=text),
cost=None,
extra={'usage': response['usage'], 'request_id': response['request_id']},
extra={'usage': response['usage'], 'request_id': response['request_id'], 'content': content_list, 'result_images': result_images},
)

@override
Expand Down
5 changes: 5 additions & 0 deletions generate/image_generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
QianfanImageGeneration,
QianfanImageGenerationParameters,
ZhipuImageGeneration,
ZhipuImageGenerationParameters,
)
from generate.model import ModelParameters

P = TypeVar('P', bound=ModelParameters)

ImageGenerationModels: list[tuple[Type[ImageGenerationModel], Type[ModelParameters]]] = [
(OpenAIImageGeneration, OpenAIImageGenerationParameters),
(BaiduImageGeneration, BaiduImageGenerationParameters),
(QianfanImageGeneration, QianfanImageGenerationParameters),
(ZhipuImageGeneration, ZhipuImageGenerationParameters),
]

ImageGenerationModelRegistry: dict[str, tuple[Type[ImageGenerationModel], Type[ModelParameters]]] = {
Expand All @@ -35,4 +39,5 @@
'QianfanImageGeneration',
'QianfanImageGenerationParameters',
'ZhipuImageGeneration',
'ZhipuImageGenerationParameters',
]
3 changes: 2 additions & 1 deletion generate/image_generation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from generate.image_generation.models.baidu import BaiduImageGeneration, BaiduImageGenerationParameters
from generate.image_generation.models.openai import OpenAIImageGeneration, OpenAIImageGenerationParameters
from generate.image_generation.models.qianfan import QianfanImageGeneration, QianfanImageGenerationParameters
from generate.image_generation.models.zhipu import ZhipuImageGeneration
from generate.image_generation.models.zhipu import ZhipuImageGeneration, ZhipuImageGenerationParameters

__all__ = [
'OpenAIImageGeneration',
Expand All @@ -11,4 +11,5 @@
'QianfanImageGeneration',
'QianfanImageGenerationParameters',
'ZhipuImageGeneration',
'ZhipuImageGenerationParameters',
]
1 change: 1 addition & 0 deletions generate/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async def main(message: cl.Message) -> None:
state._chat_history.append(chunk.message)
except Exception as e:
await cl.Message(content=f'Error: {e}').send()
raise
await assistant_message.update()


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.post1'
__version__ = '0.3.3'
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.post1"
version = "0.3.3"
description = "文本生成,图像生成,语音生成"
authors = ["wangyuxin <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 30c7586

Please sign in to comment.