Skip to content

Commit

Permalink
feat: add Google Gemini support and refactor service providers
Browse files Browse the repository at this point in the history
- Rename 'custom' to 'openai-compatible' in Service Provider options for better clarity
- Add Google Gemini as a new service provider
- Refactor code to support multiple service providers using adapter pattern
- Update configuration and documentation
  • Loading branch information
liby committed Dec 5, 2024
1 parent d73ab1b commit db18502
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 460 deletions.
44 changes: 24 additions & 20 deletions docs/configuration_manual_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,48 @@

- 必选项

- 默认值: OpenAI
- 默认值OpenAI

- 说明

- OpenAI: 使用 OpenAI 官方服务
- OpenAI使用 OpenAI 官方服务

- Azure OpenAI: 使用 [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/Translator/quickstart-text-rest-api)
- OpenAI Compatible:使用与 OpenAI 兼容的服务,如 [Ollama](https://ollama.com/blog/openai-compatibility) 等服务;或是自定义/第三方反代服务,如 [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) 或者 [Ollama](https://ollama.com/blog/openai-compatibility) 等服务

- Custom: 使用自定义服务,如 [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) 或者 [Ollama](https://ollama.com/blog/openai-compatibility) 等服务商
- Azure OpenAI:使用 [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart)

- Google Gemini:使用 [Google Gemini](https://ai.google.dev/gemini-api/docs) 服务


### API URL

- 可选项(OpenAI)/ 必填项(Azure OpenAI 和 Custom
- 可选项(OpenAI 和 Google Gemini)/ 必填项(Azure OpenAI 和 OpenAI Compatible

- 默认值:
- 默认值

- 说明

- OpenAI: 可选,默认为: `https://api.openai.com`
- OpenAI:可选,默认为:`https://api.openai.com`

- OpenAI Compatible:必填,需填入完整的 API URL,例如使用 Cloudflare AI Gateway 时,填入:

```
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
```
- Azure OpenAI: 必填,完整的 API URL,格式为:
- Azure OpenAI必填,需填入完整的 API URL,格式为:
```
https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION
```
- Custom: 必填,值为完整的 API URL,例如使用 Cloudflare AI Gateway 时,需填入:
```
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
```
- Google Gemini:可选,默认为:`https://generativelanguage.googleapis.com/v1beta/models`
### API KEY
- 必填项
- 默认值:
- 默认值
- 说明
Expand All @@ -51,7 +55,7 @@
- 必选项
- 默认值: `gpt-3.5-turbo`
- 默认值`gpt-3.5-turbo`
- 说明
Expand All @@ -61,7 +65,7 @@
- 可选项
- 默认值: `gpt-3.5-turbo`
- 默认值`gpt-3.5-turbo`
- 说明
Expand All @@ -71,7 +75,7 @@
- 可选项
- 默认值: `You are a translation engine that can only translate text and cannot interpret it.`
- 默认值`You are a translation engine that can only translate text and cannot interpret it.`
- 说明
Expand All @@ -89,7 +93,7 @@
- 可选项
- 默认值: `translate from $sourceLang to $targetLang:\n\n$text`
- 默认值`translate from $sourceLang to $targetLang:\n\n$text`
- 说明
Expand All @@ -101,7 +105,7 @@
- 可选项
- 默认值: `Enable`
- 默认值`Enable`
- 说明
Expand All @@ -113,7 +117,7 @@
- 可选项
- 默认值: `0.2`
- 默认值`0.2`
- 说明
Expand Down
22 changes: 12 additions & 10 deletions docs/configuration_manual_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@

- OpenAI: Use official OpenAI service

- Azure OpenAI: Use [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/Translator/quickstart-text-rest-api)
- OpenAI Compatible: Use OpenAI compatible service, such as [Ollama](https://ollama.com/blog/openai-compatibility) service; or custom/third-party reverse proxy service, such as [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/)

- Custom: Use custom service, such as [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) or [Ollama](https://ollama.com/blog/openai-compatibility)
- Azure OpenAI: Use [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart)

- Google Gemini: Use [Google Gemini](https://ai.google.dev/gemini-api/docs) service

### API URL

- Optional (OpenAI) / Required (Azure OpenAI and Custom)
- Optional (OpenAI and Google Gemini) / Required (Azure OpenAI and OpenAI Compatible)

- Default value: None

- Description

- OpenAI: Optional, default value: `https://api.openai.com`

- OpenAI Compatible: Required, complete API URL, for example when using Cloudflare AI Gateway:

```
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
```
- Azure OpenAI: Required, complete API URL in format:
```
https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION
```
- For more information, please refer to [Cloudflare AI Gateway Official Documentation](https://developers.cloudflare.com/ai-gateway/).
- Custom: Required, complete API URL, for example when using Cloudflare AI Gateway:
```
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
```
- Google Gemini: Optional, default value: `https://generativelanguage.googleapis.com/v1beta/models`
### API KEY
Expand Down
150 changes: 79 additions & 71 deletions public/info.json
Original file line number Diff line number Diff line change
@@ -1,74 +1,66 @@
{
"identifier": "yetone.openai.translator",
"version": "3.0.0",
"category": "translate",
"name": "OpenAI Translator",
"summary": "GPT powered translator",
"icon": "",
"appcast": "https://raw.githubusercontent.com/openai-translator/bob-plugin-openai-translator/main/appcast.json",
"author": "yetone <[email protected]>",
"category": "translate",
"homepage": "https://github.com/openai-translator/bob-plugin-openai-translator",
"appcast": "https://raw.githubusercontent.com/openai-translator/bob-plugin-openai-translator/main/appcast.json",
"icon": "",
"identifier": "yetone.openai.translator",
"minBobVersion": "1.8.0",
"name": "OpenAI Translator",
"options": [
{
"identifier": "serviceProvider",
"type": "menu",
"title": "Service Provider",
"defaultValue": "openai",
"identifier": "serviceProvider",
"menuValues": [
{
"title": "OpenAI",
"value": "openai"
},
{
"title": "OpenAI Compatible",
"value": "openai-compatible"
},
{
"title": "Azure OpenAI",
"value": "azure-openai"
},
{
"title": "Custom",
"value": "custom"
"title": "Google Gemini",
"value": "gemini"
}
]
],
"title": "Service Provider",
"type": "menu"
},
{
"desc": "OpenAI: https://api.openai.com\n\nOpenAI Compatible: 完整的 API 地址,例如:https://gateway.ai.cloudflare.com/v1/CF_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions\n\nAzure OpenAI: https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION\n\nGoogle Gemini: https://generativelanguage.googleapis.com/v1beta/models",
"identifier": "apiUrl",
"type": "text",
"title": "API URL",
"desc": "OpenAI: https://api.openai.com\n\nAzure OpenAI: https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION\n\nCustom: 您的完整 API 地址,例如:https://gateway.ai.cloudflare.com/v1/CF_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions",
"textConfig": {
"type": "visible",
"placeholderText": "https://api.openai.com"
}
"placeholderText": "https://api.openai.com",
"type": "visible"
},
"title": "API URL",
"type": "text"
},
{
"identifier": "apiKeys",
"type": "text",
"title": "API KEY",
"desc": "必填项。可以用英文逗号分割多个 API KEY 以实现额度加倍及负载均衡",
"identifier": "apiKeys",
"textConfig": {
"type": "secure",
"height": "40",
"placeholderText": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
"placeholderText": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"type": "secure"
},
"title": "API KEY",
"type": "text"
},
{
"identifier": "model",
"type": "menu",
"title": "模型",
"defaultValue": "gpt-3.5-turbo",
"identifier": "model",
"menuValues": [
{
"title": "Custom",
"value": "custom"
},
{
"title": "GPT-3.5 Turbo",
"value": "gpt-3.5-turbo"
},
{
"title": "GPT-4",
"value": "gpt-4"
},
{
"title": "GPT-4o",
"value": "gpt-4o"
Expand All @@ -82,60 +74,72 @@
"value": "gpt-4-turbo"
},
{
"title": "GPT-4 32K",
"value": "gpt-4-32k"
"title": "GPT-4",
"value": "gpt-4"
},
{
"title": "GPT-3.5 Turbo",
"value": "gpt-3.5-turbo"
},
{
"title": "Gemini 1.5 Pro",
"value": "gemini-1.5-pro"
},
{
"title": "Gemini 1.5 Flash",
"value": "gemini-1.5-flash"
}
]
],
"title": "模型",
"type": "menu"
},
{
"identifier": "customModel",
"type": "text",
"title": "自定义模型",
"desc": "可选项。当 Model 选择 Custom 时,此项为必填项。请填写有效的模型名称",
"identifier": "customModel",
"textConfig": {
"type": "visible",
"placeholderText": "gpt-3.5-turbo"
}
"placeholderText": "gpt-3.5-turbo",
"type": "visible"
},
"title": "自定义模型",
"type": "text"
},
{
"identifier": "customSystemPrompt",
"type": "text",
"title": "系统指令",
"defaultValue": "You are a translation engine that can only translate text and cannot interpret it.",
"desc": "可选项。自定义 System Prompt,填写则会覆盖默认的 System Prompt。自定义 Prompt可使用以下变量:\n\n`$text` - 需要翻译的文本,即翻译窗口输入框内的文本 `$sourceLang` - 原文语言,即翻译窗口输入框内文本的语言,比如「简体中文」\n\n`$targetLang` - 目标语言,即需要翻译成的语言,可以在翻译窗口中手动选择或自动检测,比如「English」",
"desc": "可选项。自定义 System Prompt,填写则会覆盖默认的 System Prompt。自定义 Prompt可使用以下变量:\n\n`$text` - 需要翻译的文本,即翻译窗口输入框内的文本 `$sourceLang` - 原文语言,即翻译窗口输入框内文本的语言,比如「简体中文」\n\n`$targetLang` - 目标语言,即需要翻译成的语言,可以在翻译窗口中手动选择或自动检测,例如「English」",
"identifier": "customSystemPrompt",
"textConfig": {
"type": "visible",
"height": "100",
"placeholderText": "You are a translation engine that can only translate text and cannot interpret it.",
"keyWords": [
"$text",
"$sourceLang",
"$targetLang"
]
}
],
"placeholderText": "You are a translation engine that can only translate text and cannot interpret it.",
"type": "visible"
},
"title": "系统指令",
"type": "text"
},
{
"identifier": "customUserPrompt",
"type": "text",
"title": "用户指令",
"defaultValue": "translate from $sourceLang to $targetLang:\n\n$text",
"desc": "可选项。自定义 User Prompt,填写则会覆盖默认的 User Prompt,默认值为`$text`(即翻译窗口输入框内的文本)。\n\n自定义 Prompt 中可以使用与系统指令中相同的变量",
"identifier": "customUserPrompt",
"textConfig": {
"type": "visible",
"height": "100",
"placeholderText": "translate from $sourceLang to $targetLang:\n\n$text",
"keyWords": [
"$text",
"$sourceLang",
"$targetLang"
]
}
],
"placeholderText": "translate from $sourceLang to $targetLang:\n\n$text",
"type": "visible"
},
"title": "用户指令",
"type": "text"
},
{
"identifier": "stream",
"type": "menu",
"title": "流式输出",
"defaultValue": "enable",
"identifier": "stream",
"menuValues": [
{
"title": "Enable",
Expand All @@ -145,18 +149,22 @@
"title": "Disable",
"value": "disable"
}
]
],
"title": "流式输出",
"type": "menu"
},
{
"identifier": "temperature",
"type": "text",
"title": "温度",
"defaultValue": "0.2",
"desc": "可选项。温度值越高,生成的文本越随机。默认值为 0.2",
"identifier": "temperature",
"textConfig": {
"type": "visible",
"placeholderText": "0.2"
}
"placeholderText": "0.2",
"type": "visible"
},
"title": "温度",
"type": "text"
}
]
],
"summary": "AI powered translator",
"version": "3.0.0"
}
Loading

0 comments on commit db18502

Please sign in to comment.