Skip to content

Commit 6f60d33

Browse files
fix(local-ai): bound default llama generation (#1241)
Apply the existing 8,192-token gateway ceiling to the managed llama-server preset so malformed or direct requests cannot inherit unlimited generation when max_tokens is omitted. Co-authored-by: Copilot <[email protected]>
1 parent cb610b2 commit 6f60d33

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/OpenClaw.Connection/LocalAi/LlamaServerRouterConfiguration.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private static string BuildPreset(LocalModelInfo model, string modelPath)
119119
preset.Append("model = ").AppendLine(modelPath);
120120
preset.AppendLine("load-on-startup = false");
121121
preset.Append("ctx-size = ").AppendLine(Invariant(recipe.ContextTokens));
122+
preset.Append("n-predict = ").AppendLine(Invariant(LocalAiGatewayProviderDefinition.MaximumOutputTokens));
122123
preset.Append("parallel = ").AppendLine(Invariant(recipe.ParallelRequests));
123124
preset.AppendLine("cache-type-k = f16");
124125
preset.AppendLine("cache-type-v = f16");

‎tests/OpenClaw.Connection.Tests/LocalAiPortLifecycleTests.cs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OpenClaw.TestSupport;
55
using System.Collections.Immutable;
66
using System.Net;
7+
using System.Text.Json;
78

89
namespace OpenClaw.Connection.Tests;
910

@@ -59,6 +60,29 @@ public async Task Manifest_AcceptsAndIgnoresLegacyHardwareProfileId()
5960
Assert.Equal(LocalModelCatalog.Qwen35BModelId, launch.ModelAlias);
6061
}
6162

63+
[Fact]
64+
public async Task RouterPreset_BoundsOmittedGenerationAtGatewayMaximum()
65+
{
66+
using var temp = new TempDirectory("local-ai-manifest-");
67+
var paths = new LocalAiPaths(temp.Path);
68+
var store = new LocalAiManifestStore(paths);
69+
await store.SaveAsync(ValidManifest() with { Endpoint = "http://127.0.0.1:28765/v1" });
70+
LocalAiResolvedInstall saved = (await store.LoadAsync())!;
71+
72+
LlamaServerRouterLaunchPlan launch = LlamaServerRouterConfiguration.Build(paths, saved);
73+
using JsonDocument provider = JsonDocument.Parse(
74+
LocalAiGatewayProviderDefinition.BuildProviderJson(saved));
75+
int gatewayMaximum = provider.RootElement
76+
.GetProperty("models")[0]
77+
.GetProperty("maxTokens")
78+
.GetInt32();
79+
80+
Assert.Equal(LocalAiGatewayProviderDefinition.MaximumOutputTokens, gatewayMaximum);
81+
Assert.Contains(
82+
$"n-predict = {gatewayMaximum}",
83+
launch.PresetContent.Split(Environment.NewLine));
84+
}
85+
6286
[Fact]
6387
public async Task Manifest_OmitsLegacyHardwareProfileIdFromNewWrites()
6488
{

0 commit comments

Comments
 (0)