Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ollama model configs to config.toml and some QOL stuff #456

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sample.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ ANTHROPIC = "" # Anthropic API key - sk-ant-1234567890abcdef1234567890abcdef

[API_ENDPOINTS]
SEARXNG = "http://localhost:32768" # SearxNG API URL
OLLAMA = "" # Ollama API URL - http://host.docker.internal:11434
OLLAMA = "" # Ollama API URL - http://host.docker.internal:11434

[OLLAMA_PARAMS]
TEMPERATURE = 0.7 # ollama default temp is 0.8
NUM_CTX = 2_048 # ollama num_ctx default is 2048
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ interface Config {
SEARXNG: string;
OLLAMA: string;
};
OLLAMA_PARAMS: {
TEMPERATURE: number;
NUM_CTX: number;
}
}

type RecursivePartial<T> = {
Expand Down Expand Up @@ -45,6 +49,10 @@ export const getSearxngApiEndpoint = () =>

export const getOllamaApiEndpoint = () => loadConfig().API_ENDPOINTS.OLLAMA;

export const getModelTemperature = () => loadConfig().OLLAMA_PARAMS.TEMPERATURE;

export const getModelNumCtx = () => loadConfig().OLLAMA_PARAMS.NUM_CTX;

export const updateConfig = (config: RecursivePartial<Config>) => {
const currentConfig = loadConfig();

Expand Down
13 changes: 9 additions & 4 deletions src/lib/providers/ollama.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama';
import { getOllamaApiEndpoint } from '../../config';
import { getModelNumCtx, getModelTemperature, getOllamaApiEndpoint } from '../../config';
import logger from '../../utils/logger';
import { ChatOllama } from '@langchain/community/chat_models/ollama';

export const loadOllamaChatModels = async () => {
const ollamaEndpoint = getOllamaApiEndpoint();


if (!ollamaEndpoint) return {};

Expand All @@ -16,20 +17,24 @@ export const loadOllamaChatModels = async () => {
});

const { models: ollamaModels } = (await response.json()) as any;

const chatModels = ollamaModels.reduce((acc, model) => {
const modelTemperature = getModelTemperature();
const modelNumCtx = getModelNumCtx();
acc[model.model] = {
displayName: model.name,
model: new ChatOllama({
baseUrl: ollamaEndpoint,
model: model.model,
temperature: 0.7,
temperature: modelTemperature,
numCtx: modelNumCtx,
}),
};

return acc;
}, {});



return chatModels;
} catch (err) {
logger.error(`Error loading Ollama models: ${err}`);
Expand Down
4 changes: 2 additions & 2 deletions ui/components/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const SettingsDialog = ({
? chatModelProvider.map((model) => ({
value: model.name,
label: model.displayName,
}))
})).sort((a, b) => a.label.localeCompare(b.label))
: [
{
value: '',
Expand Down Expand Up @@ -392,7 +392,7 @@ const SettingsDialog = ({
? embeddingModelProvider.map((model) => ({
label: model.displayName,
value: model.name,
}))
})).sort((a, b) => a.label.localeCompare(b.label))
: [
{
label: 'No embedding models available',
Expand Down