Improve type safety, update logging, remove unused paths

This commit is contained in:
Aaron Po
2026-04-18 19:18:21 -04:00
parent 8a6cbe5efd
commit 1b242e86b5
4 changed files with 18 additions and 22 deletions

View File

@@ -44,8 +44,6 @@ hex ::= [0-9a-fA-F]
)json_brewery";
static constexpr int kBreweryInitialMaxTokens = 2800;
static constexpr int kBreweryTruncationRetryTokenBump = 700;
static constexpr int kBreweryMaxTokensCeiling = 5000;
BreweryResult LlamaGenerator::GenerateBrewery(
const Location& location, const std::string& region_context) {
@@ -98,8 +96,8 @@ BreweryResult LlamaGenerator::GenerateBrewery(
// Generate brewery data from LLM
raw = this->Infer(system_prompt, user_prompt, max_tokens,
kBreweryJsonGrammar);
spdlog::info("LlamaGenerator: raw output (attempt {}): {}", attempt + 1,
raw);
spdlog::debug("LlamaGenerator: raw output (attempt {}): {}", attempt + 1,
raw);
// Validate output: parse JSON and check required fields
@@ -123,18 +121,6 @@ BreweryResult LlamaGenerator::GenerateBrewery(
spdlog::warn("LlamaGenerator: malformed brewery JSON (attempt {}): {}",
attempt + 1, *validation_error);
if (last_error == "JSON parse error: incomplete JSON") {
const int previous_max_tokens = max_tokens;
max_tokens = std::min(max_tokens + kBreweryTruncationRetryTokenBump,
kBreweryMaxTokensCeiling);
spdlog::info(
"LlamaGenerator: detected truncated JSON; increasing max_tokens from "
"{} to {} and retrying",
previous_max_tokens, max_tokens);
continue;
}
// Update prompt with error details to guide LLM toward correct output.
user_prompt = std::format(
"Your previous response was invalid. Error: {}\nReturn the thought "