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

feat(ark): support doubao vision series models #11740

Merged
merged 2 commits into from
Dec 17, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
from collections.abc import Generator
from typing import Optional, cast

Expand Down Expand Up @@ -104,17 +103,16 @@ def convert_prompt_message(message: PromptMessage) -> ChatCompletionMessageParam
if message_content.type == PromptMessageContentType.TEXT:
content.append(
ChatCompletionContentPartTextParam(
text=message_content.text,
text=message_content.data,
type="text",
)
)
elif message_content.type == PromptMessageContentType.IMAGE:
message_content = cast(ImagePromptMessageContent, message_content)
image_data = re.sub(r"^data:image\/[a-zA-Z]+;base64,", "", message_content.data)
content.append(
ChatCompletionContentPartImageParam(
image_url=ImageURL(
url=image_data,
url=message_content.data,
detail=message_content.detail.value,
),
type="image_url",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def _get_num_tokens_v3(self, messages: list[PromptMessage]) -> int:
messages_dict = [ArkClientV3.convert_prompt_message(m) for m in messages]
for message in messages_dict:
for key, value in message.items():
# Ignore tokens for image type
if isinstance(value, list):
text = ""
for item in value:
if isinstance(item, dict) and item["type"] == "text":
text += item["text"]

value = text
num_tokens += self._get_num_tokens_by_gpt2(str(key))
num_tokens += self._get_num_tokens_by_gpt2(str(value))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class ModelConfig(BaseModel):


configs: dict[str, ModelConfig] = {
"Doubao-vision-pro-32k": ModelConfig(
properties=ModelProperties(context_size=32768, max_tokens=4096, mode=LLMMode.CHAT),
features=[ModelFeature.VISION],
),
"Doubao-vision-lite-32k": ModelConfig(
properties=ModelProperties(context_size=32768, max_tokens=4096, mode=LLMMode.CHAT),
features=[ModelFeature.VISION],
),
"Doubao-pro-4k": ModelConfig(
properties=ModelProperties(context_size=4096, max_tokens=4096, mode=LLMMode.CHAT),
features=[ModelFeature.TOOL_CALL],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ model_credential_schema:
type: select
required: true
options:
- label:
en_US: Doubao-vision-pro-32k
value: Doubao-vision-pro-32k
show_on:
- variable: __model_type
value: llm
- label:
en_US: Doubao-vision-lite-32k
value: Doubao-vision-lite-32k
show_on:
- variable: __model_type
value: llm
- label:
en_US: Doubao-pro-4k
value: Doubao-pro-4k
Expand Down
Loading