mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
Gitee AI tools (#10314)
This commit is contained in:
parent
ce1f9d935d
commit
2b7341af57
|
@ -0,0 +1,3 @@
|
|||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M25.132 24.3947C25.497 25.7527 25.8984 27.1413 26.3334 28.5834C26.7302 29.8992 25.5459 30.4167 25.0752 29.1758C24.571 27.8466 24.0885 26.523 23.6347 25.1729C21.065 26.4654 18.5025 27.5424 15.5961 28.7541C16.7581 33.0256 17.8309 36.5984 19.4952 39.9935C19.4953 39.9936 19.4953 39.9937 19.4954 39.9938C19.6631 39.9979 19.8313 40 20 40C31.0457 40 40 31.0457 40 20C40 16.0335 38.8453 12.3366 36.8537 9.22729C31.6585 9.69534 27.0513 10.4562 22.8185 11.406C22.8882 12.252 22.9677 13.0739 23.0555 13.855C23.3824 16.7604 23.9112 19.5281 24.6137 22.3836C27.0581 21.2848 29.084 20.3225 30.6816 19.522C32.2154 18.7535 33.6943 18.7062 31.2018 20.6594C29.0388 22.1602 27.0644 23.3566 25.132 24.3947ZM36.1559 8.20846C33.0001 3.89184 28.1561 0.887462 22.5955 0.166882C22.4257 2.86234 22.4785 6.26344 22.681 9.50447C26.7473 8.88859 31.1721 8.46032 36.1559 8.20846ZM19.9369 9.73661e-05C19.7594 2.92694 19.8384 6.65663 20.19 9.91293C17.3748 10.4109 14.7225 11.0064 12.1592 11.7038C12.0486 10.4257 11.9927 9.25764 11.9927 8.24178C11.9927 7.5054 11.3957 6.90844 10.6593 6.90844C9.92296 6.90844 9.32601 7.5054 9.32601 8.24178C9.32601 9.47868 9.42873 10.898 9.61402 12.438C8.33567 12.8278 7.07397 13.2443 5.81918 13.688C5.12493 13.9336 4.76118 14.6954 5.0067 15.3896C5.25223 16.0839 6.01406 16.4476 6.7083 16.2021C7.7931 15.8185 8.88482 15.4388 9.98927 15.0659C10.5222 18.3344 11.3344 21.9428 12.2703 25.4156C12.4336 26.0218 12.6062 26.6262 12.7863 27.2263C9.34168 28.4135 5.82612 29.3782 2.61128 29.8879C0.949407 26.9716 0 23.5967 0 20C0 8.97534 8.92023 0.0341108 19.9369 9.73661e-05ZM4.19152 32.2527C7.45069 36.4516 12.3458 39.3173 17.9204 39.8932C16.5916 37.455 14.9338 33.717 13.5405 29.5901C10.4404 30.7762 7.25883 31.6027 4.19152 32.2527ZM22.9735 23.1135C22.1479 20.41 21.4462 17.5441 20.9225 14.277C20.746 13.5841 20.5918 12.8035 20.4593 11.9636C17.6508 12.6606 14.9992 13.4372 12.4356 14.2598C12.8479 17.4766 13.5448 21.1334 14.5118 24.7218C14.662 25.2792 14.8081 25.8248 14.9514 26.3594L14.9516 26.3603L14.9524 26.3634L14.9526 26.3639L14.973 26.4401C16.1833 25.9872 17.3746 25.5123 18.53 25.0259C20.1235 24.3552 21.6051 23.7165 22.9735 23.1135Z" fill="#141519"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
17
api/core/tools/provider/builtin/gitee_ai/gitee_ai.py
Normal file
17
api/core/tools/provider/builtin/gitee_ai/gitee_ai.py
Normal file
|
@ -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")
|
22
api/core/tools/provider/builtin/gitee_ai/gitee_ai.yaml
Normal file
22
api/core/tools/provider/builtin/gitee_ai/gitee_ai.yaml
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user