ai-prompt-decorator
描述#
ai-prompt-decorator 插件通过在请求中追加或前置提示,简化了对 LLM 提供商(如 OpenAI 和 Anthropic)及其模型的访问。
插件属性#
| 字段 | 必选项 | 类型 | 描述 |
|---|---|---|---|
prepend | 条件必选* | Array | 要前置的提示对象数组 |
prepend.role | 是 | String | 消息的角色(system、user、assistant) |
prepend.content | 是 | String | 消息的内容。最小长度:1 |
append | 条件必选* | Array | 要追加的提示对象数组 |
append.role | 是 | String | 消息的角色(system、user、assistant) |
append.content | 是 | String | 消息的内容。最小长度:1 |
* 条件必选:必须提供 prepend 或 append 中的至少一个。
使用示例#
创建一个带有 ai-prompt-decorator 插件的路由,如下所示:
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",
"plugins": {
"ai-prompt-decorator": {
"prepend":[
{
"role": "system",
"content": "我明天有考试,所以请简要地从概念上解释"
}
],
"append":[
{
"role": "system",
"content": "用一个类比来结束回答。"
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"api.openai.com:443": 1
},
"pass_host": "node",
"scheme": "https"
}
}'
现在发送一个请求:
curl http://127.0.0.1:9080/v1/chat/completions -i -XPOST -H 'Content-Type: application/json' -d '{
"model": "gpt-4",
"messages": [{ "role": "user", "content": "什么是 TLS 握手?" }]
}' -H "Authorization: Bearer <your token here>"
然后请求体将被修改为类似这样:
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "我明天有考试,所以请简要地从概念上解释"
},
{ "role": "user", "content": "什么是 TLS 握手?" },
{
"role": "system",
"content": "用一个类比来结束回答。"
}
]
}