Skip to content
Open
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ This should return a JSON response listing available models. If you get a connec

> For a complete list of all available configuration options with comments and defaults, see `mod-ollama-chat.conf.dist` included in this repository.

### Key Inference / Sampling Parameters

These options control how the Ollama model generates text. All are set in `mod-ollama-chat.conf`:

| Option | Default | Description |
|---|---|---|
| `OllamaChat.NumPredict` | `40` | Max tokens to generate. `0` = unlimited. |
| `OllamaChat.Temperature` | `0.8` | Output randomness. Lower = more focused; higher = more creative. |
| `OllamaChat.TopP` | `0.95` | Nucleus sampling threshold. |
| `OllamaChat.RepeatPenalty` | `1.1` | Penalizes repeated tokens. `1.0` = no penalty. |
| `OllamaChat.TopK` | `0` | Limits sampling to the top K tokens. `0` = unset (model default, typically 40). |
| `OllamaChat.MinP` | `0.0` | Min-p sampling: keeps tokens with prob >= MinP × top-token prob. `0.0` = unset (model default). Alternative to TopP. |
| `OllamaChat.PresencePenalty` | `0.0` | Penalizes tokens that have already appeared, encouraging new topics. `0.0` = unset (model default / no penalty). |
| `OllamaChat.FrequencyPenalty` | `0.0` | Penalizes tokens proportionally to how often they have appeared, reducing repetition. `0.0` = unset (model default / no penalty). |

These four parameters (`TopK`, `MinP`, `PresencePenalty`, `FrequencyPenalty`) default to `0` / `0.0`, which means they are **not sent** to Ollama and the model uses its own defaults. Behavior is unchanged unless an operator explicitly sets a non-zero value.

## Text Commands

The module provides several in-game text commands for administrators (Game Masters) to manage and monitor the Ollama chat functionality. All commands require **SEC_ADMINISTRATOR** security level (GM level 3 or higher).
Expand Down
28 changes: 28 additions & 0 deletions conf/mod_ollama_chat.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ OllamaChat.TopP = 0.95
# Default: 1.1
OllamaChat.RepeatPenalty = 1.1

# OllamaChat.TopK
# Description: Limits sampling to the top K most likely tokens. Higher = more diverse.
# 0 = unset (uses the model default, typically 40). Typical: 40.
# Example: OllamaChat.TopK = 40
# Default: 0
OllamaChat.TopK = 0

# OllamaChat.MinP
# Description: Min-p sampling: keep tokens with probability >= MinP * (top token prob).
# An alternative to TopP. 0.0 = unset (model default). Typical: 0.05.
# Example: OllamaChat.MinP = 0.05
# Default: 0.0
OllamaChat.MinP = 0.0

# OllamaChat.PresencePenalty
# Description: Penalizes tokens that have already appeared, encouraging new topics.
# 0.0 = unset (model default / no penalty). Typical: 0.1-0.5.
# Example: OllamaChat.PresencePenalty = 0.2
# Default: 0.0
OllamaChat.PresencePenalty = 0.0

# OllamaChat.FrequencyPenalty
# Description: Penalizes tokens proportionally to how often they have appeared,
# reducing repetition. 0.0 = unset (model default / no penalty). Typical: 0.1-0.5.
# Example: OllamaChat.FrequencyPenalty = 0.2
# Default: 0.0
OllamaChat.FrequencyPenalty = 0.0

# OllamaChat.NumCtx
# Description: Maximum context length (in tokens) sent to the model.
# 0 = model default. Use a value only if you want to restrict or expand context.
Expand Down
16 changes: 16 additions & 0 deletions src/mod-ollama-chat_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ std::string QueryOllamaAPI(const std::string& prompt)
options["repeat_penalty"] = g_OllamaRepeatPenalty;
hasOptions = true;
}
if (g_OllamaTopK > 0) {
options["top_k"] = g_OllamaTopK;
hasOptions = true;
}
if (g_OllamaMinP != 0.0f) {
options["min_p"] = g_OllamaMinP;
hasOptions = true;
}
if (g_OllamaPresencePenalty != 0.0f) {
options["presence_penalty"] = g_OllamaPresencePenalty;
hasOptions = true;
}
if (g_OllamaFrequencyPenalty != 0.0f) {
options["frequency_penalty"] = g_OllamaFrequencyPenalty;
hasOptions = true;
}
if (g_OllamaNumCtx > 0) {
options["num_ctx"] = g_OllamaNumCtx;
hasOptions = true;
Expand Down
8 changes: 8 additions & 0 deletions src/mod-ollama-chat_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ uint32_t g_OllamaNumPredict = 40;
float g_OllamaTemperature = 0.8f;
float g_OllamaTopP = 0.95f;
float g_OllamaRepeatPenalty = 1.1f;
uint32_t g_OllamaTopK = 0;
float g_OllamaMinP = 0.0f;
float g_OllamaPresencePenalty = 0.0f;
float g_OllamaFrequencyPenalty = 0.0f;
uint32_t g_OllamaNumCtx = 0;
uint32_t g_OllamaNumThreads = 0;
std::string g_OllamaStop = "";
Expand Down Expand Up @@ -390,6 +394,10 @@ void LoadOllamaChatConfig()
g_OllamaTemperature = sConfigMgr->GetOption<float>("OllamaChat.Temperature", 0.8f);
g_OllamaTopP = sConfigMgr->GetOption<float>("OllamaChat.TopP", 0.95f);
g_OllamaRepeatPenalty = sConfigMgr->GetOption<float>("OllamaChat.RepeatPenalty", 1.1f);
g_OllamaTopK = sConfigMgr->GetOption<uint32_t>("OllamaChat.TopK", 0);
g_OllamaMinP = sConfigMgr->GetOption<float>("OllamaChat.MinP", 0.0f);
g_OllamaPresencePenalty = sConfigMgr->GetOption<float>("OllamaChat.PresencePenalty", 0.0f);
g_OllamaFrequencyPenalty = sConfigMgr->GetOption<float>("OllamaChat.FrequencyPenalty", 0.0f);
g_OllamaNumCtx = sConfigMgr->GetOption<uint32_t>("OllamaChat.NumCtx", 0);
g_OllamaNumThreads = sConfigMgr->GetOption<uint32_t>("OllamaChat.NumThreads", 0);
g_OllamaStop = sConfigMgr->GetOption<std::string>("OllamaChat.Stop", "");
Expand Down
5 changes: 5 additions & 0 deletions src/mod-ollama-chat_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ extern uint32_t g_OllamaNumPredict;
extern float g_OllamaTemperature;
extern float g_OllamaTopP;
extern float g_OllamaRepeatPenalty;
// additional Ollama sampling parameters (0 / 0.0 = unset, not sent -> model default)
extern uint32_t g_OllamaTopK;
extern float g_OllamaMinP;
extern float g_OllamaPresencePenalty;
extern float g_OllamaFrequencyPenalty;
extern uint32_t g_OllamaNumCtx;
extern uint32_t g_OllamaNumThreads;
extern std::string g_OllamaStop;
Expand Down