mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 23:05:51 +01:00
add additional options for ollama embeddings
This commit is contained in:
40
src/routes/api/ollama.ts
Normal file
40
src/routes/api/ollama.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import axios from 'axios';
|
||||
import options from "../../services/options.js";
|
||||
import log from "../../services/log.js";
|
||||
import type { Request, Response } from "express";
|
||||
|
||||
/**
|
||||
* List available models from Ollama
|
||||
*/
|
||||
async function listModels(req: Request, res: Response) {
|
||||
try {
|
||||
const { baseUrl } = req.body;
|
||||
|
||||
// Use provided base URL or default from options
|
||||
const ollamaBaseUrl = baseUrl || await options.getOption('ollamaBaseUrl') || 'http://localhost:11434';
|
||||
|
||||
// Call Ollama API to get models
|
||||
const response = await axios.get(`${ollamaBaseUrl}/api/tags`, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Return the models list
|
||||
return res.send({
|
||||
success: true,
|
||||
models: response.data.models || []
|
||||
});
|
||||
} catch (error: any) {
|
||||
log.error(`Error listing Ollama models: ${error.message || 'Unknown error'}`);
|
||||
|
||||
return res.status(500).send({
|
||||
success: false,
|
||||
message: error.message || 'Failed to list Ollama models',
|
||||
error: error.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
listModels
|
||||
};
|
||||
Reference in New Issue
Block a user