Skip to content

Commit

Permalink
Fix settings loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rizerphe committed May 4, 2023
1 parent 3c172b3 commit e04ba5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/complete/completers/chatgpt/model_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function SettingsUI({
settings: string | null;
saveSettings: (settings: string) => void;
}) {
const parsed_settings = parse_settings(settings);
console.log(parsed_settings);
return (
<>
<SettingsItem name="Rate limits" />
Expand All @@ -54,11 +56,11 @@ export function SettingsUI({
<SettingsItem name="System prompt" />
<textarea
className="ai-complete-chatgpt-full-width"
value={parse_settings(settings).system_prompt}
value={parsed_settings.system_prompt}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
system_prompt: e.target.value,
})
)
Expand All @@ -67,11 +69,11 @@ export function SettingsUI({
<SettingsItem name="User prompt" />
<textarea
className="ai-complete-chatgpt-full-width"
value={parse_settings(settings).user_prompt}
value={parsed_settings.user_prompt}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
user_prompt: e.target.value,
})
)
Expand All @@ -80,11 +82,15 @@ export function SettingsUI({
<SettingsItem name="Temperature">
<input
type="number"
value={parse_settings(settings).temperature}
value={
parsed_settings.temperature === undefined
? ""
: parsed_settings.temperature
}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
temperature: parseFloat(e.target.value),
})
)
Expand All @@ -94,11 +100,15 @@ export function SettingsUI({
<SettingsItem name="Top P">
<input
type="number"
value={parse_settings(settings).top_p}
value={
parsed_settings.top_p === undefined
? ""
: parsed_settings.top_p
}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
top_p: parseFloat(e.target.value),
})
)
Expand All @@ -108,11 +118,15 @@ export function SettingsUI({
<SettingsItem name="Presence penalty">
<input
type="number"
value={parse_settings(settings).presence_penalty}
value={
parsed_settings.presence_penalty === undefined
? ""
: parsed_settings.presence_penalty
}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
presence_penalty: parseFloat(e.target.value),
})
)
Expand All @@ -122,11 +136,15 @@ export function SettingsUI({
<SettingsItem name="Frequency penalty">
<input
type="number"
value={parse_settings(settings).frequency_penalty}
value={
parsed_settings.frequency_penalty === undefined
? ""
: parsed_settings.frequency_penalty
}
onChange={(e) =>
saveSettings(
JSON.stringify({
...parse_settings(settings),
...parsed_settings,
frequency_penalty: parseFloat(e.target.value),
})
)
Expand Down
3 changes: 3 additions & 0 deletions src/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ function ProviderModelChooser({
if (!provider) return;
_setModel(available_models.filter((model) => model.id === model_id)[0]);
plugin.settings.model = model_id;
_setModelSettings(
plugin.settings.provider_settings[provider.id]?.models[model_id]
);
plugin.saveData(plugin.settings);
};

Expand Down

0 comments on commit e04ba5d

Please sign in to comment.