Skip to content

Commit

Permalink
feat: add hunyuan-vision
Browse files Browse the repository at this point in the history
  • Loading branch information
muzea committed Sep 18, 2024
1 parent c06c25a commit caa6d4b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/core/model_runtime/model_providers/hunyuan/llm/llm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
from collections.abc import Generator
from typing import cast

from tencentcloud.common import credential
from tencentcloud.common.exception import TencentCloudSDKException
Expand All @@ -11,9 +12,12 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
ImagePromptMessageContent,
PromptMessage,
PromptMessageContentType,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
ToolPromptMessage,
UserPromptMessage,
)
Expand Down Expand Up @@ -143,6 +147,25 @@ def _convert_prompt_messages_to_dicts(self, prompt_messages: list[PromptMessage]
tool_execute_result = {"result": message.content}
content = json.dumps(tool_execute_result, ensure_ascii=False)
dict_list.append({"Role": message.role.value, "Content": content, "ToolCallId": message.tool_call_id})
elif isinstance(message, UserPromptMessage):
message = cast(UserPromptMessage, message)
if isinstance(message.content, str):
dict_list.append({"Role": message.role.value, "Content": message.content})
else:
sub_messages = []
for message_content in message.content:
if message_content.type == PromptMessageContentType.TEXT:
message_content = cast(TextPromptMessageContent, message_content)
sub_message_dict = {"Type": "text", "Text": message_content.data}
sub_messages.append(sub_message_dict)
elif message_content.type == PromptMessageContentType.IMAGE:
message_content = cast(ImagePromptMessageContent, message_content)
sub_message_dict = {
"Type": "image_url",
"ImageUrl": {"Url": message_content.data},
}
sub_messages.append(sub_message_dict)
dict_list.append({"Role": message.role.value, "Contents": sub_messages})
else:
dict_list.append({"Role": message.role.value, "Content": message.content})
return dict_list
Expand Down

0 comments on commit caa6d4b

Please sign in to comment.