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

feat: Support for Ollama keep_alive API parameter #237

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
7 changes: 7 additions & 0 deletions lib/chat_models/chat_ollama_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule LangChain.ChatModels.ChatOllamaAI do

@create_fields [
:endpoint,
:keep_alive,
:mirostat,
:mirostat_eta,
:mirostat_tau,
Expand Down Expand Up @@ -78,6 +79,10 @@ defmodule LangChain.ChatModels.ChatOllamaAI do
embedded_schema do
field :endpoint, :string, default: "http://localhost:11434/api/chat"

# Change Keep Alive setting for unloading the model from memory.
# (Default: "5m", set to a negative interval to disable)
field :keep_alive, :string, default: "5m"

# Enable Mirostat sampling for controlling perplexity.
# (default: 0, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)
field :mirostat, :integer, default: 0
Expand Down Expand Up @@ -199,6 +204,7 @@ defmodule LangChain.ChatModels.ChatOllamaAI do
num_predict: model.num_predict,
repeat_last_n: model.repeat_last_n,
repeat_penalty: model.repeat_penalty,
keep_alive: model.keep_alive,
mirostat: model.mirostat,
mirostat_eta: model.mirostat_eta,
mirostat_tau: model.mirostat_tau,
Expand Down Expand Up @@ -411,6 +417,7 @@ defmodule LangChain.ChatModels.ChatOllamaAI do
model,
[
:endpoint,
:keep_alive,
:model,
:mirostat,
:mirostat_eta,
Expand Down
1 change: 1 addition & 0 deletions test/chat_models/chat_ollama_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ defmodule ChatModels.ChatOllamaAITest do

assert result == %{
"endpoint" => "http://localhost:11434/api/chat",
"keep_alive" => "5m",
"mirostat" => 0,
"mirostat_eta" => 0.1,
"mirostat_tau" => 5.0,
Expand Down
Loading