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: add giteeAI risk control identification. #12946

Merged
merged 2 commits into from
Jan 22, 2025
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
26 changes: 26 additions & 0 deletions api/core/tools/provider/builtin/gitee_ai/tools/risk-control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Any, Union

import requests

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool


class GiteeAIToolRiskControl(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']}",
}

inputs = [{"type": "text", "text": tool_parameters.get("input-text")}]
model = tool_parameters.get("model", "Security-semantic-filtering")
payload = {"model": model, "input": inputs}
url = "https://ai.gitee.com/v1/moderations"
response = requests.post(url, json=payload, headers=headers)
if response.status_code != 200:
return self.create_text_message(f"Got Error Response:{response.text}")

return [self.create_text_message(response.content.decode("utf-8"))]
32 changes: 32 additions & 0 deletions api/core/tools/provider/builtin/gitee_ai/tools/risk-control.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
identity:
name: risk control
author: gitee_ai
label:
en_US: risk control identification
zh_Hans: 风控识别
icon: icon.svg
description:
human:
en_US: Ensuring the protection and compliance of sensitive information through the filtering and analysis of data semantics
zh_Hans: 通过对数据语义的过滤和分析,确保敏感信息的保护和合规性
llm: This tool is used to risk control identification.
parameters:
- name: model
type: string
required: true
default: Security-semantic-filtering
label:
en_US: Service Model
zh_Hans: 服务模型
form: form
- name: input-text
type: string
required: true
label:
en_US: Input Text
zh_Hans: 输入文本
human_description:
en_US: The text input for filtering and analysis.
zh_Hans: 用于分析过滤的文本
llm_description: The text input for filtering and analysis.
form: llm
Loading