Skip to content

Commit

Permalink
feat(ollama-adapter): add keepAlive configuration for persistent conn…
Browse files Browse the repository at this point in the history
…ections, fix #356
  • Loading branch information
dingyi222666 committed Jan 12, 2025
1 parent adcf1da commit 6b08e9b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/ollama-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Config extends ChatLunaPlugin.Config {
presencePenalty: number
frequencyPenalty: number
supportImage: boolean
keepAlive: boolean
}

export const Config: Schema<Config> = Schema.intersect([
Expand All @@ -46,7 +47,8 @@ export const Config: Schema<Config> = Schema.intersect([
apiEndpoints: Schema.array(Schema.string()).default([
'http://127.0.0.1:11434'
]),
supportImage: Schema.boolean().default(true)
supportImage: Schema.boolean().default(true),
keepAlive: Schema.boolean().default(true)
}),
Schema.object({
maxTokens: Schema.number().min(16).max(4096).step(16).default(1024),
Expand Down
5 changes: 3 additions & 2 deletions packages/ollama-adapter/src/locales/en-US.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ $inner:
- {}
- $desc: 'API Configuration'
apiEndpoints:
$desc: 'Ollama API endpoints'
supportImage: 'Whether the current model supports multi-modal image input'
$desc: 'Ollama API endpoints'
supportImage: 'Whether the current model supports multi-modal image input'
keepAlive: 'Whether to keep the connection alive and keep the model loaded'

- $desc: 'Model Parameters'
maxTokens: 'Max input tokens (16-4096, multiple of 16). Note: >2000 for 8k+ token models'
Expand Down
1 change: 1 addition & 0 deletions packages/ollama-adapter/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $inner:
apiEndpoints:
$desc: Ollama 的请求地址列表。
supportImage: 目前运行的模型是否支持多模态图片输入。
keepAlive: 是否保持长连接,不卸载模型。

- $desc: 模型配置
maxTokens: 输入的最大上下文 Token(16~4096,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。
Expand Down
1 change: 1 addition & 0 deletions packages/ollama-adapter/src/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class OllamaRequester
params.input,
this._plugin.config.supportImage
),
keep_alive: this._plugin.config.keepAlive ? -1 : undefined,
options: {
temperature: params.temperature,
// top_k: params.n,
Expand Down
1 change: 1 addition & 0 deletions packages/ollama-adapter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface OllamaRequest {
top_p: number
stop: string
}
keep_alive?: number
messages: OllamaMessage[]
stream: boolean
}
Expand Down

0 comments on commit 6b08e9b

Please sign in to comment.