Configurable ollama keep_alive Closes #1859
| @@ -98,6 +98,13 @@ mistral: | ||
| 98 | 98 | # Enables prefilling of the reply with the last assistant message in the prompt |
| 99 | 99 | # CAUTION: The prefix is echoed into the completion. You may want to use regex to trim it out. |
| 100 | 100 | enablePrefix: false |
| 101 | +# -- OLLAMA API CONFIGURATION -- | |
| 102 | +ollama: | |
| 103 | + # Controls how long the model will stay loaded into memory following the request | |
| 104 | + # * -1: Keep the model loaded indefinitely | |
| 105 | + # * 0: Unload the model immediately after the request | |
| 106 | + # * 5m: Keep the model loaded for 5 minutes after the request. Accepts duration strings (e.g. 5h30m40s) | |
| 107 | + keepAlive: -1 | |
| 101 | 108 | # -- SERVER PLUGIN CONFIGURATION -- |
| 102 | 109 | enableServerPlugins: false |
| 103 | 110 | # User session timeout *in seconds* (defaults to 24 hours). |
| @@ -5,7 +5,7 @@ const Readable = require('stream').Readable; | ||
| 5 | 5 | |
| 6 | 6 | const { jsonParser } = require('../../express-common'); |
| 7 | 7 | const { TEXTGEN_TYPES, TOGETHERAI_KEYS, OLLAMA_KEYS, INFERMATICAI_KEYS, OPENROUTER_KEYS, VLLM_KEYS, DREAMGEN_KEYS, FEATHERLESS_KEYS } = require('../../constants'); |
| 8 | 8 | const { forwardFetchResponse, trimV1, getConfigValue } = require('../../util'); |
| 9 | 9 | const { setAdditionalHeaders } = require('../../additional-headers'); |
| 10 | 10 | |
| 11 | 11 | const router = express.Router(); |
| @@ -325,11 +325,12 @@ router.post('/generate', jsonParser, async function (request, response) { | ||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | if (request.body.api_type === TEXTGEN_TYPES.OLLAMA) { |
| 328 | + const keepAlive = getConfigValue('ollama.keepAlive', -1); | |
| 328 | 329 | args.body = JSON.stringify({ |
| 329 | 330 | model: request.body.model, |
| 330 | 331 | prompt: request.body.prompt, |
| 331 | 332 | stream: request.body.stream ?? false, |
| 332 | 333 | keep_alive: -1keepAlive, |
| 333 | 334 | raw: true, |
| 334 | 335 | options: _.pickBy(request.body, (_, key) => OLLAMA_KEYS.includes(key)), |
| 335 | 336 | }); |