自定义 AI 模块
此模块帮助您连接 Crowdin 尚未支持的 AI 提供商。 创建此类应用后,您将能够使用所连接的 AI 提供商自动翻译内容,并将该 AI 提供商作为编辑器中的助手使用。
您可以将此模块的访问权限授予以下用户类别之一:
对于 Crowdin:
- 仅限我自己(即项目所有者)
- 所有项目成员
- 选定用户
对于 Crowdin Enterprise:
- 仅限组织管理员
- 组织项目中的所有用户
- 选定用户
{ "modules": { "ai-provider": [ { "key": "custom-ai", "name": "Custom Open AI", "logo": "/logo.png", "url": "/ai-settings", "chatCompletionsUrl": "/chat/completions", "modelsUrl": "/models" } ] }}key | 类型: 必填: 是 描述: Crowdin 应用内的模块标识符。 |
name | 类型: 必填: 是 描述: 模块的可读名称。 |
logo | 类型: 必填: 是 描述: 自定义 AI 徽标的相对 URL,将在 Crowdin 界面中显示。 |
url | 类型: 必填: 否 说明: 模块设置页面的相对 URL(例如,AI 提供商凭据设置等)。 |
chatCompletionsUrl | 类型: 必填: 是 说明: 用于获取聊天补全的相对 URL。 |
modelsUrl | 类型: 必填: 是 说明: 用于检索 AI 提供商所支持模型列表的相对 URL。 |
environments | 类型: 允许值: 描述: 可安装该模块的环境集合。 |
restrictAiToSameApp | 类型: 说明: 如果您的应用程序同时实现了 AI Provider 和 AI Prompt Provider 模块,并且需要限制它们仅成对使用,可以使用 |
Crowdin 使用 chatCompletionsUrl 向应用发送提示词,应用处理这些提示词后将回复发送给 Crowdin。
为了在 Crowdin 编辑器中将自定义 AI 作为助手使用时获得更好的体验,建议使用服务器发送事件来实现 stream 参数。
支持流式传输后,AI 生成的内容可以逐步交付,为用户提供实时反馈。 这通过提供即时建议或更正,无需等待完整响应,来改善工作流程,确保在确认术语、检查一致性或优化译文等任务中获得流畅的交互体验。
Crowdin 在向应用发送 chatCompletions 请求时,会将 stream 参数设置为 true,并期望收到相应格式的响应。
在 AI > 提供商页面配置自定义 AI 提供商时,Crowdin 会使用 modelsUrl 向应用发送请求,专门用于在自定义 AI 提供商设置页面的相应输入字段中显示可用模型。 您可以选择并保存所需的模型,这些模型随后将通过 chatCompletionsUrl 用于内容自动翻译以及与助手的通信。
HTTP 请求:
https://{AppBaseUrl}/chat/completions/请求头
向 chatCompletionsUrl 发送的请求将包含授权头(例如,Authorization: Bearer \<App JWT token>)。
请求载荷示例:
{ "model": "gpt-3.5-turbo",
"stream": false, "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Prompt" }, { "type": "image", "mimeType": "image/png", "url": "https://picsum.photos/200/300" } ] }, { "role": "assistant", "content": "Reply" }, { "role": "user", "content": "New prompt" } ]}响应载荷示例:
{ "choices": [ { "message": { "role": "assistant", "content": "New reply" } } ]}响应载荷示例:
data: {"choices":[{"delta":{"role":"assistant","content":"Your"}}]}
data: {"choices":[{"delta":{"role":"assistant","content":" rephrased"}}]}
....
data: {"choices":[{"delta":{"role":"assistant","content":" translation"}}]}
[DONE]响应载荷示例:
{ "data": [ { "id": "gpt-3.5-turbo", "supportsJsonMode": true, "supportsFunctionCalling": true, "supportsVision": false, "contextWindowLimit": 16385, "outputLimit": 4096 }, { "id": "gpt-4-turbo", "supportsJsonMode": true, "supportsFunctionCalling": true, "supportsVision": true, "contextWindowLimit": 128000, "outputLimit": 4096 }, { "id": "gpt-5-power", "supportsJsonMode": true, "supportsFunctionCalling": true, "supportsVision": true, "contextWindowLimit": 1000000, "outputLimit": 8192 }, { "id": "gpt-6-devil", "supportsJsonMode": true, "supportsFunctionCalling": true, "supportsStreaming": true, "supportsVision": true, "contextWindowLimit": 1000000, "outputLimit": 8192 }, { "id": "gpt-7-magic", "supportsJsonMode": true, "supportsFunctionCalling": true, "supportsStreaming": true, "supportsVision": true, "contextWindowLimit": 1000000, "outputLimit": 8192 } ]}默认值:
- supportsJsonMode:
false - supportsFunctionCalling:
false - supportsStreaming:
false - supportsVision:
false - contextWindowLimit:
4096 - outputLimit:
4096
应用返回的响应结构应与所提供的示例一致,否则 Crowdin 将视其为无效。