mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(llm): also add embeddings options for embedding creation
This commit is contained in:
parent
3dee462476
commit
63722a28a2
@ -83,11 +83,17 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
// Voyage options
|
// Voyage options
|
||||||
this.setupChangeHandler('.voyage-api-key', 'voyageApiKey');
|
this.setupChangeHandler('.voyage-api-key', 'voyageApiKey');
|
||||||
this.setupChangeHandler('.voyage-embedding-model', 'voyageEmbeddingModel');
|
this.setupChangeHandler('.voyage-embedding-model', 'voyageEmbeddingModel');
|
||||||
|
this.setupChangeHandler('.voyage-embedding-base-url', 'voyageEmbeddingBaseUrl');
|
||||||
|
|
||||||
// Ollama options
|
// Ollama options
|
||||||
this.setupChangeHandler('.ollama-base-url', 'ollamaBaseUrl');
|
this.setupChangeHandler('.ollama-base-url', 'ollamaBaseUrl');
|
||||||
this.setupChangeHandler('.ollama-default-model', 'ollamaDefaultModel');
|
this.setupChangeHandler('.ollama-default-model', 'ollamaDefaultModel');
|
||||||
this.setupChangeHandler('.ollama-embedding-model', 'ollamaEmbeddingModel');
|
this.setupChangeHandler('.ollama-embedding-model', 'ollamaEmbeddingModel');
|
||||||
|
this.setupChangeHandler('.ollama-embedding-base-url', 'ollamaEmbeddingBaseUrl');
|
||||||
|
|
||||||
|
// Embedding-specific provider options
|
||||||
|
this.setupChangeHandler('.openai-embedding-api-key', 'openaiEmbeddingApiKey', true);
|
||||||
|
this.setupChangeHandler('.openai-embedding-base-url', 'openaiEmbeddingBaseUrl', true);
|
||||||
|
|
||||||
const $refreshModels = this.$widget.find('.refresh-models');
|
const $refreshModels = this.$widget.find('.refresh-models');
|
||||||
$refreshModels.on('click', async () => {
|
$refreshModels.on('click', async () => {
|
||||||
@ -215,6 +221,37 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add embedding base URL change handlers to trigger model fetching
|
||||||
|
this.$widget.find('.openai-embedding-base-url').on('change', async () => {
|
||||||
|
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
||||||
|
if (selectedEmbeddingProvider === 'openai') {
|
||||||
|
await this.fetchModelsForProvider('openai', 'embedding');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$widget.find('.voyage-embedding-base-url').on('change', async () => {
|
||||||
|
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
||||||
|
if (selectedEmbeddingProvider === 'voyage') {
|
||||||
|
// Voyage doesn't have dynamic model fetching yet, but we can add it here when implemented
|
||||||
|
console.log('Voyage embedding base URL changed - model fetching not yet implemented');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$widget.find('.ollama-embedding-base-url').on('change', async () => {
|
||||||
|
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
||||||
|
if (selectedEmbeddingProvider === 'ollama') {
|
||||||
|
await this.fetchModelsForProvider('ollama', 'embedding');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add embedding API key change handlers to trigger model fetching
|
||||||
|
this.$widget.find('.openai-embedding-api-key').on('change', async () => {
|
||||||
|
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
||||||
|
if (selectedEmbeddingProvider === 'openai') {
|
||||||
|
await this.fetchModelsForProvider('openai', 'embedding');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// No sortable behavior needed anymore
|
// No sortable behavior needed anymore
|
||||||
|
|
||||||
// Embedding stats refresh button
|
// Embedding stats refresh button
|
||||||
@ -514,13 +551,13 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
if (!this.$widget || !value) return;
|
if (!this.$widget || !value) return;
|
||||||
|
|
||||||
const $dropdown = this.$widget.find(selector);
|
const $dropdown = this.$widget.find(selector);
|
||||||
|
|
||||||
// Check if the value already exists as an option
|
// Check if the value already exists as an option
|
||||||
if ($dropdown.find(`option[value="${value}"]`).length === 0) {
|
if ($dropdown.find(`option[value="${value}"]`).length === 0) {
|
||||||
// Add the custom value as an option
|
// Add the custom value as an option
|
||||||
$dropdown.append(`<option value="${value}">${value} (current)</option>`);
|
$dropdown.append(`<option value="${value}">${value} (current)</option>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the value
|
// Set the value
|
||||||
$dropdown.val(value);
|
$dropdown.val(value);
|
||||||
}
|
}
|
||||||
@ -596,13 +633,19 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
|
|
||||||
// Voyage Section
|
// Voyage Section
|
||||||
this.$widget.find('.voyage-api-key').val(options.voyageApiKey || '');
|
this.$widget.find('.voyage-api-key').val(options.voyageApiKey || '');
|
||||||
|
this.$widget.find('.voyage-embedding-base-url').val(options.voyageEmbeddingBaseUrl || 'https://api.voyageai.com/v1');
|
||||||
this.setModelDropdownValue('.voyage-embedding-model', options.voyageEmbeddingModel);
|
this.setModelDropdownValue('.voyage-embedding-model', options.voyageEmbeddingModel);
|
||||||
|
|
||||||
// Ollama Section
|
// Ollama Section
|
||||||
this.$widget.find('.ollama-base-url').val(options.ollamaBaseUrl || 'http://localhost:11434');
|
this.$widget.find('.ollama-base-url').val(options.ollamaBaseUrl || 'http://localhost:11434');
|
||||||
|
this.$widget.find('.ollama-embedding-base-url').val(options.ollamaEmbeddingBaseUrl || 'http://localhost:11434');
|
||||||
this.setModelDropdownValue('.ollama-default-model', options.ollamaDefaultModel);
|
this.setModelDropdownValue('.ollama-default-model', options.ollamaDefaultModel);
|
||||||
this.setModelDropdownValue('.ollama-embedding-model', options.ollamaEmbeddingModel);
|
this.setModelDropdownValue('.ollama-embedding-model', options.ollamaEmbeddingModel);
|
||||||
|
|
||||||
|
// Embedding-specific provider options
|
||||||
|
this.$widget.find('.openai-embedding-api-key').val(options.openaiEmbeddingApiKey || '');
|
||||||
|
this.$widget.find('.openai-embedding-base-url').val(options.openaiEmbeddingBaseUrl || 'https://api.openai.com/v1');
|
||||||
|
|
||||||
// Embedding Options
|
// Embedding Options
|
||||||
this.$widget.find('.embedding-selected-provider').val(options.embeddingSelectedProvider || 'openai');
|
this.$widget.find('.embedding-selected-provider').val(options.embeddingSelectedProvider || 'openai');
|
||||||
this.$widget.find('.embedding-auto-update-enabled').prop('checked', options.embeddingAutoUpdateEnabled !== 'false');
|
this.$widget.find('.embedding-auto-update-enabled').prop('checked', options.embeddingAutoUpdateEnabled !== 'false');
|
||||||
@ -619,11 +662,11 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
// Automatically fetch models for currently selected providers
|
// Automatically fetch models for currently selected providers
|
||||||
const selectedAiProvider = this.$widget.find('.ai-selected-provider').val() as string;
|
const selectedAiProvider = this.$widget.find('.ai-selected-provider').val() as string;
|
||||||
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
const selectedEmbeddingProvider = this.$widget.find('.embedding-selected-provider').val() as string;
|
||||||
|
|
||||||
if (selectedAiProvider) {
|
if (selectedAiProvider) {
|
||||||
await this.fetchModelsForProvider(selectedAiProvider, 'chat');
|
await this.fetchModelsForProvider(selectedAiProvider, 'chat');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedEmbeddingProvider) {
|
if (selectedEmbeddingProvider) {
|
||||||
await this.fetchModelsForProvider(selectedEmbeddingProvider, 'embedding');
|
await this.fetchModelsForProvider(selectedEmbeddingProvider, 'embedding');
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,18 @@ export const TPL = `
|
|||||||
<h5>${t("ai_llm.openai_embedding_settings")}</h5>
|
<h5>${t("ai_llm.openai_embedding_settings")}</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>${t("ai_llm.api_key")}</label>
|
||||||
|
<input type="password" class="openai-embedding-api-key form-control" autocomplete="off" />
|
||||||
|
<div class="form-text">${t("ai_llm.openai_embedding_api_key_description")}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>${t("ai_llm.url")}</label>
|
||||||
|
<input type="text" class="openai-embedding-base-url form-control" />
|
||||||
|
<div class="form-text">${t("ai_llm.openai_embedding_url_description")}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>${t("ai_llm.embedding_model")}</label>
|
<label>${t("ai_llm.embedding_model")}</label>
|
||||||
<select class="openai-embedding-model form-control">
|
<select class="openai-embedding-model form-control">
|
||||||
@ -217,7 +229,6 @@ export const TPL = `
|
|||||||
</select>
|
</select>
|
||||||
<div class="form-text">${t("ai_llm.openai_embedding_model_description")}</div>
|
<div class="form-text">${t("ai_llm.openai_embedding_model_description")}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-text text-muted">${t("ai_llm.openai_embedding_shared_settings")}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -235,6 +246,12 @@ export const TPL = `
|
|||||||
<div class="form-text">${t("ai_llm.voyage_api_key_description")}</div>
|
<div class="form-text">${t("ai_llm.voyage_api_key_description")}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>${t("ai_llm.url")}</label>
|
||||||
|
<input type="text" class="voyage-embedding-base-url form-control" />
|
||||||
|
<div class="form-text">${t("ai_llm.voyage_embedding_url_description")}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>${t("ai_llm.embedding_model")}</label>
|
<label>${t("ai_llm.embedding_model")}</label>
|
||||||
<select class="voyage-embedding-model form-control">
|
<select class="voyage-embedding-model form-control">
|
||||||
@ -253,6 +270,12 @@ export const TPL = `
|
|||||||
<h5>${t("ai_llm.ollama_embedding_settings")}</h5>
|
<h5>${t("ai_llm.ollama_embedding_settings")}</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>${t("ai_llm.url")}</label>
|
||||||
|
<input type="text" class="ollama-embedding-base-url form-control" />
|
||||||
|
<div class="form-text">${t("ai_llm.ollama_embedding_url_description")}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>${t("ai_llm.embedding_model")}</label>
|
<label>${t("ai_llm.embedding_model")}</label>
|
||||||
<select class="ollama-embedding-model form-control">
|
<select class="ollama-embedding-model form-control">
|
||||||
@ -260,7 +283,6 @@ export const TPL = `
|
|||||||
</select>
|
</select>
|
||||||
<div class="form-text">${t("ai_llm.ollama_embedding_model_description")}</div>
|
<div class="form-text">${t("ai_llm.ollama_embedding_model_description")}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-text text-muted">${t("ai_llm.ollama_embedding_shared_settings")}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -209,6 +209,12 @@ const defaultOptions: DefaultOption[] = [
|
|||||||
{ name: "ollamaEmbeddingModel", value: "", isSynced: true },
|
{ name: "ollamaEmbeddingModel", value: "", isSynced: true },
|
||||||
{ name: "embeddingAutoUpdateEnabled", value: "true", isSynced: true },
|
{ name: "embeddingAutoUpdateEnabled", value: "true", isSynced: true },
|
||||||
|
|
||||||
|
// Embedding-specific provider options
|
||||||
|
{ name: "openaiEmbeddingApiKey", value: "", isSynced: false },
|
||||||
|
{ name: "openaiEmbeddingBaseUrl", value: "https://api.openai.com/v1", isSynced: true },
|
||||||
|
{ name: "voyageEmbeddingBaseUrl", value: "https://api.voyageai.com/v1", isSynced: true },
|
||||||
|
{ name: "ollamaEmbeddingBaseUrl", value: "http://localhost:11434", isSynced: true },
|
||||||
|
|
||||||
// Adding missing AI options
|
// Adding missing AI options
|
||||||
{ name: "aiTemperature", value: "0.7", isSynced: true },
|
{ name: "aiTemperature", value: "0.7", isSynced: true },
|
||||||
{ name: "aiSystemPrompt", value: "", isSynced: true },
|
{ name: "aiSystemPrompt", value: "", isSynced: true },
|
||||||
|
@ -131,16 +131,20 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
|
|||||||
openaiApiKey: string;
|
openaiApiKey: string;
|
||||||
openaiDefaultModel: string;
|
openaiDefaultModel: string;
|
||||||
openaiEmbeddingModel: string;
|
openaiEmbeddingModel: string;
|
||||||
|
openaiEmbeddingApiKey: string;
|
||||||
|
openaiEmbeddingBaseUrl: string;
|
||||||
openaiBaseUrl: string;
|
openaiBaseUrl: string;
|
||||||
anthropicApiKey: string;
|
anthropicApiKey: string;
|
||||||
anthropicDefaultModel: string;
|
anthropicDefaultModel: string;
|
||||||
voyageEmbeddingModel: string;
|
voyageEmbeddingModel: string;
|
||||||
voyageApiKey: string;
|
voyageApiKey: string;
|
||||||
|
voyageEmbeddingBaseUrl: string;
|
||||||
anthropicBaseUrl: string;
|
anthropicBaseUrl: string;
|
||||||
ollamaEnabled: boolean;
|
ollamaEnabled: boolean;
|
||||||
ollamaBaseUrl: string;
|
ollamaBaseUrl: string;
|
||||||
ollamaDefaultModel: string;
|
ollamaDefaultModel: string;
|
||||||
ollamaEmbeddingModel: string;
|
ollamaEmbeddingModel: string;
|
||||||
|
ollamaEmbeddingBaseUrl: string;
|
||||||
codeOpenAiModel: string;
|
codeOpenAiModel: string;
|
||||||
aiSelectedProvider: string;
|
aiSelectedProvider: string;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user