Copilot commented on code in PR #13210: URL: https://github.com/apache/apisix/pull/13210#discussion_r3076973466
########## docs/zh/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: ai-request-rewrite 插件在客户端请求转发到上游服务之 # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## 描述 -`ai-request-rewrite` 插件在客户端请求转发到上游服务之前拦截请求。它将预定义的提示与原始请求体一起发送到指定的 LLM 服务。LLM 处理输入并返回修改后的请求体,然后用于上游请求。这允许基于 AI 生成的内容动态转换 API 请求。 +`ai-request-rewrite` 插件在将客户端请求转发到上游服务之前,先将请求发送到 LLM 服务进行转换处理。这使得 LLM 能够对请求进行数据脱敏、内容增强或格式转换等修改。该插件支持集成 OpenAI、DeepSeek、Gemini、Vertex AI、Anthropic、OpenRouter 以及其他 OpenAI 兼容的 API。 ## 插件属性 -| **字段** | **必选项** | **类型** | **描述** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | 是 | String | 发送到 LLM 服务的提示。 | -| provider | 是 | String | LLM 服务的名称。可用选项:openai、deekseek、azure-openai、aimlapi、anthropic、openrouter、gemini、vertex-ai 和 openai-compatible。当选择 `aimlapi` 时,插件使用 OpenAI 兼容驱动程序,默认端点为 `https://api.aimlapi.com/v1/chat/completions`。 | -| provider_conf | 否 | Object | 特定提供商的配置。当 `provider` 设置为 `vertex-ai` 且未配置 `override` 时必填。 | -| provider_conf.project_id | 是 | String | Google Cloud 项目 ID。 | -| provider_conf.region | 是 | String | Google Cloud 区域。 | -| auth | 是 | Object | 身份验证配置 | -| auth.header | 否 | Object | 身份验证头部。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.query | 否 | Object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.gcp | 否 | Object | Google Cloud Platform (GCP) 身份验证配置。 | -| auth.gcp.service_account_json | 否 | String | GCP 服务账号 JSON 文件的内容。也可以通过设置“GCP_SERVICE_ACCOUNT”环境变量来配置。 | -| auth.gcp.max_ttl | 否 | Integer | 缓存 GCP 访问令牌的最大 TTL(秒)。最小值:1。 | -| auth.gcp.expire_early_secs| 否 | Integer | 在访问令牌实际过期时间之前使其过期的秒数,以避免边缘情况。最小值:0。默认值:60。 | -| options | 否 | Object | 模型的键/值设置 | -| options.model | 否 | String | 要执行的模型。示例:openai 的 "gpt-3.5-turbo",deekseek 的 "deepseek-chat",或 openai-compatible 或 aimlapi 服务的 "qwen-turbo" | -| override.endpoint | 否 | String | 使用 OpenAI 兼容服务时覆盖默认端点(例如,自托管模型或第三方 LLM 服务)。当提供商为 'openai-compatible' 时,endpoint 字段是必需的。 | -| timeout | 否 | Integer | 对 LLM 服务请求的总超时时间(毫秒),包括连接、发送和读取超时。范围:1 - 60000。默认值:30000| -| keepalive | 否 | Boolean | 为对 LLM 服务的请求启用 keepalive。默认值:true | -| keepalive_timeout | 否 | Integer | 对 LLM 服务请求的 keepalive 超时时间(毫秒)。最小值:1000。默认值:60000 | -| keepalive_pool | 否 | Integer | 对 LLM 服务请求的 keepalive 池大小。最小值:1。默认值:30 | -| ssl_verify | 否 | Boolean | 对 LLM 服务请求的 SSL 验证。默认值:true | - -## 工作原理 - - +| **字段** | **必选项** | **类型** | **描述** | +| --- | --- | --- | --- | +| `prompt` | True | string | 发送到 LLM 服务用于重写客户端请求的提示词。 | +| `provider` | True | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除用户请求中的 `model` 参数。 | +| `auth` | True | object | 身份验证配置。 | +| `auth.header` | False | object | 身份验证请求头。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `auth.query` | False | object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `options` | False | object | 模型配置。除了 `model` 之外,还可以配置其他参数,这些参数会在请求体中转发给上游 LLM 服务。例如,使用 OpenAI 时,可以配置 `temperature`、`top_p` 和 `stream` 等参数。更多可用选项请参阅 LLM 提供商的 API 文档。 | +| `options.model` | False | string | LLM 模型名称,例如 `gpt-4` 或 `gpt-3.5`。更多可用模型请参阅 LLM 提供商的 API 文档。 | +| `override` | False | object | 覆盖设置。 | +| `override.endpoint` | False | string | LLM 提供商端点。当 `provider` 为 `openai-compatible` 时必填。 | +| `timeout` | False | integer | 请求 LLM 服务的超时时间(毫秒)。范围:1 - 60000。默认值:`30000`。 | +| `keepalive` | False | boolean | 是否在请求 LLM 服务时保持连接。默认值:`true`。 | +| `keepalive_timeout` | False | integer | 请求 LLM 服务的 keepalive 超时时间(毫秒)。最小值:`1000`。默认值:`60000`。 | Review Comment: 文档声明 `keepalive_timeout` 默认值为 `60000`,但 `ai-request-rewrite` 插件的 schema 未定义该字段及默认值(实现中会读取 `conf.keepalive_timeout`)。建议:要么在文档里去掉默认值/最小值描述并说明需要显式配置,要么先补齐插件 schema 再在文档中保留该默认值说明,避免与实际行为不一致。 ```suggestion | `keepalive_timeout` | False | integer | 请求 LLM 服务的 keepalive 超时时间(毫秒)。该参数需要显式配置。 | ``` ########## docs/zh/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: ai-request-rewrite 插件在客户端请求转发到上游服务之 # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## 描述 -`ai-request-rewrite` 插件在客户端请求转发到上游服务之前拦截请求。它将预定义的提示与原始请求体一起发送到指定的 LLM 服务。LLM 处理输入并返回修改后的请求体,然后用于上游请求。这允许基于 AI 生成的内容动态转换 API 请求。 +`ai-request-rewrite` 插件在将客户端请求转发到上游服务之前,先将请求发送到 LLM 服务进行转换处理。这使得 LLM 能够对请求进行数据脱敏、内容增强或格式转换等修改。该插件支持集成 OpenAI、DeepSeek、Gemini、Vertex AI、Anthropic、OpenRouter 以及其他 OpenAI 兼容的 API。 ## 插件属性 -| **字段** | **必选项** | **类型** | **描述** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | 是 | String | 发送到 LLM 服务的提示。 | -| provider | 是 | String | LLM 服务的名称。可用选项:openai、deekseek、azure-openai、aimlapi、anthropic、openrouter、gemini、vertex-ai 和 openai-compatible。当选择 `aimlapi` 时,插件使用 OpenAI 兼容驱动程序,默认端点为 `https://api.aimlapi.com/v1/chat/completions`。 | -| provider_conf | 否 | Object | 特定提供商的配置。当 `provider` 设置为 `vertex-ai` 且未配置 `override` 时必填。 | -| provider_conf.project_id | 是 | String | Google Cloud 项目 ID。 | -| provider_conf.region | 是 | String | Google Cloud 区域。 | -| auth | 是 | Object | 身份验证配置 | -| auth.header | 否 | Object | 身份验证头部。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.query | 否 | Object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.gcp | 否 | Object | Google Cloud Platform (GCP) 身份验证配置。 | -| auth.gcp.service_account_json | 否 | String | GCP 服务账号 JSON 文件的内容。也可以通过设置“GCP_SERVICE_ACCOUNT”环境变量来配置。 | -| auth.gcp.max_ttl | 否 | Integer | 缓存 GCP 访问令牌的最大 TTL(秒)。最小值:1。 | -| auth.gcp.expire_early_secs| 否 | Integer | 在访问令牌实际过期时间之前使其过期的秒数,以避免边缘情况。最小值:0。默认值:60。 | -| options | 否 | Object | 模型的键/值设置 | -| options.model | 否 | String | 要执行的模型。示例:openai 的 "gpt-3.5-turbo",deekseek 的 "deepseek-chat",或 openai-compatible 或 aimlapi 服务的 "qwen-turbo" | -| override.endpoint | 否 | String | 使用 OpenAI 兼容服务时覆盖默认端点(例如,自托管模型或第三方 LLM 服务)。当提供商为 'openai-compatible' 时,endpoint 字段是必需的。 | -| timeout | 否 | Integer | 对 LLM 服务请求的总超时时间(毫秒),包括连接、发送和读取超时。范围:1 - 60000。默认值:30000| -| keepalive | 否 | Boolean | 为对 LLM 服务的请求启用 keepalive。默认值:true | -| keepalive_timeout | 否 | Integer | 对 LLM 服务请求的 keepalive 超时时间(毫秒)。最小值:1000。默认值:60000 | -| keepalive_pool | 否 | Integer | 对 LLM 服务请求的 keepalive 池大小。最小值:1。默认值:30 | -| ssl_verify | 否 | Boolean | 对 LLM 服务请求的 SSL 验证。默认值:true | - -## 工作原理 - - +| **字段** | **必选项** | **类型** | **描述** | +| --- | --- | --- | --- | +| `prompt` | True | string | 发送到 LLM 服务用于重写客户端请求的提示词。 | +| `provider` | True | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除用户请求中的 `model` 参数。 | +| `auth` | True | object | 身份验证配置。 | +| `auth.header` | False | object | 身份验证请求头。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `auth.query` | False | object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `options` | False | object | 模型配置。除了 `model` 之外,还可以配置其他参数,这些参数会在请求体中转发给上游 LLM 服务。例如,使用 OpenAI 时,可以配置 `temperature`、`top_p` 和 `stream` 等参数。更多可用选项请参阅 LLM 提供商的 API 文档。 | +| `options.model` | False | string | LLM 模型名称,例如 `gpt-4` 或 `gpt-3.5`。更多可用模型请参阅 LLM 提供商的 API 文档。 | +| `override` | False | object | 覆盖设置。 | +| `override.endpoint` | False | string | LLM 提供商端点。当 `provider` 为 `openai-compatible` 时必填。 | +| `timeout` | False | integer | 请求 LLM 服务的超时时间(毫秒)。范围:1 - 60000。默认值:`30000`。 | +| `keepalive` | False | boolean | 是否在请求 LLM 服务时保持连接。默认值:`true`。 | +| `keepalive_timeout` | False | integer | 请求 LLM 服务的 keepalive 超时时间(毫秒)。最小值:`1000`。默认值:`60000`。 | Review Comment: 表格的“必选项”列当前使用 True/False,但中文插件文档里该列通常使用“是/否”(例如 ai-proxy)。建议将本表的 True/False 统一改为 是/否 以保持中文文档一致性。 ```suggestion | `prompt` | 是 | string | 发送到 LLM 服务用于重写客户端请求的提示词。 | | `provider` | 是 | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除用户请求中的 `model` 参数。 | | `auth` | 是 | object | 身份验证配置。 | | `auth.header` | 否 | object | 身份验证请求头。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | | `auth.query` | 否 | object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | | `options` | 否 | object | 模型配置。除了 `model` 之外,还可以配置其他参数,这些参数会在请求体中转发给上游 LLM 服务。例如,使用 OpenAI 时,可以配置 `temperature`、`top_p` 和 `stream` 等参数。更多可用选项请参阅 LLM 提供商的 API 文档。 | | `options.model` | 否 | string | LLM 模型名称,例如 `gpt-4` 或 `gpt-3.5`。更多可用模型请参阅 LLM 提供商的 API 文档。 | | `override` | 否 | object | 覆盖设置。 | | `override.endpoint` | 否 | string | LLM 提供商端点。当 `provider` 为 `openai-compatible` 时必填。 | | `timeout` | 否 | integer | 请求 LLM 服务的超时时间(毫秒)。范围:1 - 60000。默认值:`30000`。 | | `keepalive` | 否 | boolean | 是否在请求 LLM 服务时保持连接。默认值:`true`。 | | `keepalive_timeout` | 否 | integer | 请求 LLM 服务的 keepalive 超时时间(毫秒)。最小值:`1000`。默认值:`60000`。 | ``` ########## docs/zh/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: ai-request-rewrite 插件在客户端请求转发到上游服务之 # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## 描述 -`ai-request-rewrite` 插件在客户端请求转发到上游服务之前拦截请求。它将预定义的提示与原始请求体一起发送到指定的 LLM 服务。LLM 处理输入并返回修改后的请求体,然后用于上游请求。这允许基于 AI 生成的内容动态转换 API 请求。 +`ai-request-rewrite` 插件在将客户端请求转发到上游服务之前,先将请求发送到 LLM 服务进行转换处理。这使得 LLM 能够对请求进行数据脱敏、内容增强或格式转换等修改。该插件支持集成 OpenAI、DeepSeek、Gemini、Vertex AI、Anthropic、OpenRouter 以及其他 OpenAI 兼容的 API。 ## 插件属性 -| **字段** | **必选项** | **类型** | **描述** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | 是 | String | 发送到 LLM 服务的提示。 | -| provider | 是 | String | LLM 服务的名称。可用选项:openai、deekseek、azure-openai、aimlapi、anthropic、openrouter、gemini、vertex-ai 和 openai-compatible。当选择 `aimlapi` 时,插件使用 OpenAI 兼容驱动程序,默认端点为 `https://api.aimlapi.com/v1/chat/completions`。 | -| provider_conf | 否 | Object | 特定提供商的配置。当 `provider` 设置为 `vertex-ai` 且未配置 `override` 时必填。 | -| provider_conf.project_id | 是 | String | Google Cloud 项目 ID。 | -| provider_conf.region | 是 | String | Google Cloud 区域。 | -| auth | 是 | Object | 身份验证配置 | -| auth.header | 否 | Object | 身份验证头部。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.query | 否 | Object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.gcp | 否 | Object | Google Cloud Platform (GCP) 身份验证配置。 | -| auth.gcp.service_account_json | 否 | String | GCP 服务账号 JSON 文件的内容。也可以通过设置“GCP_SERVICE_ACCOUNT”环境变量来配置。 | -| auth.gcp.max_ttl | 否 | Integer | 缓存 GCP 访问令牌的最大 TTL(秒)。最小值:1。 | -| auth.gcp.expire_early_secs| 否 | Integer | 在访问令牌实际过期时间之前使其过期的秒数,以避免边缘情况。最小值:0。默认值:60。 | -| options | 否 | Object | 模型的键/值设置 | -| options.model | 否 | String | 要执行的模型。示例:openai 的 "gpt-3.5-turbo",deekseek 的 "deepseek-chat",或 openai-compatible 或 aimlapi 服务的 "qwen-turbo" | -| override.endpoint | 否 | String | 使用 OpenAI 兼容服务时覆盖默认端点(例如,自托管模型或第三方 LLM 服务)。当提供商为 'openai-compatible' 时,endpoint 字段是必需的。 | -| timeout | 否 | Integer | 对 LLM 服务请求的总超时时间(毫秒),包括连接、发送和读取超时。范围:1 - 60000。默认值:30000| -| keepalive | 否 | Boolean | 为对 LLM 服务的请求启用 keepalive。默认值:true | -| keepalive_timeout | 否 | Integer | 对 LLM 服务请求的 keepalive 超时时间(毫秒)。最小值:1000。默认值:60000 | -| keepalive_pool | 否 | Integer | 对 LLM 服务请求的 keepalive 池大小。最小值:1。默认值:30 | -| ssl_verify | 否 | Boolean | 对 LLM 服务请求的 SSL 验证。默认值:true | - -## 工作原理 - - +| **字段** | **必选项** | **类型** | **描述** | +| --- | --- | --- | --- | +| `prompt` | True | string | 发送到 LLM 服务用于重写客户端请求的提示词。 | +| `provider` | True | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除用户请求中的 `model` 参数。 | Review Comment: `provider` 字段对 `azure-openai` 的描述里提到“会额外移除用户请求中的 `model` 参数”,但从实现上看移除的是发送给 Azure OpenAI 上游的请求体里的 `model` 字段(由 provider 驱动处理),不是“用户请求”。建议调整表述以避免误解。 ```suggestion | `provider` | True | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除发送给 Azure OpenAI 上游的请求体中的 `model` 字段。 | ``` ########## docs/en/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: The ai-request-rewrite plugin intercepts client requests before the # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## Description -The `ai-request-rewrite` plugin intercepts client requests before they are forwarded to the upstream service. It sends a predefined prompt, along with the original request body, to a specified LLM service. The LLM processes the input and returns a modified request body, which is then used for the upstream request. This allows dynamic transformation of API requests based on AI-generated content. +The `ai-request-rewrite` Plugin processes client requests by forwarding them to LLM services for transformation before relaying them to Upstream services. This enables LLM-powered modifications such as data redaction, content enrichment, or reformatting. The Plugin supports integration with OpenAI, DeepSeek, Gemini, Vertex AI, Anthropic, OpenRouter, and other OpenAI-compatible APIs. ## Plugin Attributes -| **Field** | **Required** | **Type** | **Description** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | Yes | String | The prompt send to LLM service. | -| provider | Yes | String | Name of the LLM service. Available options: openai, deekseek, azure-openai, aimlapi, anthropic, openrouter, gemini, vertex-ai, and openai-compatible. When `aimlapi` is selected, the plugin uses the OpenAI-compatible driver with a default endpoint of `https://api.aimlapi.com/v1/chat/completions`. | -| provider_conf | No | Object | Configuration for the specific provider. Required when `provider` is set to `vertex-ai` and `override` is not configured. | -| provider_conf.project_id | Yes | String | Google Cloud Project ID. | -| provider_conf.region | Yes | String | Google Cloud Region. | -| auth | Yes | Object | Authentication configuration | -| auth.header | No | Object | Authentication headers. Key must match pattern `^[a-zA-Z0-9._-]+$`. | -| auth.query | No | Object | Authentication query parameters. Key must match pattern `^[a-zA-Z0-9._-]+$`. | -| auth.gcp | No | Object | Configuration for Google Cloud Platform (GCP) authentication. | -| auth.gcp.service_account_json | No | String | Content of the GCP service account JSON file. This can also be configured by setting the `GCP_SERVICE_ACCOUNT` environment variable. | -| auth.gcp.max_ttl | No | Integer | Maximum TTL (in seconds) for caching the GCP access token. Minimum: 1. | -| auth.gcp.expire_early_secs| No | Integer | Seconds to expire the access token before its actual expiration time to avoid edge cases. Minimum: 0. Default: 60. | -| options | No | Object | Key/value settings for the model | -| options.model | No | String | Model to execute. Examples: "gpt-3.5-turbo" for openai, "deepseek-chat" for deekseek, or "qwen-turbo" for openai-compatible or aimlapi services | -| override.endpoint | No | String | Override the default endpoint when using OpenAI-compatible services (e.g., self-hosted models or third-party LLM services). When the provider is 'openai-compatible', the endpoint field is required. | -| timeout | No | Integer | Total timeout in milliseconds for requests to LLM service, including connect, send, and read timeouts. Range: 1 - 60000. Default: 30000| -| keepalive | No | Boolean | Enable keepalive for requests to LLM service. Default: true | -| keepalive_timeout | No | Integer | Keepalive timeout in milliseconds for requests to LLM service. Minimum: 1000. Default: 60000 | -| keepalive_pool | No | Integer | Keepalive pool size for requests to LLM service. Minimum: 1. Default: 30 | -| ssl_verify | No | Boolean | SSL verification for requests to LLM service. Default: true | - -## How it works - - +| **Field** | **Required** | **Type** | **Description** | +| --- | --- | --- | --- | +| `prompt` | True | string | The prompt to send to the LLM service for rewriting the client request. | +| `provider` | True | string | LLM service provider. Valid values: `openai`, `deepseek`, `azure-openai`, `aimlapi`, `gemini`, `vertex-ai`, `anthropic`, `openrouter`, `openai-compatible`. When set to `aimlapi`, the Plugin uses the OpenAI-compatible driver and proxies the request to `https://api.aimlapi.com/v1/chat/completions`. When set to `openai-compatible`, the Plugin proxies requests to the custom endpoint configured in `override`. When set to `azure-openai`, the Plugin also proxies requests to the custom endpoint configured in `override` and additionally removes the `model` parameter from user requests. | Review Comment: `provider` row says Azure OpenAI “removes the `model` parameter from user requests”, but in implementation the provider removes `model` from the request body sent to Azure OpenAI (not from the original client request). Please rephrase to avoid implying the plugin mutates client-supplied `model`. ```suggestion | `provider` | True | string | LLM service provider. Valid values: `openai`, `deepseek`, `azure-openai`, `aimlapi`, `gemini`, `vertex-ai`, `anthropic`, `openrouter`, `openai-compatible`. When set to `aimlapi`, the Plugin uses the OpenAI-compatible driver and proxies the request to `https://api.aimlapi.com/v1/chat/completions`. When set to `openai-compatible`, the Plugin proxies requests to the custom endpoint configured in `override`. When set to `azure-openai`, the Plugin also proxies requests to the custom endpoint configured in `override` and additionally omits the `model` parameter from the request body sent to Azure OpenAI. | ``` ########## docs/zh/latest/plugins/ai-request-rewrite.md: ########## @@ -102,53 +115,633 @@ curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \ }' ``` -现在发送一个请求: +</TabItem> +<TabItem value="adc" label="ADC"> + +创建带有 `ai-request-rewrite` 插件的路由: + +```yaml title="adc.yaml" +services: + - name: ai-request-rewrite-service + routes: + - name: ai-request-rewrite-route + uris: + - /anything + methods: + - POST + plugins: + ai-request-rewrite: + provider: openai + auth: + header: + Authorization: "Bearer ${OPENAI_API_KEY}" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." + upstream: + type: roundrobin + nodes: + - host: httpbin.org + port: 80 + weight: 1 +``` + +将配置同步到网关: ```shell -curl "http://127.0.0.1:9080/anything" \ +adc sync -f adc.yaml +``` + +</TabItem> +<TabItem value="ingress" label="Ingress Controller"> + +<Tabs groupId="k8s-api"> +<TabItem value="gateway-api" label="Gateway API"> + +```yaml title="ai-request-rewrite-gw.yaml" +apiVersion: v1 +kind: Service +metadata: + namespace: aic + name: httpbin-external-domain +spec: + type: ExternalName + externalName: httpbin.org +--- +apiVersion: apisix.apache.org/v1alpha1 +kind: PluginConfig +metadata: + namespace: aic + name: ai-request-rewrite-plugin-config +spec: + plugins: + - name: ai-request-rewrite + config: + provider: openai + auth: + header: + Authorization: "Bearer your-api-key" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + namespace: aic + name: ai-request-rewrite-route +spec: + parentRefs: + - name: apisix + rules: + - matches: + - path: + type: Exact + value: /anything + method: POST + filters: + - type: ExtensionRef + extensionRef: + group: apisix.apache.org + kind: PluginConfig + name: ai-request-rewrite-plugin-config + backendRefs: + - name: httpbin-external-domain + port: 80 +``` + +</TabItem> +<TabItem value="ingress" label="APISIX Ingress Controller"> + +```yaml title="ai-request-rewrite-ic.yaml" +apiVersion: apisix.apache.org/v2 +kind: ApisixUpstream +metadata: + namespace: aic + name: httpbin-external-domain +spec: + ingressClassName: apisix + externalNodes: + - type: Domain + name: httpbin.org +--- +apiVersion: apisix.apache.org/v2 +kind: ApisixRoute +metadata: + namespace: aic + name: ai-request-rewrite-route +spec: + ingressClassName: apisix + http: + - name: ai-request-rewrite-route + match: + paths: + - /anything + methods: + - POST + upstreams: + - name: httpbin-external-domain + plugins: + - name: ai-request-rewrite + enable: true + config: + provider: openai + auth: + header: + Authorization: "Bearer your-api-key" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." +``` + +</TabItem> +</Tabs> + +将配置应用到集群: + +```shell +kubectl apply -f ai-request-rewrite-ic.yaml +``` + +</TabItem> +</Tabs> + +发送一个包含个人敏感信息的 POST 请求到路由: + +```shell +curl "http://127.0.0.1:9080/anything" -X POST \ -H "Content-Type: application/json" \ -d '{ - "name": "John Doe", - "email": "[email protected]", - "credit_card": "4111 1111 1111 1111", - "ssn": "123-45-6789", - "address": "123 Main St" + "content": "John said his debit card number is 4111 1111 1111 1111 and SIN is 123-45-6789." }' ``` -发送到 LLM 服务的请求体如下: +你应该收到类似以下的响应: ```json { - "messages": [ - { - "role": "system", - "content": "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., '*** **** **** 1234') for credit card numbers). Ensure the JSON structure remains unchanged." - }, - { - "role": "user", - "content": "{\n\"name\":\"John Doe\",\n\"email\":\"[email protected]\",\n\"credit_card\":\"4111 1111 1111 1111\",\n\"ssn\":\"123-45-6789\",\n\"address\":\"123 Main St\"\n}" - } - ] + "args": {}, + "data": "{\n \"content\": \"John said his debit card number is **** **** **** 1111 and SIN is ***-**-****.\"\n }", + ..., + "json": { + "messages": [ + { + "content": "Client information from customer service calls", + "role": "system" + }, + { + "content": "John said his debit card number is **** **** **** 1111 and SIN is ***-**-****.", + "role": "user" + } + ], + "model": "openai" Review Comment: 这里的示例响应里 `data` 显示上游收到的是 `{ "content": ... }`,但紧接着的 `json` 字段却展示了 `messages/model`(更像是发往 LLM 的 OpenAI 请求体)。`ai-request-rewrite` 会把请求体替换为 LLM 返回的文本再转发给上游,因此示例响应应与重写后的请求体一致。建议更新该响应示例,避免读者误解转发到上游的内容。 ```suggestion "content": "John said his debit card number is **** **** **** 1111 and SIN is ***-**-****." ``` ########## docs/en/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: The ai-request-rewrite plugin intercepts client requests before the # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## Description -The `ai-request-rewrite` plugin intercepts client requests before they are forwarded to the upstream service. It sends a predefined prompt, along with the original request body, to a specified LLM service. The LLM processes the input and returns a modified request body, which is then used for the upstream request. This allows dynamic transformation of API requests based on AI-generated content. +The `ai-request-rewrite` Plugin processes client requests by forwarding them to LLM services for transformation before relaying them to Upstream services. This enables LLM-powered modifications such as data redaction, content enrichment, or reformatting. The Plugin supports integration with OpenAI, DeepSeek, Gemini, Vertex AI, Anthropic, OpenRouter, and other OpenAI-compatible APIs. ## Plugin Attributes -| **Field** | **Required** | **Type** | **Description** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | Yes | String | The prompt send to LLM service. | -| provider | Yes | String | Name of the LLM service. Available options: openai, deekseek, azure-openai, aimlapi, anthropic, openrouter, gemini, vertex-ai, and openai-compatible. When `aimlapi` is selected, the plugin uses the OpenAI-compatible driver with a default endpoint of `https://api.aimlapi.com/v1/chat/completions`. | -| provider_conf | No | Object | Configuration for the specific provider. Required when `provider` is set to `vertex-ai` and `override` is not configured. | -| provider_conf.project_id | Yes | String | Google Cloud Project ID. | -| provider_conf.region | Yes | String | Google Cloud Region. | -| auth | Yes | Object | Authentication configuration | -| auth.header | No | Object | Authentication headers. Key must match pattern `^[a-zA-Z0-9._-]+$`. | -| auth.query | No | Object | Authentication query parameters. Key must match pattern `^[a-zA-Z0-9._-]+$`. | -| auth.gcp | No | Object | Configuration for Google Cloud Platform (GCP) authentication. | -| auth.gcp.service_account_json | No | String | Content of the GCP service account JSON file. This can also be configured by setting the `GCP_SERVICE_ACCOUNT` environment variable. | -| auth.gcp.max_ttl | No | Integer | Maximum TTL (in seconds) for caching the GCP access token. Minimum: 1. | -| auth.gcp.expire_early_secs| No | Integer | Seconds to expire the access token before its actual expiration time to avoid edge cases. Minimum: 0. Default: 60. | -| options | No | Object | Key/value settings for the model | -| options.model | No | String | Model to execute. Examples: "gpt-3.5-turbo" for openai, "deepseek-chat" for deekseek, or "qwen-turbo" for openai-compatible or aimlapi services | -| override.endpoint | No | String | Override the default endpoint when using OpenAI-compatible services (e.g., self-hosted models or third-party LLM services). When the provider is 'openai-compatible', the endpoint field is required. | -| timeout | No | Integer | Total timeout in milliseconds for requests to LLM service, including connect, send, and read timeouts. Range: 1 - 60000. Default: 30000| -| keepalive | No | Boolean | Enable keepalive for requests to LLM service. Default: true | -| keepalive_timeout | No | Integer | Keepalive timeout in milliseconds for requests to LLM service. Minimum: 1000. Default: 60000 | -| keepalive_pool | No | Integer | Keepalive pool size for requests to LLM service. Minimum: 1. Default: 30 | -| ssl_verify | No | Boolean | SSL verification for requests to LLM service. Default: true | - -## How it works - - +| **Field** | **Required** | **Type** | **Description** | +| --- | --- | --- | --- | +| `prompt` | True | string | The prompt to send to the LLM service for rewriting the client request. | +| `provider` | True | string | LLM service provider. Valid values: `openai`, `deepseek`, `azure-openai`, `aimlapi`, `gemini`, `vertex-ai`, `anthropic`, `openrouter`, `openai-compatible`. When set to `aimlapi`, the Plugin uses the OpenAI-compatible driver and proxies the request to `https://api.aimlapi.com/v1/chat/completions`. When set to `openai-compatible`, the Plugin proxies requests to the custom endpoint configured in `override`. When set to `azure-openai`, the Plugin also proxies requests to the custom endpoint configured in `override` and additionally removes the `model` parameter from user requests. | +| `auth` | True | object | Authentication configurations. | +| `auth.header` | False | object | Authentication headers. Key must match pattern `^[a-zA-Z0-9._-]+$`. At least one of `header` and `query` should be configured. | +| `auth.query` | False | object | Authentication query parameters. Key must match pattern `^[a-zA-Z0-9._-]+$`. At least one of `header` and `query` should be configured. | +| `options` | False | object | Model configurations. In addition to `model`, you can configure additional parameters and they will be forwarded to the upstream LLM service in the request body. For instance, if you are working with OpenAI, you can configure additional parameters such as `temperature`, `top_p`, and `stream`. See your LLM provider's API documentation for more available options. | +| `options.model` | False | string | Name of the LLM model, such as `gpt-4` or `gpt-3.5`. See your LLM provider's API documentation for more available models. | +| `override` | False | object | Override setting. | +| `override.endpoint` | False | string | LLM provider endpoint. Required when `provider` is `openai-compatible`. | +| `timeout` | False | integer | Request timeout in milliseconds when requesting the LLM service. Range: 1 - 60000. Default: `30000`. | +| `keepalive` | False | boolean | If true, keep the connection alive when requesting the LLM service. Default: `true`. | +| `keepalive_timeout` | False | integer | Keepalive timeout in milliseconds for requests to the LLM service. Minimum: `1000`. Default: `60000`. | Review Comment: The docs claim `keepalive_timeout` has a default of `60000`, but `ai-request-rewrite`'s plugin schema does not define `keepalive_timeout` (and therefore doesn't apply a default), even though the implementation reads `conf.keepalive_timeout`. Please either remove/adjust the default/minimum claims in the docs or update the plugin schema so the documented default is actually applied. ```suggestion | `keepalive_timeout` | False | integer | Keepalive timeout in milliseconds for requests to the LLM service. | ``` ########## docs/en/latest/plugins/ai-request-rewrite.md: ########## @@ -102,53 +115,633 @@ curl "http://127.0.0.1:9180/apisix/admin/routes/1" -X PUT \ }' ``` -Now send a request: +</TabItem> +<TabItem value="adc" label="ADC"> + +Create a Route with the `ai-request-rewrite` Plugin: + +```yaml title="adc.yaml" +services: + - name: ai-request-rewrite-service + routes: + - name: ai-request-rewrite-route + uris: + - /anything + methods: + - POST + plugins: + ai-request-rewrite: + provider: openai + auth: + header: + Authorization: "Bearer ${OPENAI_API_KEY}" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." + upstream: + type: roundrobin + nodes: + - host: httpbin.org + port: 80 + weight: 1 +``` + +Synchronize the configuration to the gateway: ```shell -curl "http://127.0.0.1:9080/anything" \ +adc sync -f adc.yaml +``` + +</TabItem> +<TabItem value="ingress" label="Ingress Controller"> + +<Tabs groupId="k8s-api"> +<TabItem value="gateway-api" label="Gateway API"> + +```yaml title="ai-request-rewrite-gw.yaml" +apiVersion: v1 +kind: Service +metadata: + namespace: aic + name: httpbin-external-domain +spec: + type: ExternalName + externalName: httpbin.org +--- +apiVersion: apisix.apache.org/v1alpha1 +kind: PluginConfig +metadata: + namespace: aic + name: ai-request-rewrite-plugin-config +spec: + plugins: + - name: ai-request-rewrite + config: + provider: openai + auth: + header: + Authorization: "Bearer your-api-key" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + namespace: aic + name: ai-request-rewrite-route +spec: + parentRefs: + - name: apisix + rules: + - matches: + - path: + type: Exact + value: /anything + method: POST + filters: + - type: ExtensionRef + extensionRef: + group: apisix.apache.org + kind: PluginConfig + name: ai-request-rewrite-plugin-config + backendRefs: + - name: httpbin-external-domain + port: 80 +``` + +</TabItem> +<TabItem value="ingress" label="APISIX Ingress Controller"> + +```yaml title="ai-request-rewrite-ic.yaml" +apiVersion: apisix.apache.org/v2 +kind: ApisixUpstream +metadata: + namespace: aic + name: httpbin-external-domain +spec: + ingressClassName: apisix + externalNodes: + - type: Domain + name: httpbin.org +--- +apiVersion: apisix.apache.org/v2 +kind: ApisixRoute +metadata: + namespace: aic + name: ai-request-rewrite-route +spec: + ingressClassName: apisix + http: + - name: ai-request-rewrite-route + match: + paths: + - /anything + methods: + - POST + upstreams: + - name: httpbin-external-domain + plugins: + - name: ai-request-rewrite + enable: true + config: + provider: openai + auth: + header: + Authorization: "Bearer your-api-key" + options: + model: gpt-4 + prompt: "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., \"*** **** **** 1234\") for credit card numbers. Ensure the JSON structure remains unchanged." +``` + +</TabItem> +</Tabs> + +Apply the configuration to your cluster: + +```shell +kubectl apply -f ai-request-rewrite-ic.yaml +``` + +</TabItem> +</Tabs> + +Send a POST request to the Route with some personally identifiable information: + +```shell +curl "http://127.0.0.1:9080/anything" -X POST \ -H "Content-Type: application/json" \ -d '{ - "name": "John Doe", - "email": "[email protected]", - "credit_card": "4111 1111 1111 1111", - "ssn": "123-45-6789", - "address": "123 Main St" + "content": "John said his debit card number is 4111 1111 1111 1111 and SIN is 123-45-6789." }' ``` -The request body send to the LLM Service is as follows: +You should receive a response similar to the following: ```json { - "messages": [ - { - "role": "system", - "content": "Given a JSON request body, identify and mask any sensitive information such as credit card numbers, social security numbers, and personal identification numbers (e.g., passport or driver's license numbers). Replace detected sensitive values with a masked format (e.g., '*** **** **** 1234') for credit card numbers). Ensure the JSON structure remains unchanged." - }, - { - "role": "user", - "content": "{\n\"name\":\"John Doe\",\n\"email\":\"[email protected]\",\n\"credit_card\":\"4111 1111 1111 1111\",\n\"ssn\":\"123-45-6789\",\n\"address\":\"123 Main St\"\n}" - } - ] + "args": {}, + "data": "{\n \"content\": \"John said his debit card number is **** **** **** 1111 and SIN is ***-**-****.\"\n }", + ..., + "json": { + "messages": [ + { + "content": "Client information from customer service calls", + "role": "system" + }, + { + "content": "John said his debit card number is **** **** **** 1111 and SIN is ***-**-****.", + "role": "user" + } + ], + "model": "openai" Review Comment: In this example response, `data` shows the upstream received `{ "content": ... }`, but the `json` field then shows `messages`/`model` (which looks like the sidecar OpenAI request). Since `ai-request-rewrite` replaces the client request body with the LLM output before proxying upstream, the example response should reflect the rewritten body consistently. Please update the response snippet to match the actual upstream payload. ```suggestion "content": "John said his debit card number is **** **** **** 1111 and SIN is ***-**-****." ``` ########## docs/zh/latest/plugins/ai-request-rewrite.md: ########## @@ -27,70 +27,83 @@ description: ai-request-rewrite 插件在客户端请求转发到上游服务之 # --> +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/ai-request-rewrite" /> +</head> + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## 描述 -`ai-request-rewrite` 插件在客户端请求转发到上游服务之前拦截请求。它将预定义的提示与原始请求体一起发送到指定的 LLM 服务。LLM 处理输入并返回修改后的请求体,然后用于上游请求。这允许基于 AI 生成的内容动态转换 API 请求。 +`ai-request-rewrite` 插件在将客户端请求转发到上游服务之前,先将请求发送到 LLM 服务进行转换处理。这使得 LLM 能够对请求进行数据脱敏、内容增强或格式转换等修改。该插件支持集成 OpenAI、DeepSeek、Gemini、Vertex AI、Anthropic、OpenRouter 以及其他 OpenAI 兼容的 API。 ## 插件属性 -| **字段** | **必选项** | **类型** | **描述** | -| ------------------------- | ------------ | -------- | ------------------------------------------------------------------------------------ | -| prompt | 是 | String | 发送到 LLM 服务的提示。 | -| provider | 是 | String | LLM 服务的名称。可用选项:openai、deekseek、azure-openai、aimlapi、anthropic、openrouter、gemini、vertex-ai 和 openai-compatible。当选择 `aimlapi` 时,插件使用 OpenAI 兼容驱动程序,默认端点为 `https://api.aimlapi.com/v1/chat/completions`。 | -| provider_conf | 否 | Object | 特定提供商的配置。当 `provider` 设置为 `vertex-ai` 且未配置 `override` 时必填。 | -| provider_conf.project_id | 是 | String | Google Cloud 项目 ID。 | -| provider_conf.region | 是 | String | Google Cloud 区域。 | -| auth | 是 | Object | 身份验证配置 | -| auth.header | 否 | Object | 身份验证头部。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.query | 否 | Object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。 | -| auth.gcp | 否 | Object | Google Cloud Platform (GCP) 身份验证配置。 | -| auth.gcp.service_account_json | 否 | String | GCP 服务账号 JSON 文件的内容。也可以通过设置“GCP_SERVICE_ACCOUNT”环境变量来配置。 | -| auth.gcp.max_ttl | 否 | Integer | 缓存 GCP 访问令牌的最大 TTL(秒)。最小值:1。 | -| auth.gcp.expire_early_secs| 否 | Integer | 在访问令牌实际过期时间之前使其过期的秒数,以避免边缘情况。最小值:0。默认值:60。 | -| options | 否 | Object | 模型的键/值设置 | -| options.model | 否 | String | 要执行的模型。示例:openai 的 "gpt-3.5-turbo",deekseek 的 "deepseek-chat",或 openai-compatible 或 aimlapi 服务的 "qwen-turbo" | -| override.endpoint | 否 | String | 使用 OpenAI 兼容服务时覆盖默认端点(例如,自托管模型或第三方 LLM 服务)。当提供商为 'openai-compatible' 时,endpoint 字段是必需的。 | -| timeout | 否 | Integer | 对 LLM 服务请求的总超时时间(毫秒),包括连接、发送和读取超时。范围:1 - 60000。默认值:30000| -| keepalive | 否 | Boolean | 为对 LLM 服务的请求启用 keepalive。默认值:true | -| keepalive_timeout | 否 | Integer | 对 LLM 服务请求的 keepalive 超时时间(毫秒)。最小值:1000。默认值:60000 | -| keepalive_pool | 否 | Integer | 对 LLM 服务请求的 keepalive 池大小。最小值:1。默认值:30 | -| ssl_verify | 否 | Boolean | 对 LLM 服务请求的 SSL 验证。默认值:true | - -## 工作原理 - - +| **字段** | **必选项** | **类型** | **描述** | +| --- | --- | --- | --- | +| `prompt` | True | string | 发送到 LLM 服务用于重写客户端请求的提示词。 | +| `provider` | True | string | LLM 服务提供商。可选值:`openai`、`deepseek`、`azure-openai`、`aimlapi`、`gemini`、`vertex-ai`、`anthropic`、`openrouter`、`openai-compatible`。设置为 `aimlapi` 时,插件使用 OpenAI 兼容驱动并将请求代理到 `https://api.aimlapi.com/v1/chat/completions`。设置为 `openai-compatible` 时,插件将请求代理到 `override` 中配置的自定义端点。设置为 `azure-openai` 时,插件同样将请求代理到 `override` 中配置的自定义端点,并会额外移除用户请求中的 `model` 参数。 | +| `auth` | True | object | 身份验证配置。 | +| `auth.header` | False | object | 身份验证请求头。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `auth.query` | False | object | 身份验证查询参数。键必须匹配模式 `^[a-zA-Z0-9._-]+$`。`header` 和 `query` 至少需要配置其中一个。 | +| `options` | False | object | 模型配置。除了 `model` 之外,还可以配置其他参数,这些参数会在请求体中转发给上游 LLM 服务。例如,使用 OpenAI 时,可以配置 `temperature`、`top_p` 和 `stream` 等参数。更多可用选项请参阅 LLM 提供商的 API 文档。 | +| `options.model` | False | string | LLM 模型名称,例如 `gpt-4` 或 `gpt-3.5`。更多可用模型请参阅 LLM 提供商的 API 文档。 | +| `override` | False | object | 覆盖设置。 | +| `override.endpoint` | False | string | LLM 提供商端点。当 `provider` 为 `openai-compatible` 时必填。 | +| `timeout` | False | integer | 请求 LLM 服务的超时时间(毫秒)。范围:1 - 60000。默认值:`30000`。 | +| `keepalive` | False | boolean | 是否在请求 LLM 服务时保持连接。默认值:`true`。 | +| `keepalive_timeout` | False | integer | 请求 LLM 服务的 keepalive 超时时间(毫秒)。最小值:`1000`。默认值:`60000`。 | +| `keepalive_pool` | False | integer | 连接 LLM 服务的 keepalive 连接池大小。最小值:`1`。默认值:`30`。 | +| `ssl_verify` | False | boolean | 是否验证 LLM 服务的 SSL 证书。默认值:`true`。 | ## 示例 -以下示例演示了如何为不同场景配置 `ai-request-rewrite`。 +以下示例演示如何为不同场景配置 `ai-request-rewrite`。 + +示例使用 OpenAI 作为 LLM 服务。请先获取 OpenAI [API 密钥](https://openai.com/blog/openai-api)并将其保存到环境变量: + +```shell +export OPENAI_API_KEY=<your-api-key> +``` :::note -您可以使用以下命令从 config.yaml 获取 admin_key 并保存到环境变量中: +你可以使用以下命令从 `config.yaml` 中获取 `admin_key` 并保存到环境变量: Review Comment: 同一套中文插件文档中 note 语气通常使用“您可以…”。这里使用“你可以…”与其他页面不一致,建议改为“您可以…”,以保持整体风格统一。 ```suggestion 您可以使用以下命令从 `config.yaml` 中获取 `admin_key` 并保存到环境变量: ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
