Skip to content

Commit 028eefc

Browse files
committed
feat: add Google Gemini support and refactor service providers
- 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
1 parent d73ab1b commit 028eefc

11 files changed

+687
-460
lines changed

docs/configuration_manual_CN.md

+24-20
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,48 @@
44

55
- 必选项
66

7-
- 默认值: OpenAI
7+
- 默认值OpenAI
88

99
- 说明
1010

11-
- OpenAI: 使用 OpenAI 官方服务
11+
- OpenAI使用 OpenAI 官方服务
1212

13-
- Azure OpenAI: 使用 [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/Translator/quickstart-text-rest-api)
13+
- 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) 等服务
1414

15-
- Custom: 使用自定义服务,如 [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) 或者 [Ollama](https://ollama.com/blog/openai-compatibility) 等服务商
15+
- Azure OpenAI:使用 [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart)
16+
17+
- Google Gemini:使用 [Google Gemini](https://ai.google.dev/gemini-api/docs) 服务
1618

1719

1820
### API URL
1921

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

22-
- 默认值:
24+
- 默认值
2325

2426
- 说明
2527

26-
- OpenAI: 可选,默认为: `https://api.openai.com`
28+
- OpenAI:可选,默认为:`https://api.openai.com`
29+
30+
- OpenAI Compatible:必填,需填入完整的 API URL,例如使用 Cloudflare AI Gateway 时,填入:
31+
32+
```
33+
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
34+
```
2735
28-
- Azure OpenAI: 必填,完整的 API URL,格式为:
36+
- Azure OpenAI必填,需填入完整的 API URL,格式为:
2937
3038
```
3139
https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION
3240
```
3341
34-
- Custom: 必填,值为完整的 API URL,例如使用 Cloudflare AI Gateway 时,需填入:
35-
36-
```
37-
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
38-
```
42+
- Google Gemini:可选,默认为:`https://generativelanguage.googleapis.com/v1beta/models`
3943
4044
### API KEY
4145
4246
- 必填项
4347
44-
- 默认值:
48+
- 默认值
4549
4650
- 说明
4751
@@ -51,7 +55,7 @@
5155
5256
- 必选项
5357
54-
- 默认值: `gpt-3.5-turbo`
58+
- 默认值`gpt-3.5-turbo`
5559
5660
- 说明
5761
@@ -61,7 +65,7 @@
6165
6266
- 可选项
6367
64-
- 默认值: `gpt-3.5-turbo`
68+
- 默认值`gpt-3.5-turbo`
6569
6670
- 说明
6771
@@ -71,7 +75,7 @@
7175
7276
- 可选项
7377
74-
- 默认值: `You are a translation engine that can only translate text and cannot interpret it.`
78+
- 默认值`You are a translation engine that can only translate text and cannot interpret it.`
7579
7680
- 说明
7781
@@ -89,7 +93,7 @@
8993
9094
- 可选项
9195
92-
- 默认值: `translate from $sourceLang to $targetLang:\n\n$text`
96+
- 默认值`translate from $sourceLang to $targetLang:\n\n$text`
9397
9498
- 说明
9599
@@ -101,7 +105,7 @@
101105
102106
- 可选项
103107
104-
- 默认值: `Enable`
108+
- 默认值`Enable`
105109
106110
- 说明
107111
@@ -113,7 +117,7 @@
113117
114118
- 可选项
115119
116-
- 默认值: `0.2`
120+
- 默认值`0.2`
117121
118122
- 说明
119123

docs/configuration_manual_EN.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@
1010

1111
- OpenAI: Use official OpenAI service
1212

13-
- Azure OpenAI: Use [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/Translator/quickstart-text-rest-api)
13+
- 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/)
1414

15-
- Custom: Use custom service, such as [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) or [Ollama](https://ollama.com/blog/openai-compatibility)
15+
- Azure OpenAI: Use [Azure OpenAI Service](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart)
16+
17+
- Google Gemini: Use [Google Gemini](https://ai.google.dev/gemini-api/docs) service
1618

1719
### API URL
1820

19-
- Optional (OpenAI) / Required (Azure OpenAI and Custom)
21+
- Optional (OpenAI and Google Gemini) / Required (Azure OpenAI and OpenAI Compatible)
2022

2123
- Default value: None
2224

2325
- Description
2426

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

29+
- OpenAI Compatible: Required, complete API URL, for example when using Cloudflare AI Gateway:
30+
31+
```
32+
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
33+
```
34+
2735
- Azure OpenAI: Required, complete API URL in format:
2836
2937
```
3038
https://RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION
3139
```
3240
33-
- For more information, please refer to [Cloudflare AI Gateway Official Documentation](https://developers.cloudflare.com/ai-gateway/).
34-
35-
- Custom: Required, complete API URL, for example when using Cloudflare AI Gateway:
36-
37-
```
38-
https://gateway.ai.cloudflare.com/v1/CLOUDFLARE_ACCOUNT_ID/GATEWAY_ID/openai/chat/completions
39-
```
41+
- Google Gemini: Optional, default value: `https://generativelanguage.googleapis.com/v1beta/models`
4042
4143
### API KEY
4244

public/info.json

+79-71
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,66 @@
11
{
2-
"identifier": "yetone.openai.translator",
3-
"version": "3.0.0",
4-
"category": "translate",
5-
"name": "OpenAI Translator",
6-
"summary": "GPT powered translator",
7-
"icon": "",
2+
"appcast": "https://raw.githubusercontent.com/openai-translator/bob-plugin-openai-translator/main/appcast.json",
83
"author": "yetone <[email protected]>",
4+
"category": "translate",
95
"homepage": "https://github.com/openai-translator/bob-plugin-openai-translator",
10-
"appcast": "https://raw.githubusercontent.com/openai-translator/bob-plugin-openai-translator/main/appcast.json",
6+
"icon": "",
7+
"identifier": "yetone.openai.translator",
118
"minBobVersion": "1.8.0",
9+
"name": "OpenAI Translator",
1210
"options": [
1311
{
14-
"identifier": "serviceProvider",
15-
"type": "menu",
16-
"title": "Service Provider",
1712
"defaultValue": "openai",
13+
"identifier": "serviceProvider",
1814
"menuValues": [
1915
{
2016
"title": "OpenAI",
2117
"value": "openai"
2218
},
19+
{
20+
"title": "OpenAI Compatible",
21+
"value": "openai-compatible"
22+
},
2323
{
2424
"title": "Azure OpenAI",
2525
"value": "azure-openai"
2626
},
2727
{
28-
"title": "Custom",
29-
"value": "custom"
28+
"title": "Google Gemini",
29+
"value": "gemini"
3030
}
31-
]
31+
],
32+
"title": "Service Provider",
33+
"type": "menu"
3234
},
3335
{
36+
"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",
3437
"identifier": "apiUrl",
35-
"type": "text",
36-
"title": "API URL",
37-
"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",
3838
"textConfig": {
39-
"type": "visible",
40-
"placeholderText": "https://api.openai.com"
41-
}
39+
"placeholderText": "https://api.openai.com",
40+
"type": "visible"
41+
},
42+
"title": "API URL",
43+
"type": "text"
4244
},
4345
{
44-
"identifier": "apiKeys",
45-
"type": "text",
46-
"title": "API KEY",
4746
"desc": "必填项。可以用英文逗号分割多个 API KEY 以实现额度加倍及负载均衡",
47+
"identifier": "apiKeys",
4848
"textConfig": {
49-
"type": "secure",
5049
"height": "40",
51-
"placeholderText": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
52-
}
50+
"placeholderText": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
51+
"type": "secure"
52+
},
53+
"title": "API KEY",
54+
"type": "text"
5355
},
5456
{
55-
"identifier": "model",
56-
"type": "menu",
57-
"title": "模型",
5857
"defaultValue": "gpt-3.5-turbo",
58+
"identifier": "model",
5959
"menuValues": [
6060
{
6161
"title": "Custom",
6262
"value": "custom"
6363
},
64-
{
65-
"title": "GPT-3.5 Turbo",
66-
"value": "gpt-3.5-turbo"
67-
},
68-
{
69-
"title": "GPT-4",
70-
"value": "gpt-4"
71-
},
7264
{
7365
"title": "GPT-4o",
7466
"value": "gpt-4o"
@@ -82,60 +74,72 @@
8274
"value": "gpt-4-turbo"
8375
},
8476
{
85-
"title": "GPT-4 32K",
86-
"value": "gpt-4-32k"
77+
"title": "GPT-4",
78+
"value": "gpt-4"
79+
},
80+
{
81+
"title": "GPT-3.5 Turbo",
82+
"value": "gpt-3.5-turbo"
83+
},
84+
{
85+
"title": "Gemini 1.5 Pro",
86+
"value": "gemini-1.5-pro"
87+
},
88+
{
89+
"title": "Gemini 1.5 Flash",
90+
"value": "gemini-1.5-flash"
8791
}
88-
]
92+
],
93+
"title": "模型",
94+
"type": "menu"
8995
},
9096
{
91-
"identifier": "customModel",
92-
"type": "text",
93-
"title": "自定义模型",
9497
"desc": "可选项。当 Model 选择 Custom 时,此项为必填项。请填写有效的模型名称",
98+
"identifier": "customModel",
9599
"textConfig": {
96-
"type": "visible",
97-
"placeholderText": "gpt-3.5-turbo"
98-
}
100+
"placeholderText": "gpt-3.5-turbo",
101+
"type": "visible"
102+
},
103+
"title": "自定义模型",
104+
"type": "text"
99105
},
100106
{
101-
"identifier": "customSystemPrompt",
102-
"type": "text",
103-
"title": "系统指令",
104107
"defaultValue": "You are a translation engine that can only translate text and cannot interpret it.",
105-
"desc": "可选项。自定义 System Prompt,填写则会覆盖默认的 System Prompt。自定义 Prompt可使用以下变量:\n\n`$text` - 需要翻译的文本,即翻译窗口输入框内的文本 `$sourceLang` - 原文语言,即翻译窗口输入框内文本的语言,比如「简体中文」\n\n`$targetLang` - 目标语言,即需要翻译成的语言,可以在翻译窗口中手动选择或自动检测,比如「English」",
108+
"desc": "可选项。自定义 System Prompt,填写则会覆盖默认的 System Prompt。自定义 Prompt可使用以下变量:\n\n`$text` - 需要翻译的文本,即翻译窗口输入框内的文本 `$sourceLang` - 原文语言,即翻译窗口输入框内文本的语言,比如「简体中文」\n\n`$targetLang` - 目标语言,即需要翻译成的语言,可以在翻译窗口中手动选择或自动检测,例如「English」",
109+
"identifier": "customSystemPrompt",
106110
"textConfig": {
107-
"type": "visible",
108111
"height": "100",
109-
"placeholderText": "You are a translation engine that can only translate text and cannot interpret it.",
110112
"keyWords": [
111113
"$text",
112114
"$sourceLang",
113115
"$targetLang"
114-
]
115-
}
116+
],
117+
"placeholderText": "You are a translation engine that can only translate text and cannot interpret it.",
118+
"type": "visible"
119+
},
120+
"title": "系统指令",
121+
"type": "text"
116122
},
117123
{
118-
"identifier": "customUserPrompt",
119-
"type": "text",
120-
"title": "用户指令",
121124
"defaultValue": "translate from $sourceLang to $targetLang:\n\n$text",
122125
"desc": "可选项。自定义 User Prompt,填写则会覆盖默认的 User Prompt,默认值为`$text`(即翻译窗口输入框内的文本)。\n\n自定义 Prompt 中可以使用与系统指令中相同的变量",
126+
"identifier": "customUserPrompt",
123127
"textConfig": {
124-
"type": "visible",
125128
"height": "100",
126-
"placeholderText": "translate from $sourceLang to $targetLang:\n\n$text",
127129
"keyWords": [
128130
"$text",
129131
"$sourceLang",
130132
"$targetLang"
131-
]
132-
}
133+
],
134+
"placeholderText": "translate from $sourceLang to $targetLang:\n\n$text",
135+
"type": "visible"
136+
},
137+
"title": "用户指令",
138+
"type": "text"
133139
},
134140
{
135-
"identifier": "stream",
136-
"type": "menu",
137-
"title": "流式输出",
138141
"defaultValue": "enable",
142+
"identifier": "stream",
139143
"menuValues": [
140144
{
141145
"title": "Enable",
@@ -145,18 +149,22 @@
145149
"title": "Disable",
146150
"value": "disable"
147151
}
148-
]
152+
],
153+
"title": "流式输出",
154+
"type": "menu"
149155
},
150156
{
151-
"identifier": "temperature",
152-
"type": "text",
153-
"title": "温度",
154157
"defaultValue": "0.2",
155158
"desc": "可选项。温度值越高,生成的文本越随机。默认值为 0.2",
159+
"identifier": "temperature",
156160
"textConfig": {
157-
"type": "visible",
158-
"placeholderText": "0.2"
159-
}
161+
"placeholderText": "0.2",
162+
"type": "visible"
163+
},
164+
"title": "温度",
165+
"type": "text"
160166
}
161-
]
167+
],
168+
"summary": "AI powered translator",
169+
"version": "3.0.0"
162170
}

0 commit comments

Comments
 (0)