Skip to content

Commit

Permalink
fix: image tokenizer (#2752)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly authored Mar 8, 2024
1 parent 4170d6a commit 3231a8c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion api/core/model_runtime/model_providers/anthropic/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,25 @@ def _convert_one_message_to_text(self, message: PromptMessage) -> str:

if isinstance(message, UserPromptMessage):
message_text = f"{human_prompt} {content}"
if not isinstance(message.content, list):
message_text = f"{ai_prompt} {content}"
else:
message_text = ""
for sub_message in message.content:
if sub_message.type == PromptMessageContentType.TEXT:
message_text += f"{human_prompt} {sub_message.data}"
elif sub_message.type == PromptMessageContentType.IMAGE:
message_text += f"{human_prompt} [IMAGE]"
elif isinstance(message, AssistantPromptMessage):
message_text = f"{ai_prompt} {content}"
if not isinstance(message.content, list):
message_text = f"{ai_prompt} {content}"
else:
message_text = ""
for sub_message in message.content:
if sub_message.type == PromptMessageContentType.TEXT:
message_text += f"{ai_prompt} {sub_message.data}"
elif sub_message.type == PromptMessageContentType.IMAGE:
message_text += f"{ai_prompt} [IMAGE]"
elif isinstance(message, SystemPromptMessage):
message_text = content
else:
Expand Down

0 comments on commit 3231a8c

Please sign in to comment.