Skip to content

Commit

Permalink
feat(ollama): add keep_alive param
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzCrazyKns committed Nov 20, 2024
1 parent 874505c commit c650d1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions sample.config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[GENERAL]
PORT = 3001 # Port to run the server on
SIMILARITY_MEASURE = "cosine" # "cosine" or "dot"
KEEP_ALIVE = "5m" # How long to keep Ollama models loaded into memory. (Instead of using -1 use "-1m")

[API_KEYS]
OPENAI = "" # OpenAI API key - sk-1234567890abcdef1234567890abcdef
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Config {
GENERAL: {
PORT: number;
SIMILARITY_MEASURE: string;
KEEP_ALIVE: string;
};
API_KEYS: {
OPENAI: string;
Expand All @@ -34,6 +35,8 @@ export const getPort = () => loadConfig().GENERAL.PORT;
export const getSimilarityMeasure = () =>
loadConfig().GENERAL.SIMILARITY_MEASURE;

export const getKeepAlive = () => loadConfig().GENERAL.KEEP_ALIVE;

export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI;

export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/providers/ollama.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama';
import { getOllamaApiEndpoint } from '../../config';
import { getKeepAlive, getOllamaApiEndpoint } from '../../config';
import logger from '../../utils/logger';
import { ChatOllama } from '@langchain/community/chat_models/ollama';

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

const keepAlive = getKeepAlive();

if (!ollamaEndpoint) return {};

try {
Expand All @@ -24,6 +25,7 @@ export const loadOllamaChatModels = async () => {
baseUrl: ollamaEndpoint,
model: model.model,
temperature: 0.7,
keepAlive: keepAlive
}),
};

Expand Down

0 comments on commit c650d1c

Please sign in to comment.