Skip to content

Commit

Permalink
allow embedding model fields to be saved
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq committed Dec 6, 2024
1 parent 6df1247 commit a24b436
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/jupyter-ai/src/components/chat-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
const [apiKeys, setApiKeys] = useState<Record<string, string>>({});
const [sendWse, setSendWse] = useState<boolean>(false);
const [fields, setFields] = useState<Record<string, any>>({});
const [embeddingModelFields, setEmbeddingModelFields] = useState<
Record<string, any>
>({});

const [isCompleterEnabled, setIsCompleterEnabled] = useState(
props.completionProvider && props.completionProvider.isEnabled()
Expand Down Expand Up @@ -188,7 +191,15 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
const currFields: Record<string, any> =
server.config.fields?.[lmGlobalId] ?? {};
setFields(currFields);
}, [server, lmProvider]);

if (!emGlobalId) {
return;
}

const initEmbeddingModelFields: Record<string, any> =
server.config.fields?.[emGlobalId] ?? {};
setEmbeddingModelFields(initEmbeddingModelFields);
}, [server, lmGlobalId, emGlobalId]);

const handleSave = async () => {
// compress fields with JSON values
Expand Down Expand Up @@ -222,6 +233,9 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
}),
...(clmGlobalId && {
[clmGlobalId]: fields
}),
...(emGlobalId && {
[emGlobalId]: embeddingModelFields
})
}
}),
Expand Down Expand Up @@ -400,8 +414,8 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
{emGlobalId && (
<ModelFields
fields={emProvider?.fields}
values={fields}
onChange={setFields}
values={embeddingModelFields}
onChange={setEmbeddingModelFields}
/>
)}
</Box>
Expand Down

0 comments on commit a24b436

Please sign in to comment.