mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 10:04:00 +00:00
fix: stabilize Gemma 4 brewery generation
remove misleading turn-token output guidance from the brewery prompt extract the last balanced JSON object before validation keep README model setup and run instructions aligned preserve Gemma 4 sampling defaults and local model usage
This commit is contained in:
@@ -26,8 +26,9 @@ auto ExtractFinalJsonPayload(std::string raw_response) -> std::string {
|
||||
return text.substr(first, last - first + 1);
|
||||
};
|
||||
|
||||
static const std::array<std::string_view, 4> separator_tokens = {
|
||||
"<|turn|>", "<turn|>", "<channel|>", "<|channel|>"};
|
||||
static const std::array<std::string_view, 6> separator_tokens = {
|
||||
"<|think|>", "<think|>", "<|turn|>",
|
||||
"<turn|>", "<channel|>", "<|channel|>"};
|
||||
|
||||
std::size_t separator_pos = std::string::npos;
|
||||
std::size_t separator_length = 0;
|
||||
@@ -46,18 +47,13 @@ auto ExtractFinalJsonPayload(std::string raw_response) -> std::string {
|
||||
}
|
||||
|
||||
const std::string_view trimmed = trim(raw_response);
|
||||
const std::size_t first_brace = trimmed.find('{');
|
||||
if (first_brace == std::string_view::npos) {
|
||||
return std::string(trimmed);
|
||||
std::string json_candidate =
|
||||
ExtractLastJsonObjectPublic(std::string(trimmed));
|
||||
if (!json_candidate.empty()) {
|
||||
return ExtractLastJsonObjectPublic(std::string(trimmed));
|
||||
}
|
||||
|
||||
const std::size_t last_brace = trimmed.find_last_of('}');
|
||||
if (last_brace == std::string_view::npos || last_brace < first_brace) {
|
||||
return std::string(trimmed.substr(first_brace));
|
||||
}
|
||||
|
||||
return std::string(
|
||||
trimmed.substr(first_brace, last_brace - first_brace + 1));
|
||||
return std::string(trimmed);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -147,9 +143,11 @@ auto LlamaGenerator::GenerateBrewery(const BreweryLocation& location,
|
||||
// limits.
|
||||
prompt =
|
||||
"Your previous response was invalid. Error: " + validation_error +
|
||||
"\nReturn ONLY valid JSON with this exact schema: "
|
||||
"{\"name\": \"string\", \"description\": \"string\"}."
|
||||
"\nDo not include markdown, comments, or extra keys.";
|
||||
"\nReturn ONLY valid JSON with exactly these keys: "
|
||||
"{\"name\": \"<brewery name>\", "
|
||||
"\"description\": \"<single-paragraph description>\"}."
|
||||
"\nDo not include markdown, comments, extra keys, or literal "
|
||||
"placeholder values.";
|
||||
prompt += "\n\n";
|
||||
prompt += retry_location;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user