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