mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-02 21:42:15 +08:00
fix the Ollama embedding model setting option breaking
This commit is contained in:
parent
d3013c925e
commit
553f7dd498
@ -252,13 +252,13 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
const $refreshModels = this.$widget.find('.refresh-models');
|
const $refreshModels = this.$widget.find('.refresh-models');
|
||||||
$refreshModels.on('click', async () => {
|
$refreshModels.on('click', async () => {
|
||||||
$refreshModels.prop('disabled', true);
|
$refreshModels.prop('disabled', true);
|
||||||
$refreshModels.text(t("ai_llm.refresh_models"));
|
$refreshModels.text(t("ai_llm.refreshing_models"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ollamaBaseUrl = this.$widget.find('.ollama-base-url').val() as string;
|
const ollamaBaseUrl = this.$widget.find('.ollama-base-url').val() as string;
|
||||||
const response = await server.post<OllamaModelResponse>('ollama/list-models', { baseUrl: ollamaBaseUrl });
|
const response = await server.post<OllamaModelResponse>('ollama/list-models', { baseUrl: ollamaBaseUrl });
|
||||||
|
|
||||||
if (response && response.models) {
|
if (response && response.success && response.models && response.models.length > 0) {
|
||||||
const $embedModelSelect = this.$widget.find('.ollama-embedding-model');
|
const $embedModelSelect = this.$widget.find('.ollama-embedding-model');
|
||||||
const currentValue = $embedModelSelect.val();
|
const currentValue = $embedModelSelect.val();
|
||||||
|
|
||||||
@ -273,8 +273,10 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
$embedModelSelect.append(`<option value="${model.name}">${model.name}</option>`);
|
$embedModelSelect.append(`<option value="${model.name}">${model.name}</option>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add separator
|
// Add separator if we have both types
|
||||||
|
if (embeddingModels.length > 0) {
|
||||||
$embedModelSelect.append(`<option disabled>───────────</option>`);
|
$embedModelSelect.append(`<option disabled>───────────</option>`);
|
||||||
|
}
|
||||||
|
|
||||||
// Add other models (LLMs can also generate embeddings)
|
// Add other models (LLMs can also generate embeddings)
|
||||||
const otherModels = response.models.filter(model =>
|
const otherModels = response.models.filter(model =>
|
||||||
@ -288,9 +290,14 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
if (currentValue) {
|
if (currentValue) {
|
||||||
$embedModelSelect.val(currentValue);
|
$embedModelSelect.val(currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toastService.showMessage("Models refreshed successfully");
|
||||||
|
} else {
|
||||||
|
toastService.showError("No models found from Ollama server");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error("Error refreshing Ollama models:", error);
|
console.error("Error refreshing Ollama models:", error);
|
||||||
|
toastService.showError(`Error refreshing models: ${error.message || 'Unknown error'}`);
|
||||||
} finally {
|
} finally {
|
||||||
$refreshModels.prop('disabled', false);
|
$refreshModels.prop('disabled', false);
|
||||||
$refreshModels.text(t("ai_llm.refresh_models"));
|
$refreshModels.text(t("ai_llm.refresh_models"));
|
||||||
|
@ -20,18 +20,18 @@ async function listModels(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Return the models list
|
// Return the models list
|
||||||
return res.send({
|
const models = response.data.models || [];
|
||||||
|
|
||||||
|
// Important: don't use "return res.send()" - just return the data
|
||||||
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
models: response.data.models || []
|
models: models
|
||||||
});
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
log.error(`Error listing Ollama models: ${error.message || 'Unknown error'}`);
|
log.error(`Error listing Ollama models: ${error.message || 'Unknown error'}`);
|
||||||
|
|
||||||
return res.status(500).send({
|
// Properly throw the error to be handled by the global error handler
|
||||||
success: false,
|
throw new Error(`Failed to list Ollama models: ${error.message || 'Unknown error'}`);
|
||||||
message: error.message || 'Failed to list Ollama models',
|
|
||||||
error: error.toString()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user