Skip to content

Commit a49c00a

Browse files
committed
Update i18n translations and ConfigStore
1 parent 6004387 commit a49c00a

4 files changed

Lines changed: 97 additions & 35 deletions

File tree

src/models/index.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,72 @@ const modelsTemplate = [
44
provider: "devchat",
55
stream: true,
66
max_input_tokens: 13000,
7-
// temperature: 0.3,
8-
// max_tokens: 2048,
97
},
108
{
119
name: "gpt-4",
1210
provider: "devchat",
1311
stream: true,
1412
max_input_tokens: 6000,
15-
// temperature: 0.3,
16-
// max_tokens: 2048,
1713
},
1814
{
1915
name: "gpt-4-turbo-preview",
2016
provider: "devchat",
2117
stream: true,
2218
max_input_tokens: 32000,
23-
// temperature: 0.3,
24-
// max_tokens: 2048,
2519
},
2620
{
27-
name: "claude-2.1",
21+
name: "claude-3-opus",
22+
provider: "devchat",
23+
stream: true,
24+
max_input_tokens: 32000,
25+
},
26+
{
27+
name: "claude-3-sonnet",
2828
provider: "devchat",
2929
stream: true,
3030
max_input_tokens: 32000,
31-
// temperature: 0.3,
32-
// max_tokens: 2048,
3331
},
3432
{
3533
name: "xinghuo-3.5",
3634
provider: "devchat",
3735
stream: true,
3836
max_input_tokens: 6000,
39-
// temperature: 0.3,
40-
// max_tokens: 2048,
4137
},
4238
{
4339
name: "GLM-4",
4440
provider: "devchat",
4541
stream: true,
4642
max_input_tokens: 8000,
47-
// temperature: 0.3,
48-
// max_tokens: 2048,
4943
},
5044
{
5145
name: "ERNIE-Bot-4.0",
5246
provider: "devchat",
5347
stream: true,
5448
max_input_tokens: 8000,
55-
// temperature: 0.3,
56-
// max_tokens: 2048,
5749
},
5850
{
5951
name: "togetherai/codellama/CodeLlama-70b-Instruct-hf",
6052
provider: "devchat",
6153
stream: true,
6254
max_input_tokens: 4000,
63-
// temperature: 0.3,
64-
// max_tokens: 2048,
6555
},
6656
{
6757
name: "togetherai/mistralai/Mixtral-8x7B-Instruct-v0.1",
6858
provider: "devchat",
6959
stream: true,
70-
// max_input_tokens: 4000,
71-
// temperature: 0.3,
72-
// max_tokens: 2048,
60+
max_input_tokens: 4000,
7361
},
7462
{
7563
name: "minimax/abab6-chat",
7664
provider: "devchat",
7765
stream: true,
78-
// max_input_tokens: 4000,
79-
// temperature: 0.3,
80-
// max_tokens: 2048,
66+
max_input_tokens: 4000,
8167
},
8268
{
8369
name: "llama-2-70b-chat",
8470
provider: "devchat",
8571
stream: true,
86-
// max_input_tokens: 4000,
87-
// temperature: 0.3,
88-
// max_tokens: 2048,
72+
max_input_tokens: 4000,
8973
},
9074
];
9175

src/views/i18n/zh.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@
2424
"note-explain": "使用这个工作流程,您可以生成专业的、格式化的发布说明(markdown格式)。我只需要关于本次发布的提交的一些基本信息。通过点击“+”按钮并选择 git_log_releasenote 将这些信息添加到上下文中。如果提交的范围与默认命令不同,您还可以选择 <custom command> 并输入如 git log 579398b^..HEAD --pretty=format:\"%h - %B\" 的命令行来包含从提交 579398b(包括此提交)到最新提交的所有变更。",
2525
"Explain /code": "解释 /code",
2626
"code-explain": "使用 DevChat 工作流程来请求编写代码。请输入您的具体需求,并提供适当的实施上下文。您可以选择相关的代码或文件,然后右键点击“添加到 DevChat”。如果您发现上下文仍然不足以解释清楚,您可以通过提供所选代码的类/函数定义来增强我对您代码的理解。要做到这一点,请点击所选代码旁边的“+”按钮,然后选择“符号定义”。请注意,这些信息显示在 DevChat 中可能需要几秒钟时间。",
27-
"Config": "配置"
27+
"Config": "配置",
28+
"Singapore Node": "新加坡区节点",
29+
"China Node": "中国区节点",
30+
"Custom": "自定义",
31+
"Custom API Base of Devchat": "自定义 DevChat API 地址"
2832
}

src/views/pages/Config.tsx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useState, forwardRef } from "react";
22
import {
33
Title,
44
Box,
@@ -67,6 +67,22 @@ const Config = function () {
6767
const { config } = useMst();
6868
const router = useRouter();
6969
const { i18n, t } = useTranslation();
70+
71+
const apiSelection = [
72+
{
73+
value: "https://api.devchat.ai/v1",
74+
label: t("Singapore Node"),
75+
},
76+
{
77+
value: "https://api.devchat-ai.cn/v1",
78+
label: t("China Node"),
79+
},
80+
{
81+
value: "custom",
82+
label: t("Custom"),
83+
},
84+
];
85+
7086
const form = useForm({
7187
initialValues: {
7288
providers: {},
@@ -80,6 +96,10 @@ const Config = function () {
8096
// value.length > 0 ? null : "Please enter access key",
8197
api_base: (value) =>
8298
value.length > 0 ? null : "Please enter api base",
99+
cumstom_api_base: (value, values) =>
100+
values.providers.devchat.api_base === "custom" && value.length > 0
101+
? null
102+
: "Please enter custom api base",
83103
},
84104
},
85105
},
@@ -107,6 +127,16 @@ const Config = function () {
107127
useEffect(() => {
108128
if (router.currentRoute !== "config") return;
109129
const cloneConfig = cloneDeep(config.config);
130+
if (
131+
cloneConfig?.providers?.devchat?.api_base !== apiSelection[0].value ||
132+
cloneConfig?.providers?.devchat?.api_base !== apiSelection[1].value
133+
) {
134+
cloneConfig.providers.devchat.api_base = "custom";
135+
}
136+
console.log(
137+
"cloneConfig.providers.devchat.api_base: ",
138+
cloneConfig.providers.devchat.api_base
139+
);
110140
form.setValues(cloneConfig);
111141
if (config.settle && loading) {
112142
setTimeout(() => {
@@ -119,9 +149,15 @@ const Config = function () {
119149
const onSave = (values) => {
120150
config.updateSettle(false);
121151
startLoading();
152+
const writeConfig = cloneDeep(self.config);
153+
if (writeConfig.providers.devchat.cumstom_api_base) {
154+
writeConfig.providers.devchat.api_base =
155+
writeConfig.providers.devchat.cumstom_api_base;
156+
delete writeConfig.providers.devchat.cumstom_api_base;
157+
}
122158
MessageUtil.sendMessage({
123159
command: "writeConfig",
124-
value: values,
160+
value: writeConfig,
125161
key: "",
126162
});
127163
MessageUtil.sendMessage({ command: "readConfig", key: "" });
@@ -219,14 +255,26 @@ const Config = function () {
219255
}}
220256
>
221257
<Stack>
222-
<TextInput
258+
<Select
259+
data={apiSelection}
223260
styles={commonInputStyle}
224261
placeholder="https://xxxx.xx"
225262
label={t("API Base of Devchat")}
226263
withAsterisk
227264
description={t("the base URL for the API")}
228265
{...form.getInputProps("providers.devchat.api_base")}
229266
/>
267+
{form.values.providers.devchat.api_base === "custom" && (
268+
<TextInput
269+
styles={commonInputStyle}
270+
label={t("Custom API Base of Devchat")}
271+
withAsterisk
272+
description={t("the base URL for the API")}
273+
{...form.getInputProps(
274+
"providers.devchat.cumstom_api_base"
275+
)}
276+
/>
277+
)}
230278

231279
<PasswordInput
232280
styles={commonInputStyle}

src/views/stores/ConfigStore.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import MessageUtil from "@/util/MessageUtil";
22
import { types, Instance } from "mobx-state-tree";
33
import modelsTemplate from "@/models";
4+
import cloneDeep from "lodash.clonedeep";
5+
6+
const defaultAPIBase = [
7+
"https://api.devchat.ai",
8+
"https://api.devchat-ai.cn/v1",
9+
];
410

511
export const ConfigStore = types
612
.model("Config", {
@@ -72,8 +78,20 @@ export const ConfigStore = types
7278
api_base: "",
7379
};
7480
}
75-
self.config = newConfig;
81+
if (!newConfig.providers?.devchat) {
82+
newConfig.providers.devchat = {
83+
api_key: "",
84+
api_base: "",
85+
};
86+
}
87+
if (!defaultAPIBase.includes(newConfig.providers.devchat.api_base)) {
88+
newConfig.providers.devchat.cumstom_api_base =
89+
newConfig.providers.devchat.api_base;
90+
newConfig.providers.devchat.api_base = "custom";
91+
}
7692
console.log("newConfig: ", newConfig);
93+
94+
self.config = newConfig;
7795
self.settle = true;
7896
self.defaultModel = newConfig.default_model;
7997
},
@@ -87,12 +105,20 @@ export const ConfigStore = types
87105
if (key === "default_model") {
88106
self.defaultModel = value;
89107
}
90-
const newConfig = { ...self.config };
91-
newConfig[key] = value;
92-
self.config = newConfig;
108+
const cloneConfig = cloneDeep(self.config);
109+
cloneConfig[key] = value;
110+
self.config = cloneConfig;
111+
112+
const writeConfig = cloneDeep(self.config);
113+
if (writeConfig.providers.devchat.cumstom_api_base) {
114+
writeConfig.providers.devchat.api_base =
115+
writeConfig.providers.devchat.cumstom_api_base;
116+
delete writeConfig.providers.devchat.cumstom_api_base;
117+
}
118+
93119
MessageUtil.sendMessage({
94120
command: "writeConfig",
95-
value: newConfig,
121+
value: writeConfig,
96122
key: "",
97123
});
98124
},

0 commit comments

Comments
 (0)