-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
839 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
api/core/model_runtime/model_providers/__base/text2img_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from abc import abstractmethod | ||
from typing import IO, Optional | ||
|
||
from core.model_runtime.entities.model_entities import ModelType | ||
from core.model_runtime.model_providers.__base.ai_model import AIModel | ||
|
||
|
||
class Text2ImageModel(AIModel): | ||
""" | ||
Model class for text2img model. | ||
""" | ||
model_type: ModelType = ModelType.TEXT2IMG | ||
|
||
def invoke(self, model: str, credentials: dict, prompt: str, | ||
model_parameters: dict, user: Optional[str] = None) \ | ||
-> list[IO[bytes]]: | ||
""" | ||
Invoke Text2Image model | ||
:param model: model name | ||
:param credentials: model credentials | ||
:param prompt: prompt for image generation | ||
:param model_parameters: model parameters | ||
:param user: unique user id | ||
:return: image bytes | ||
""" | ||
try: | ||
return self._invoke(model, credentials, prompt, model_parameters, user) | ||
except Exception as e: | ||
raise self._transform_invoke_error(e) | ||
|
||
@abstractmethod | ||
def _invoke(self, model: str, credentials: dict, prompt: str, | ||
model_parameters: dict, user: Optional[str] = None) \ | ||
-> list[IO[bytes]]: | ||
""" | ||
Invoke Text2Image model | ||
:param model: model name | ||
:param credentials: model credentials | ||
:param prompt: prompt for image generation | ||
:param model_parameters: model parameters | ||
:param user: unique user id | ||
:return: image bytes | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
provider: anthropic | ||
label: | ||
en_US: Anthropic Model Tools | ||
zh_Hans: Anthropic 模型能力 | ||
pt_BR: Anthropic Model Tools | ||
models: | ||
- type: llm | ||
model: claude-3-sonnet-20240229 | ||
label: | ||
zh_Hans: Claude3 Sonnet 视觉 | ||
en_US: Claude3 Sonnet Vision | ||
properties: | ||
image_parameter_name: image_id | ||
- type: llm | ||
model: claude-3-opus-20240229 | ||
label: | ||
zh_Hans: Claude3 Opus 视觉 | ||
en_US: Claude3 Opus Vision | ||
properties: | ||
image_parameter_name: image_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
provider: google | ||
label: | ||
en_US: Google Model Tools | ||
zh_Hans: Google 模型能力 | ||
pt_BR: Google Model Tools | ||
models: | ||
- type: llm | ||
model: gemini-pro-vision | ||
label: | ||
zh_Hans: Gemini Pro 视觉 | ||
en_US: Gemini Pro Vision | ||
properties: | ||
image_parameter_name: image_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
provider: openai | ||
label: | ||
en_US: OpenAI Model Tools | ||
zh_Hans: OpenAI 模型能力 | ||
pt_BR: OpenAI Model Tools | ||
models: | ||
- type: llm | ||
model: gpt-4-vision-preview | ||
label: | ||
zh_Hans: GPT-4 视觉 | ||
en_US: GPT-4 Vision | ||
properties: | ||
image_parameter_name: image_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
provider: zhipuai | ||
label: | ||
en_US: ZhipuAI Model Tools | ||
zh_Hans: ZhipuAI 模型能力 | ||
pt_BR: ZhipuAI Model Tools | ||
models: | ||
- type: llm | ||
model: glm-4v | ||
label: | ||
zh_Hans: GLM-4 视觉 | ||
en_US: GLM-4 Vision | ||
properties: | ||
image_parameter_name: image_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.