YuHeng (玉衡)

A local nutrition tracking app powered by AI

View the Project on GitHub formaxcn/yuheng

Prompt Management

YuHeng features a decoupled prompt management system that keeps AI instructions separate from the application logic. This allows for easier iteration on AI behavior without changing code.

Architecture

The system is centered around the PromptManager class in lib/prompts.ts:

How it Works

1. Prompt Definition

A typical prompt file (e.g., prompts/dish-init-prompt.txt) contains base instructions and placeholders for runtime data:

You are a professional nutritionist. 
Please analyze this food photo in .
Return the results in ...

2. Variable Replacement

When the code requests a prompt, it passes a variables object:

const prompt = await promptManager.getPrompt('dish-init-prompt', {
    language: 'English',
    unit: 'kcal'
});

The PromptManager reads the file and replaces all occurrences of and with the provided values.

Benefits