mirror of
https://github.com/Dasemu/si-no-o-indiferente.git
synced 2026-11-27 15:56:52 +00:00
Add player difficulty ratings, drop hint system, use Peninsular Spanish in Gemini prompt
Players can now submit a voluntary 1-5 difficulty rating after a story ends (POST /api/stories/:id/ratings), stored in data/ratings.json. A new reclassifyDifficulty script (wired to a weekly systemd timer) averages those ratings and adjusts a story's difficulty band once it has enough votes. The progressive hint system is removed end-to-end (schema, Gemini prompt/response schema, generation instructions), and the Gemini prompt is rewritten in Peninsular Spanish with an explicit instruction to generate story content in Spain Spanish rather than any LatAm variant. Also translates remaining Spanish code comments/error strings to English and updates the backend README and systemd units accordingly.
This commit is contained in:
1 parent
7f3e6cc839
commit
99a903f6e1
20 files changed
+275
-97
No files matched your search
+17
-17
@@ -4,7 +4,7 @@ import { GeminiStoryBatchSchema, type Story } from "./storySchema.js";
|
||||
const GEMINI_ENDPOINT = (model: string) =>
|
||||
`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
|
||||
|
||||
// Subconjunto de OpenAPI que acepta el "structured output" de Gemini.
|
||||
// Subset of OpenAPI accepted by Gemini's "structured output".
|
||||
const RESPONSE_SCHEMA = {
|
||||
type: "OBJECT",
|
||||
properties: {
|
||||
@@ -18,10 +18,9 @@ const RESPONSE_SCHEMA = {
|
||||
difficulty: { type: "STRING", enum: ["easy", "medium", "hard"] },
|
||||
tags: { type: "ARRAY", items: { type: "STRING" } },
|
||||
teaser: { type: "STRING" },
|
||||
hints: { type: "ARRAY", items: { type: "STRING" } },
|
||||
solution: { type: "STRING" },
|
||||
},
|
||||
required: ["id", "title", "difficulty", "tags", "teaser", "hints", "solution"],
|
||||
required: ["id", "title", "difficulty", "tags", "teaser", "solution"],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -30,23 +29,24 @@ const RESPONSE_SCHEMA = {
|
||||
|
||||
function buildPrompt(count: number, avoidTitles: string[]): string {
|
||||
const avoidList = avoidTitles.length
|
||||
? `Evita repetir o parafrasear estos titulos ya usados: ${avoidTitles.join(", ")}.`
|
||||
? `Evita repetir o parafrasear estos títulos ya usados: ${avoidTitles.join(", ")}.`
|
||||
: "";
|
||||
|
||||
return `Sos un escritor experto en acertijos narrativos de pensamiento lateral, en el estilo del juego de mesa "historias negras"/"black stories": se cuenta un enigma breve y desconcertante (el "teaser"), y los jugadores deben adivinar la explicacion completa (la "solution") haciendo preguntas de si/no.
|
||||
return `Eres un escritor experto en acertijos narrativos de pensamiento lateral, al estilo del juego de mesa "historias negras"/"black stories": se cuenta un enigma breve y desconcertante (el "teaser"), y los jugadores deben adivinar la explicación completa (la "solution") haciendo preguntas de sí/no.
|
||||
|
||||
Genera exactamente ${count} historias completamente ORIGINALES en español (no copies acertijos clasicos ni de ningun juego comercial existente). Cada historia debe tener:
|
||||
- id: slug corto en minusculas separado por guiones, unico, derivado del titulo.
|
||||
- title: titulo corto y evocador.
|
||||
Genera exactamente ${count} historias completamente ORIGINALES en español (no copies acertijos clásicos ni de ningún juego comercial existente). Cada historia debe tener:
|
||||
- id: slug corto en minúsculas separado por guiones, único, derivado del título.
|
||||
- title: título corto y evocador.
|
||||
- difficulty: "easy", "medium" o "hard", variando entre las ${count} historias.
|
||||
- tags: 1 a 3 palabras clave en minusculas.
|
||||
- teaser: 2 a 4 frases. Presenta una situacion extraña o aparentemente inexplicable, resoluble con preguntas de si/no. No debe insinuar la solucion.
|
||||
- hints: entre 3 y 4 pistas progresivas (de mas vaga a mas reveladora) que el narrador puede leer si los jugadores estan trabados, sin regalar la solucion completa en las primeras.
|
||||
- solution: la explicacion completa y coherente que resuelve el enigma, respondiendo a todo lo planteado en el teaser. 4 a 8 frases.
|
||||
- tags: 1 a 3 palabras clave en minúsculas.
|
||||
- teaser: 2 a 4 frases. Presenta una situación extraña o aparentemente inexplicable, resoluble con preguntas de sí/no. No debe insinuar la solución.
|
||||
- solution: la explicación completa y coherente que resuelve el enigma, respondiendo a todo lo planteado en el teaser. 4 a 8 frases.
|
||||
|
||||
Las historias deben ser aptas para todo publico (sin violencia grafica extrema, sin contenido sexual), pueden ser misteriosas, agridulces o con un giro emotivo, pero siempre con una explicacion logica y satisfactoria. ${avoidList}
|
||||
Las historias deben ser aptas para todo público (sin violencia gráfica extrema, sin contenido sexual), pueden ser misteriosas, agridulces o con un giro emotivo, pero siempre con una explicación lógica y satisfactoria. ${avoidList}
|
||||
|
||||
Devolve unicamente el JSON que respeta el schema indicado.`;
|
||||
Importante sobre el idioma: todo el texto de cada historia (title, teaser, solution y tags) debe estar escrito en castellano de España (español peninsular), con su vocabulario, expresiones y gramática característicos (por ejemplo "vosotros", "coger", "ordenador"). No uses español latinoamericano ni ninguna otra variante regional del español.
|
||||
|
||||
Devuelve únicamente el JSON que respeta el schema indicado.`;
|
||||
}
|
||||
|
||||
interface GeminiResponse {
|
||||
@@ -60,7 +60,7 @@ export async function generateStoriesWithGemini(
|
||||
avoidTitles: string[] = []
|
||||
): Promise<Story[]> {
|
||||
if (!config.geminiApiKey) {
|
||||
throw new Error("GEMINI_API_KEY no esta configurada");
|
||||
throw new Error("GEMINI_API_KEY is not configured");
|
||||
}
|
||||
|
||||
const body = {
|
||||
@@ -86,13 +86,13 @@ export async function generateStoriesWithGemini(
|
||||
const data = (await res.json()) as GeminiResponse;
|
||||
const text = data.candidates?.[0]?.content?.parts?.[0]?.text;
|
||||
if (!text) {
|
||||
throw new Error("Respuesta de Gemini sin contenido de texto");
|
||||
throw new Error("Gemini response has no text content");
|
||||
}
|
||||
|
||||
const parsedJson = JSON.parse(text);
|
||||
const validated = GeminiStoryBatchSchema.parse(parsedJson);
|
||||
|
||||
// Aseguramos ids unicos por si el modelo repite alguno.
|
||||
// Ensure unique ids in case the model repeats one.
|
||||
const seen = new Set<string>();
|
||||
for (const story of validated.stories) {
|
||||
let id = story.id;
|
||||
|
||||
Reference in new issue
Block a user