fix merging embedding options with default ones, closes #39

This commit is contained in:
vcoppe
2024-08-05 17:52:24 +02:00
parent f8dea2a7f1
commit 4eb09f26c7
2 changed files with 14 additions and 2 deletions

View File

@@ -48,6 +48,18 @@ export function getDefaultEmbeddingOptions(): EmbeddingOptions {
return JSON.parse(JSON.stringify(defaultEmbeddingOptions));
}
export function getMergedEmbeddingOptions(options: any, defaultOptions: any = defaultEmbeddingOptions): EmbeddingOptions {
const mergedOptions = JSON.parse(JSON.stringify(defaultOptions));
for (const key in options) {
if (typeof options[key] === 'object' && options[key] !== null && !Array.isArray(options[key])) {
mergedOptions[key] = getMergedEmbeddingOptions(options[key], defaultOptions[key]);
} else {
mergedOptions[key] = options[key];
}
}
return mergedOptions;
}
export function getCleanedEmbeddingOptions(options: any, defaultOptions: any = defaultEmbeddingOptions): any {
const cleanedOptions = JSON.parse(JSON.stringify(options));
for (const key in cleanedOptions) {

View File

@@ -3,7 +3,7 @@
import { onMount } from 'svelte';
import Embedding from '$lib/components/embedding/Embedding.svelte';
import {
getDefaultEmbeddingOptions,
getMergedEmbeddingOptions,
type EmbeddingOptions
} from '$lib/components/embedding/Embedding';
@@ -18,7 +18,7 @@
if (options === null) {
return;
}
embeddingOptions = Object.assign(getDefaultEmbeddingOptions(), options);
embeddingOptions = getMergedEmbeddingOptions(options);
});
</script>