From 76e9cf13b26e8d6dc1fd55bebddf5e9a1ffc0336 Mon Sep 17 00:00:00 2001 From: rinfx <893383980@qq.com> Date: Wed, 19 Jun 2024 14:04:34 +0800 Subject: [PATCH] add ai plugins (#311) --- .../plugins/ai-prompt-decorator/spec.yaml | 33 +++++++++++++++++++ .../plugins/ai-prompt-template/spec.yaml | 31 +++++++++++++++++ .../main/resources/plugins/ai-rag/spec.yaml | 33 +++++++++++++++++++ .../plugins/ai-security-guard/spec.yaml | 28 ++++++++++++++++ .../resources/plugins/ai-statistics/spec.yaml | 23 +++++++++++++ .../plugins/ai-token-ratelimit/spec.yaml | 33 +++++++++++++++++++ .../plugins/ai-transformer/spec.yaml | 32 ++++++++++++++++++ .../main/resources/plugins/plugins.properties | 7 ++++ 8 files changed, 220 insertions(+) create mode 100644 backend/sdk/src/main/resources/plugins/ai-prompt-decorator/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-prompt-template/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-rag/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-security-guard/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-statistics/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-token-ratelimit/spec.yaml create mode 100644 backend/sdk/src/main/resources/plugins/ai-transformer/spec.yaml diff --git a/backend/sdk/src/main/resources/plugins/ai-prompt-decorator/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-prompt-decorator/spec.yaml new file mode 100644 index 00000000..9b0f5139 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-prompt-decorator/spec.yaml @@ -0,0 +1,33 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-prompt-decorator + title: AI提示词修饰器 + x-title-i18n: + zh-CN: AI提示词修饰器 + description: 对LLM提示词进行修改 + x-description-i18n: + zh-CN: 对LLM提示词进行修改 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 450 + configSchema: + openAPIV3Schema: + type: object + example: + decorators: + - name: hangzhou-guide + decorator: + prepend: + - role: system + content: "你将使用英语回答问题" + - role: user + content: "假设你现在所在地点为杭州" + append: + - role: user + content: "在介绍杭州时,避开杭州的饮食" + diff --git a/backend/sdk/src/main/resources/plugins/ai-prompt-template/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-prompt-template/spec.yaml new file mode 100644 index 00000000..63be4213 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-prompt-template/spec.yaml @@ -0,0 +1,31 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-prompt-template + title: AI提示词模板 + x-title-i18n: + zh-CN: AI提示词模板 + description: 基于模板构建LLM提示词 + x-description-i18n: + zh-CN: 基于模板构建LLM提示词 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 500 + configSchema: + openAPIV3Schema: + type: object + example: + templates: + - name: developer-chat + template: + model: gpt-3.5-turbo + messages: + - role: system + content: '你是一个 {{program}} 专家,编程语言为 {{language}}' + - role: user + content: '帮我写一个 {{program}} 程序' + diff --git a/backend/sdk/src/main/resources/plugins/ai-rag/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-rag/spec.yaml new file mode 100644 index 00000000..e30a1273 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-rag/spec.yaml @@ -0,0 +1,33 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-rag + title: AI检索增强生成 + x-title-i18n: + zh-CN: AI检索增强生成 + description: 通过RAG技术优化大模型生成内容 + x-description-i18n: + zh-CN: 通过RAG技术优化大模型生成内容 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 400 + configSchema: + openAPIV3Schema: + type: object + example: + dashscope: + apiKey: xxxxxxxxxxxxxxxxxxxx + serviceName: dashscope + servicePort: 443 + domain: dashscope.aliyuncs.com + dashvector: + apiKey: xxxxxxxxxxxxxxxxxxxx + serviceName: dashvector + servicePort: 443 + domain: vrs-cn-xxxxxxxxxxxxxxxxxxxx.dashvector.cn-hangzhou.aliyuncs.com + collection: news_embedings + diff --git a/backend/sdk/src/main/resources/plugins/ai-security-guard/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-security-guard/spec.yaml new file mode 100644 index 00000000..c4bad471 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-security-guard/spec.yaml @@ -0,0 +1,28 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-security-guard + title: AI内容安全 + x-title-i18n: + zh-CN: AI内容安全 + description: 基于阿里云内容安全对大模型的输入输出进行安全检测 + x-description-i18n: + zh-CN: 基于阿里云内容安全对大模型的输入输出进行安全检测 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 300 + configSchema: + openAPIV3Schema: + type: object + example: + serviceSource: dns + serviceName: safecheck + servicePort: 443 + domain: green-cip.cn-shanghai.aliyuncs.com + ak: xxxxxxxxxxxxxxxxxxxx + sk: xxxxxxxxxxxxxxxxxxxx + diff --git a/backend/sdk/src/main/resources/plugins/ai-statistics/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-statistics/spec.yaml new file mode 100644 index 00000000..5ef0d813 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-statistics/spec.yaml @@ -0,0 +1,23 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-statistics + title: AI可观测 + x-title-i18n: + zh-CN: AI可观测 + description: 生成AI可观测数据 + x-description-i18n: + zh-CN: 生成AI可观测数据 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 200 + configSchema: + openAPIV3Schema: + type: object + example: + enable: true + diff --git a/backend/sdk/src/main/resources/plugins/ai-token-ratelimit/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-token-ratelimit/spec.yaml new file mode 100644 index 00000000..989a8794 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-token-ratelimit/spec.yaml @@ -0,0 +1,33 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-token-ratelimit + title: AI Token 限流 + x-title-i18n: + zh-CN: AI Token 限流 + description: 对大模型服务进行 Token 限流 + x-description-i18n: + zh-CN: 对大模型服务进行 Token 限流 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 600 + configSchema: + openAPIV3Schema: + type: object + example: + rule_name: default_rule + rule_items: + - limit_by_per_ip: from-remote-addr + limit_keys: + - key: 0.0.0.0/0 + token_per_minute: 100 + redis: + service_name: redis.static + service_port: 6379 + username: default + password: '123456' + diff --git a/backend/sdk/src/main/resources/plugins/ai-transformer/spec.yaml b/backend/sdk/src/main/resources/plugins/ai-transformer/spec.yaml new file mode 100644 index 00000000..652fecd9 --- /dev/null +++ b/backend/sdk/src/main/resources/plugins/ai-transformer/spec.yaml @@ -0,0 +1,32 @@ +apiVersion: 1.0.0 +info: + category: custom + name: ai-transformer + title: AI请求/响应转换 + x-title-i18n: + zh-CN: AI请求/响应转换 + description: 基于LLM对请求/响应进行智能转换 + x-description-i18n: + zh-CN: 基于LLM对请求/响应进行智能转换 + iconUrl: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png + version: 1.0.0 + contact: + name: rinfx +spec: + phase: UNSPECIFIED_PHASE + priority: 550 + configSchema: + openAPIV3Schema: + type: object + example: + request: + enable: false + prompt: "如果请求path是以/httpbin开头的,帮我去掉/httpbin前缀,其他的不要改。" + response: + enable: true + prompt: "帮我修改以下HTTP应答信息,要求:1. content-type修改为application/json;2. body由xml转化为json;3.移除content-length。" + provider: + serviceName: qwen + domain: dashscope.aliyuncs.com + sk: sk-xxxxxxxxxxxxxxxxxxx + diff --git a/backend/sdk/src/main/resources/plugins/plugins.properties b/backend/sdk/src/main/resources/plugins/plugins.properties index 49e0d629..691ac73e 100644 --- a/backend/sdk/src/main/resources/plugins/plugins.properties +++ b/backend/sdk/src/main/resources/plugins/plugins.properties @@ -11,6 +11,13 @@ # specific language governing permissions and limitations under the License. # +ai-prompt-decorator=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-prompt-decorator:1.0.0 +ai-prompt-template=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-prompt-template:1.0.0 +ai-rag=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-rag:1.0.0 +ai-security-guard=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-security-guard:1.0.0 +ai-statistics=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-statistics:1.0.0 +ai-token-ratelimit=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-token-ratelimit:1.0.0 +ai-transformer=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-transformer:1.0.0 ai-cache=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-cache:1.0.0 ai-proxy=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-proxy:1.0.0 basic-auth=oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/basic-auth:1.0.0