Parcourir la source

Gitee AI tools (#10314)

方程 il y a 5 mois
Parent
commit
2b7341af57

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 0
api/core/tools/provider/builtin/gitee_ai/_assets/icon.svg


+ 17 - 0
api/core/tools/provider/builtin/gitee_ai/gitee_ai.py

@@ -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 - 0
api/core/tools/provider/builtin/gitee_ai/gitee_ai.yaml

@@ -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 - 0
api/core/tools/provider/builtin/gitee_ai/tools/text-to-image.py

@@ -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 - 0
api/core/tools/provider/builtin/gitee_ai/tools/text-to-image.yaml

@@ -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

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff