forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@ | ||
import requests | ||
|
||
from core.tools.errors import ToolProviderCredentialValidationError | ||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController | ||
|
||
|
||
class GiteeAIProvider(BuiltinToolProviderController): | ||
def _validate_credentials(self, credentials: dict) -> None: | ||
url = "https://ai.gitee.com/api/base/account/me" | ||
headers = { | ||
"accept": "application/json", | ||
"authorization": f"Bearer {credentials.get('api_key')}", | ||
} | ||
|
||
response = requests.get(url, headers=headers) | ||
if response.status_code != 200: | ||
raise ToolProviderCredentialValidationError("GiteeAI API key is invalid") |
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,22 @@ | ||
identity: | ||
author: Gitee AI | ||
name: gitee_ai | ||
label: | ||
en_US: Gitee AI | ||
zh_Hans: Gitee AI | ||
description: | ||
en_US: 快速体验大模型,领先探索 AI 开源世界 | ||
zh_Hans: 快速体验大模型,领先探索 AI 开源世界 | ||
icon: icon.svg | ||
tags: | ||
- image | ||
credentials_for_provider: | ||
api_key: | ||
type: secret-input | ||
required: true | ||
label: | ||
en_US: API Key | ||
placeholder: | ||
zh_Hans: 在此输入您的 API Key | ||
en_US: Enter your API Key | ||
url: https://ai.gitee.com/dashboard/settings/tokens |
33 changes: 33 additions & 0 deletions
33
api/core/tools/provider/builtin/gitee_ai/tools/text-to-image.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,33 @@ | ||
from typing import Any, Union | ||
|
||
import requests | ||
|
||
from core.tools.entities.tool_entities import ToolInvokeMessage | ||
from core.tools.tool.builtin_tool import BuiltinTool | ||
|
||
|
||
class GiteeAITool(BuiltinTool): | ||
def _invoke( | ||
self, user_id: str, tool_parameters: dict[str, Any] | ||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: | ||
headers = { | ||
"content-type": "application/json", | ||
"authorization": f"Bearer {self.runtime.credentials['api_key']}", | ||
} | ||
|
||
payload = { | ||
"inputs": tool_parameters.get("inputs"), | ||
"width": tool_parameters.get("width", "720"), | ||
"height": tool_parameters.get("height", "720"), | ||
} | ||
model = tool_parameters.get("model", "Kolors") | ||
url = f"https://ai.gitee.com/api/serverless/{model}/text-to-image" | ||
|
||
response = requests.post(url, json=payload, headers=headers) | ||
if response.status_code != 200: | ||
return self.create_text_message(f"Got Error Response:{response.text}") | ||
|
||
# The returned image is base64 and needs to be mark as an image | ||
result = [self.create_blob_message(blob=response.content, meta={"mime_type": "image/jpeg"})] | ||
|
||
return result |
72 changes: 72 additions & 0 deletions
72
api/core/tools/provider/builtin/gitee_ai/tools/text-to-image.yaml
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,72 @@ | ||
identity: | ||
name: text to image | ||
author: gitee_ai | ||
label: | ||
en_US: text to image | ||
icon: icon.svg | ||
description: | ||
human: | ||
en_US: generate images using a variety of popular models | ||
llm: This tool is used to generate image from text. | ||
parameters: | ||
- name: model | ||
type: select | ||
required: true | ||
options: | ||
- value: flux-1-schnell | ||
label: | ||
en_US: flux-1-schnell | ||
- value: Kolors | ||
label: | ||
en_US: Kolors | ||
- value: stable-diffusion-3-medium | ||
label: | ||
en_US: stable-diffusion-3-medium | ||
- value: stable-diffusion-xl-base-1.0 | ||
label: | ||
en_US: stable-diffusion-xl-base-1.0 | ||
- value: stable-diffusion-v1-4 | ||
label: | ||
en_US: stable-diffusion-v1-4 | ||
default: Kolors | ||
label: | ||
en_US: Choose Image Model | ||
zh_Hans: 选择生成图片的模型 | ||
form: form | ||
- name: inputs | ||
type: string | ||
required: true | ||
label: | ||
en_US: Input Text | ||
zh_Hans: 输入文本 | ||
human_description: | ||
en_US: The text input used to generate the image. | ||
zh_Hans: 用于生成图片的输入文本。 | ||
llm_description: This text input will be used to generate image. | ||
form: llm | ||
- name: width | ||
type: number | ||
required: true | ||
default: 720 | ||
min: 1 | ||
max: 1024 | ||
label: | ||
en_US: Image Width | ||
zh_Hans: 图片宽度 | ||
human_description: | ||
en_US: The width of the generated image. | ||
zh_Hans: 生成图片的宽度。 | ||
form: form | ||
- name: height | ||
type: number | ||
required: true | ||
default: 720 | ||
min: 1 | ||
max: 1024 | ||
label: | ||
en_US: Image Height | ||
zh_Hans: 图片高度 | ||
human_description: | ||
en_US: The height of the generated image. | ||
zh_Hans: 生成图片的高度。 | ||
form: form |