Skip to content

Commit

Permalink
Fix link hover color and add text decoration, update command menus, a…
Browse files Browse the repository at this point in the history
…nd show provider based on current model and API key
  • Loading branch information
small-stone committed Mar 28, 2024
1 parent 2a6caeb commit c3cbcda
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/views/components/MessageMarkdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const useStyles = createStyles((theme) => ({
link: {
"&:hover": {
color: theme.colors.merico[6],
textDecoration: "none",
},
},
codeOverride: {
Expand Down
4 changes: 1 addition & 3 deletions src/views/pages/ChatPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ const chatPanel = observer(() => {
messageUtil.registerHandler(
"regCommandList",
(message: { result: Item[] }) => {
console.log("regCommandList message: ", message);
const commandMenus = message.result?.map((item) => ({
...item,
recommend: item.args ?? -1,
recommend: item.recommend ?? -1,
}));
console.log("regCommandList commandMenus: ", commandMenus);
input.fetchCommandMenus(commandMenus);
if (!isFirstRender.current) {
return;
Expand Down
5 changes: 4 additions & 1 deletion src/views/pages/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ const Config = function () {
};

const disabledSubmit = isEqual(form.values, config.config);
const showProvider =
current.toLowerCase().startsWith("gpt") &&
form.values.providers?.openai?.api_key;

return (
<Drawer
Expand Down Expand Up @@ -342,7 +345,7 @@ const Config = function () {
value={form.values?.models[current]?.max_input_tokens}
onChange={(value) => changeModelDetail("max_input_tokens", value)}
/>
{current.toLowerCase().startsWith("gpt") && (
{showProvider && (
<Select
label="Provider"
placeholder="Pick one"
Expand Down
56 changes: 34 additions & 22 deletions src/views/stores/ConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@ export const ConfigStore = types
}
return "";
},
setConfig: (data) => {
setConfig: function (data) {
self.settle = false;
const newConfig = { ...data };
if (!data.models) {
newConfig.models = {};
}
if (!newConfig.providers?.openai) {
newConfig.providers.openai = {
api_key: "",
api_base: "",
};
}
if (!newConfig.providers?.devchat) {
newConfig.providers.devchat = {
api_key: "",
api_base: "",
};
}

self.modelsTemplate.forEach((item) => {
const currentModel: any = {
...item,
Expand All @@ -91,45 +104,35 @@ export const ConfigStore = types
) {
newConfig.models[item.name].provider = currentModel.provider;
}
// 只有之前配置过 openai 的,provider 才可以是 openai
if (
newConfig.models[item.name].provider === "openai" &&
!newConfig.providers.openai.api_key
) {
newConfig.models[item.name].provider = "devchat";
}
});

if (!newConfig.providers?.openai) {
newConfig.providers.openai = {
api_key: "",
api_base: "",
};
}
if (!newConfig.providers?.devchat) {
newConfig.providers.devchat = {
api_key: "",
api_base: "",
};
}
if (!defaultAPIBase.includes(newConfig.providers.devchat.api_base)) {
newConfig.providers.devchat.cumstom_api_base =
newConfig.providers.devchat.api_base;
newConfig.providers.devchat.api_base = "custom";
}
console.log("newConfig: ", newConfig);

self.config = newConfig;
self.settle = true;
self.defaultModel = newConfig.default_model;

this.writeConfig();
},
getModelList: () => {
const modelsArray = self.modelsTemplate.map((item) => {
return item.name;
});
return modelsArray;
},
setConfigValue: (key: string, value: any) => {
if (key === "default_model") {
self.defaultModel = value;
}
const cloneConfig = cloneDeep(self.config);
cloneConfig[key] = value;
self.config = cloneConfig;

writeConfig: function () {
console.log("writeConfig");
const writeConfig = cloneDeep(self.config);
if (
writeConfig.providers.devchat.api_base === "custom" &&
Expand All @@ -146,6 +149,15 @@ export const ConfigStore = types
key: "",
});
},
setConfigValue: function (key: string, value: any) {
if (key === "default_model") {
self.defaultModel = value;
}
const cloneConfig = cloneDeep(self.config);
cloneConfig[key] = value;
self.config = cloneConfig;
this.writeConfig();
},
}));

export type IConfigStore = Instance<typeof ConfigStore>;
1 change: 0 additions & 1 deletion src/views/stores/InputStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface Item {
pattern: string;
description: string;
recommend: number;
args?: number;
}

const regContextMenus = async () => {
Expand Down

0 comments on commit c3cbcda

Please sign in to comment.