fix: map input as fallback for all 20+ template content variables (ocr_text, alert_data, bgp_data, etc.)
This commit is contained in:
parent
f1c1d107ca
commit
719336bded
@ -147,18 +147,35 @@ export async function completionRoute(fastify: FastifyInstance): Promise<void> {
|
|||||||
// Stage 5: Prompt assembly
|
// Stage 5: Prompt assembly
|
||||||
// Use taskType directly for template lookup (so tip_transceiver_enrich.yaml is used,
|
// Use taskType directly for template lookup (so tip_transceiver_enrich.yaml is used,
|
||||||
// not the generic_qa fallback from routing). The router only selects the model.
|
// not the generic_qa fallback from routing). The router only selects the model.
|
||||||
// Spread context fields so templates can reference {{source_data}}, {{source_url}}, etc.
|
//
|
||||||
// Fall back to input for {{source_data}} when not explicitly provided in context.
|
// Variable resolution strategy:
|
||||||
|
// 1. Explicit context fields take priority (callers can pass structured data)
|
||||||
|
// 2. `input` is used as fallback for ALL common content variables so simple
|
||||||
|
// one-field callers work without knowing each template's specific var name.
|
||||||
const contextVars = context
|
const contextVars = context
|
||||||
? Object.fromEntries(Object.entries(context).map(([k, v]) => [k, v as string]))
|
? Object.fromEntries(Object.entries(context).map(([k, v]) => [k, v as string]))
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
|
// Common content variable names across all 59 templates — all default to `input`
|
||||||
|
const inputAliases: Record<string, string> = {
|
||||||
|
source_data: input, ocr_text: input, transcription: input,
|
||||||
|
ticket_content: input, alert_data: input, incident_data: input,
|
||||||
|
lldp_data: input, cve_data: input, inventory: input,
|
||||||
|
anomaly_data: input, flagged_input: input, attack_description: input,
|
||||||
|
bgp_data: input, health_checks: input, market_data: input,
|
||||||
|
manuscript_text: input, raw_content: input, content: input,
|
||||||
|
// Additional structured vars with sensible fallbacks
|
||||||
|
peeringdb_data: input, bgp_routes: input, network_context: input,
|
||||||
|
alert_context: input, affected_inventory: input,
|
||||||
|
};
|
||||||
|
|
||||||
const resolved = resolvePrompt(
|
const resolved = resolvePrompt(
|
||||||
taskType ?? decision.prompt_template,
|
taskType ?? decision.prompt_template,
|
||||||
{
|
{
|
||||||
input,
|
...inputAliases, // low priority: input as fallback for all content vars
|
||||||
|
...contextVars, // medium priority: explicit context fields override aliases
|
||||||
|
input, // always available as {{input}}
|
||||||
user_context: context,
|
user_context: context,
|
||||||
source_data: (context?.['source_data'] as string | undefined) ?? input,
|
|
||||||
...contextVars,
|
|
||||||
},
|
},
|
||||||
language ?? 'en',
|
language ?? 'en',
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user