From 6ff473cd66b216c7099b3b2a707ecd1691c61314 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 13:54:36 +0545 Subject: [PATCH 01/15] feat: ai-prompt-template plugin --- apisix/cli/config.lua | 1 + apisix/plugins/ai-prompt-template.lua | 135 +++++++++++ conf/config.yaml.example | 1 + t/plugin/ai-prompt-template.t | 329 ++++++++++++++++++++++++++ 4 files changed, 466 insertions(+) create mode 100644 apisix/plugins/ai-prompt-template.lua create mode 100644 t/plugin/ai-prompt-template.t diff --git a/apisix/cli/config.lua b/apisix/cli/config.lua index 94843621a74b..7f15542b1d7e 100644 --- a/apisix/cli/config.lua +++ b/apisix/cli/config.lua @@ -213,6 +213,7 @@ local _M = { "authz-keycloak", "proxy-cache", "body-transformer", + "ai-prompt-template", "proxy-mirror", "proxy-rewrite", "workflow", diff --git a/apisix/plugins/ai-prompt-template.lua b/apisix/plugins/ai-prompt-template.lua new file mode 100644 index 000000000000..7bd419481069 --- /dev/null +++ b/apisix/plugins/ai-prompt-template.lua @@ -0,0 +1,135 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local core = require("apisix.core") +local body_transformer = require("apisix.plugins.body-transformer") + +local prompt_schema = { + properties = { + role = { + type = "string", + enum = { "system", "user", "assistant" } + }, + content = { + type = "string", + minLength = 1, + } + }, + required = { "role", "content" } +} + +local prompts = { + type = "array", + minItems = 1, + items = prompt_schema +} + +local schema = { + type = "object", + properties = { + templates = { + type = "array", + minItems = 1, + items = { + type = "object", + properties = { + name = { + type = "string", + minLength = 1, + }, + template = { + type = "object", + properties = { + model = { + type = "string", + minLength = 1, + }, + messages = prompts + } + } + }, + required = {"name", "template"} + } + }, + }, + required = {"templates"}, +} + + +local _M = { + version = 0.1, + priority = 1060, + name = "ai-prompt-template", + schema = schema, +} + + +function _M.check_schema(conf) + return core.schema.check(schema, conf) +end + + +local function get_request_body_table() + local body, err = core.request.get_body() + if not body then + return nil, { message = "could not get body: " .. err } + end + + local body_tab, err = core.json.decode(body) + if not body_tab then + return nil, { message = "could not get parse JSON request body: ", err } + end + + return body_tab +end + + +local function find_template(conf, template_name) + for _, template in ipairs(conf.templates) do + if template.name == template_name then + return template.template + end + end + return nil +end + +function _M.rewrite(conf, ctx) + local body_tab = get_request_body_table() + local template_name = body_tab.template_name + if not template_name then + return 400, { message = "template name is missing in request." } + end + + local template = find_template(conf, template_name) + if not template then + return 400, { message = "template: " .. template_name .. " not configured." } + end + + local template_json = core.json.encode(template) + core.log.info("sending template to body_transformer: ", template_json) + return body_transformer.rewrite( + { + request = { + template = template_json, + input_format = "json" + } + }, + ctx + ) +end + + +return _M diff --git a/conf/config.yaml.example b/conf/config.yaml.example index 5a490a4bb4b3..5d22418caeb5 100644 --- a/conf/config.yaml.example +++ b/conf/config.yaml.example @@ -476,6 +476,7 @@ plugins: # plugin list (sorted by priority) #- error-log-logger # priority: 1091 - proxy-cache # priority: 1085 - body-transformer # priority: 1080 + - ai-prompt-template # priority: 1060 - proxy-mirror # priority: 1010 - proxy-rewrite # priority: 1008 - workflow # priority: 1006 diff --git a/t/plugin/ai-prompt-template.t b/t/plugin/ai-prompt-template.t new file mode 100644 index 000000000000..ad6bf914ba22 --- /dev/null +++ b/t/plugin/ai-prompt-template.t @@ -0,0 +1,329 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +use t::APISIX 'no_plan'; + +repeat_each(1); +log_level('info'); +no_root_location(); +no_shuffle(); + +add_block_preprocessor(sub { + my ($block) = @_; + + if (!$block->request) { + $block->set_value("request", "GET /t"); + } + +}); + +run_tests(); + +__DATA__ + +=== TEST 1: sanity +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/echo", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "plugins": { + "ai-prompt-template": { + "templates":[ + { + "name": "programming question", + "template": { + "model": "some model", + "messages": [ + { "role": "system", "content": "You are a {{ language }} programmer." }, + { "role": "user", "content": "Write a {{ program_name }} program." } + ] + } + }, + { + "name": "level of detail", + "template": { + "model": "some model", + "messages": [ + { "role": "user", "content": "Explain about {{ topic }} in {{ level }}." } + ] + } + } + ] + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } +} +--- response_body +passed + + + +=== TEST 2: no templates +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/echo", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "plugins": { + "ai-prompt-template": { + "templates":[] + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } +} +--- error_code: 400 +--- response_body eval +qr/.*property \\"templates\\" validation failed: expect array to have at least 1 items.*/ + + + +=== TEST 3: test template insertion +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local json = require("apisix.core.json") + local code, body, actual_resp = t('/echo', + ngx.HTTP_POST, + [[{ + "template_name": "programming question", + "language": "python", + "program_name": "quick sort" + }]], + [[{ + "model": "some model", + "messages": [ + { "role": "system", "content": "You are a python programmer." }, + { "role": "user", "content": "Write a quick sort program." } + ] + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + ngx.say("passed") + } + } +--- response_body +passed + + + +=== TEST 4: multiple templates +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/echo", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "plugins": { + "ai-prompt-template": { + "templates":[ + { + "name": "programming question", + "template": { + "model": "some model", + "messages": [ + { "role": "system", "content": "You are a {{ language }} programmer." }, + { "role": "user", "content": "Write a {{ program_name }} program." } + ] + } + }, + { + "name": "level of detail", + "template": { + "model": "some model", + "messages": [ + { "role": "user", "content": "Explain about {{ topic }} in {{ level }}." } + ] + } + } + ] + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } +} +--- response_body +passed + + + +=== TEST 5: test second template +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local json = require("apisix.core.json") + local code, body, actual_resp = t('/echo', + ngx.HTTP_POST, + [[{ + "template_name": "level of detail", + "topic": "psychology", + "level": "brief" + }]], + [[{ + "model": "some model", + "messages": [ + { "role": "user", "content": "Explain about psychology in brief." } + ] + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + ngx.say("passed") + } + } +--- response_body +passed + + + +=== TEST 6: missing template items +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local json = require("apisix.core.json") + local code, body, actual_resp = t('/echo', + ngx.HTTP_POST, + [[{ + "template_name": "level of detail", + "topic-missing": "psychology", + "level-missing": "brief" + }]], + [[{ + "model": "some model", + "messages": [ + { "role": "user", "content": "Explain about in ." } + ] + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + ngx.say("passed") + } + } +--- response_body +passed + + + +=== TEST 7: request body contains non-existent template +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local json = require("apisix.core.json") + local code, body, actual_resp = t('/echo', + ngx.HTTP_POST, + [[{ + "template_name": "random", + "some-key": "some-value" + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + ngx.say("passed") + } + } +--- error_code: 400 +--- response_body eval +qr/.*template: random not configured.*/ + + + +=== TEST 8: request body contains non-existent template +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local json = require("apisix.core.json") + local code, body, actual_resp = t('/echo', + ngx.HTTP_POST, + [[{ + "missing-template-name": "haha" + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + ngx.say("passed") + } + } +--- error_code: 400 +--- response_body eval +qr/.*template name is missing in request.*/ From 124119c2ad319ce4c91c7c25cae6fbb70e60f02c Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 14:45:24 +0545 Subject: [PATCH 02/15] body error catch --- apisix/plugins/ai-prompt-template.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/ai-prompt-template.lua b/apisix/plugins/ai-prompt-template.lua index 7bd419481069..47afe8f7f584 100644 --- a/apisix/plugins/ai-prompt-template.lua +++ b/apisix/plugins/ai-prompt-template.lua @@ -107,7 +107,10 @@ local function find_template(conf, template_name) end function _M.rewrite(conf, ctx) - local body_tab = get_request_body_table() + local body_tab, err = get_request_body_table() + if not body_tab then + return 400, err + end local template_name = body_tab.template_name if not template_name then return 400, { message = "template name is missing in request." } From 589708e36494a0025fadd6c62aebed9c9f5c9b43 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 14:45:28 +0545 Subject: [PATCH 03/15] docs --- docs/en/latest/ai-prompt-template.md | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 docs/en/latest/ai-prompt-template.md diff --git a/docs/en/latest/ai-prompt-template.md b/docs/en/latest/ai-prompt-template.md new file mode 100644 index 000000000000..bc5628352b44 --- /dev/null +++ b/docs/en/latest/ai-prompt-template.md @@ -0,0 +1,102 @@ +--- +title: ai-prompt-template +keywords: + - Apache APISIX + - API Gateway + - Plugin + - ai-prompt-template +description: This document contains information about the Apache APISIX ai-prompt-template Plugin. +--- + + + +## Description + +The `ai-prompt-template` plugin simplifies access to AI providers and models by predefining the request format +using a template and allowing users to pass only the values for template variables. + +## Plugin Attributes + +| **Field** | **Type** | **Description** | **Required** | +| ------------------------------------- | -------- | --------------------------------------------------- | ------------ | +| `templates` | Array | An array of template objects | Yes | +| `templates.name` | String | Name of the template. | Yes | +| `templates.template.model` | String | Model of the AI Model. Example: gpt-4, gpt-3.5 | Yes | +| `templates.template.messages.role` | String | Role of the message (`system`, `user`, `assistant`) | Yes | +| `templates.template.messages.content` | String | Content of the message. | Yes | + +## Example usage + +Create a route with the `ai-prompt-template` plugin like so: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \ + -H "X-API-KEY: ${ADMIN_API_KEY}" \ + -d '{ + "uri": "/v1/chat/completions", + "upstream": { + "type": "roundrobin", + "nodes": { + "api.openai.com:443": 1 + }, + "scheme": "https", + "pass_host": "node" + }, + "plugins": { + "ai-prompt-template": { + "templates": [ + { + "name": "level of detail", + "template": { + "model": "gpt-4", + "messages": [ + { + "role": "user", + "content": "Explain about {{ topic }} in {{ level }}." + } + ] + } + } + ] + } + } + }' +``` + +Now send a request: + +```shell +curl http://127.0.0.1:9080/v1/chat/completions -i -XPOST -H 'Content-Type: application/json' -d '{ + "template_name": "level of detail, + "topic": "psychology", + "level": "brief" +}' +``` + +Then the request body will be modified to something like this: + +```json +{ + "model": "some model", + "messages": [ + { "role": "user", "content": "Explain about psychology in brief." } + ] +} +``` From 5e71a00e742e451d1174229c2b1558da0485a914 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 14:46:42 +0545 Subject: [PATCH 04/15] add to index --- docs/en/latest/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/latest/config.json b/docs/en/latest/config.json index 928aec3b2b62..0998ec730cd1 100644 --- a/docs/en/latest/config.json +++ b/docs/en/latest/config.json @@ -91,6 +91,7 @@ "plugins/proxy-rewrite", "plugins/grpc-transcode", "plugins/grpc-web", + "plugins/ai-prompt-template", "plugins/fault-injection", "plugins/mocking", "plugins/degraphql", From 6bb6a40f13f99b1a3cea9f3c2daa5001c7668c59 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 14:47:53 +0545 Subject: [PATCH 05/15] plugins.t --- t/admin/plugins.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/admin/plugins.t b/t/admin/plugins.t index 911205f48cb4..547b1a316d56 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -93,6 +93,7 @@ opa authz-keycloak proxy-cache body-transformer +ai-prompt-template proxy-mirror proxy-rewrite workflow From 7f2ea98f5eba8ad90df9a099395d7ecb0b381999 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 15:16:26 +0545 Subject: [PATCH 06/15] fix local ipairs --- apisix/plugins/ai-prompt-template.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/apisix/plugins/ai-prompt-template.lua b/apisix/plugins/ai-prompt-template.lua index 47afe8f7f584..306189d37b83 100644 --- a/apisix/plugins/ai-prompt-template.lua +++ b/apisix/plugins/ai-prompt-template.lua @@ -16,6 +16,7 @@ -- local core = require("apisix.core") local body_transformer = require("apisix.plugins.body-transformer") +local ipairs = ipairs local prompt_schema = { properties = { From 16b2cbfbfa46b5bc52f1c8d7ee553beab1d23aac Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 15:42:30 +0545 Subject: [PATCH 07/15] move to correct location --- docs/en/latest/{ => plugins}/ai-prompt-template.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/en/latest/{ => plugins}/ai-prompt-template.md (100%) diff --git a/docs/en/latest/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md similarity index 100% rename from docs/en/latest/ai-prompt-template.md rename to docs/en/latest/plugins/ai-prompt-template.md From b564dbec4144e2bac3bb3367243f17b829fd9d92 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 21 Aug 2024 16:00:44 +0545 Subject: [PATCH 08/15] token --- docs/en/latest/plugins/ai-prompt-template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index bc5628352b44..c3e8aaeb188b 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -87,7 +87,7 @@ curl http://127.0.0.1:9080/v1/chat/completions -i -XPOST -H 'Content-Type: appl "template_name": "level of detail, "topic": "psychology", "level": "brief" -}' +}' -H "Authorization: Bearer " ``` Then the request body will be modified to something like this: From 7261ff0806e12ff39ea0a20cba97209226413f29 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Tue, 27 Aug 2024 15:12:20 +0545 Subject: [PATCH 09/15] cache --- apisix/plugins/ai-prompt-template.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/ai-prompt-template.lua b/apisix/plugins/ai-prompt-template.lua index 306189d37b83..0a092c3f77c0 100644 --- a/apisix/plugins/ai-prompt-template.lua +++ b/apisix/plugins/ai-prompt-template.lua @@ -77,6 +77,13 @@ local _M = { schema = schema, } +local templates_lrucache = core.lrucache.new({ + ttl = 300, count = 256 +}) + +local templates_json_lrucache = core.lrucache.new({ + ttl = 300, count = 256 +}) function _M.check_schema(conf) return core.schema.check(schema, conf) @@ -117,12 +124,12 @@ function _M.rewrite(conf, ctx) return 400, { message = "template name is missing in request." } end - local template = find_template(conf, template_name) + local template = templates_lrucache(template_name, conf, find_template, conf, template_name) if not template then return 400, { message = "template: " .. template_name .. " not configured." } end - local template_json = core.json.encode(template) + local template_json = templates_json_lrucache(template, template, core.json.encode, template) core.log.info("sending template to body_transformer: ", template_json) return body_transformer.rewrite( { From 0c52a21ce6e8398d5181012cf6f196acfb55b5e2 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Tue, 27 Aug 2024 16:41:10 +0545 Subject: [PATCH 10/15] same template test --- t/plugin/ai-prompt-template.t | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/t/plugin/ai-prompt-template.t b/t/plugin/ai-prompt-template.t index ad6bf914ba22..050e0f246268 100644 --- a/t/plugin/ai-prompt-template.t +++ b/t/plugin/ai-prompt-template.t @@ -327,3 +327,77 @@ qr/.*template: random not configured.*/ --- error_code: 400 --- response_body eval qr/.*template name is missing in request.*/ + + + +=== TEST 9: (cache test) same template name in different routes +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + for i = 1, 5, 1 do + local code = t('/apisix/admin/routes/' .. i, + ngx.HTTP_PUT, + [[{ + "uri": "/]] .. i .. [[", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "plugins": { + "ai-prompt-template": { + "templates":[ + { + "name": "same name", + "template": { + "model": "some model", + "messages": [ + { "role": "system", "content": "Field: {{ field }} in route]] .. i .. [[." } + ] + } + } + ] + }, + "proxy-rewrite": { + "uri": "/echo" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + ngx.say("failed") + return + end + end + + for i = 1, 5, 1 do + local code, body = t('/' .. i, + ngx.HTTP_POST, + [[{ + "template_name": "same name", + "field": "foo" + }]], + [[{ + "model": "some model", + "messages": [ + { "role": "system", "content": "Field: foo in route]] .. i .. [[." } + ] + }]] + ) + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + end + ngx.status = 200 + ngx.say("passed") + } + } + +--- response_body +passed From bd6a9ba0fe8fefb9df6ca40d1b0cf87501151003 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 28 Aug 2024 22:51:04 +0545 Subject: [PATCH 11/15] column rearrange --- docs/en/latest/plugins/ai-prompt-template.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index c3e8aaeb188b..4f7b1cb84b82 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -34,13 +34,13 @@ using a template and allowing users to pass only the values for template variabl ## Plugin Attributes -| **Field** | **Type** | **Description** | **Required** | -| ------------------------------------- | -------- | --------------------------------------------------- | ------------ | -| `templates` | Array | An array of template objects | Yes | -| `templates.name` | String | Name of the template. | Yes | -| `templates.template.model` | String | Model of the AI Model. Example: gpt-4, gpt-3.5 | Yes | -| `templates.template.messages.role` | String | Role of the message (`system`, `user`, `assistant`) | Yes | -| `templates.template.messages.content` | String | Content of the message. | Yes | +| **Field** | **Required** | **Type** | **Description** | +| ------------------------------------- | ------------ | -------- | --------------------------------------------------- | +| `templates` | Yes | Array | An array of template objects | +| `templates.name` | Yes | String | Name of the template. | +| `templates.template.model` | Yes | String | Model of the AI Model. Example: gpt-4, gpt-3.5 | +| `templates.template.messages.role` | Yes | String | Role of the message (`system`, `user`, `assistant`) | +| `templates.template.messages.content` | Yes | String | Content of the message. | ## Example usage From c46944f1d8bf72719b48f9b14ab2e1a0a994705d Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 28 Aug 2024 22:51:46 +0545 Subject: [PATCH 12/15] review --- docs/en/latest/plugins/ai-prompt-template.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index 4f7b1cb84b82..53e9f3a04959 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -29,8 +29,7 @@ description: This document contains information about the Apache APISIX ai-promp ## Description -The `ai-prompt-template` plugin simplifies access to AI providers and models by predefining the request format -using a template and allowing users to pass only the values for template variables. +The `ai-prompt-decorator` plugin simplifies access to LLM providers, such as OpenAI and Anthropic, and their models by appending or prepending ## Plugin Attributes From eb77af16870d225ca9c1a55338746fea6c2036c4 Mon Sep 17 00:00:00 2001 From: Shreemaan Abhishek Date: Wed, 28 Aug 2024 22:53:06 +0545 Subject: [PATCH 13/15] Apply suggestions from code review Co-authored-by: Traky Deng --- docs/en/latest/plugins/ai-prompt-template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index 53e9f3a04959..755c6c3cffe8 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -83,7 +83,7 @@ Now send a request: ```shell curl http://127.0.0.1:9080/v1/chat/completions -i -XPOST -H 'Content-Type: application/json' -d '{ - "template_name": "level of detail, + "template_name": "level of detail", "topic": "psychology", "level": "brief" }' -H "Authorization: Bearer " From d19463209db8170c9537ad45d9e03a1f564812e1 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 28 Aug 2024 22:56:23 +0545 Subject: [PATCH 14/15] fix --- docs/en/latest/plugins/ai-prompt-template.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index 53e9f3a04959..d1ff5a725411 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -29,7 +29,8 @@ description: This document contains information about the Apache APISIX ai-promp ## Description -The `ai-prompt-decorator` plugin simplifies access to LLM providers, such as OpenAI and Anthropic, and their models by appending or prepending +The `ai-prompt-template` plugin simplifies access to LLM providers, such as OpenAI and Anthropic, and their models by predefining the request format +using a template, which only allows users to pass customized values into template variables. ## Plugin Attributes From 9ece55c1e92706515f95d72ba7d3330067347acc Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Wed, 28 Aug 2024 22:57:42 +0545 Subject: [PATCH 15/15] attribute description --- docs/en/latest/plugins/ai-prompt-template.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/plugins/ai-prompt-template.md b/docs/en/latest/plugins/ai-prompt-template.md index d1ff5a725411..78decd39dcf2 100644 --- a/docs/en/latest/plugins/ai-prompt-template.md +++ b/docs/en/latest/plugins/ai-prompt-template.md @@ -34,13 +34,13 @@ using a template, which only allows users to pass customized values into templat ## Plugin Attributes -| **Field** | **Required** | **Type** | **Description** | -| ------------------------------------- | ------------ | -------- | --------------------------------------------------- | -| `templates` | Yes | Array | An array of template objects | -| `templates.name` | Yes | String | Name of the template. | -| `templates.template.model` | Yes | String | Model of the AI Model. Example: gpt-4, gpt-3.5 | -| `templates.template.messages.role` | Yes | String | Role of the message (`system`, `user`, `assistant`) | -| `templates.template.messages.content` | Yes | String | Content of the message. | +| **Field** | **Required** | **Type** | **Description** | +| ------------------------------------- | ------------ | -------- | --------------------------------------------------------------------------------------------------------------------------- | +| `templates` | Yes | Array | An array of template objects | +| `templates.name` | Yes | String | Name of the template. | +| `templates.template.model` | Yes | String | Model of the AI Model, for example `gpt-4` or `gpt-3.5`. See your LLM provider API documentation for more available models. | +| `templates.template.messages.role` | Yes | String | Role of the message (`system`, `user`, `assistant`) | +| `templates.template.messages.content` | Yes | String | Content of the message. | ## Example usage