langfuse-prompt-upsert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLangfuse Prompt Upsert
Langfuse Prompt 新增或更新
Create or update a Langfuse prompt and attach the label.
development- If the prompt does not exist: creates a new one (v1)
- If the prompt exists: creates a new version
创建或更新Langfuse Prompt,并附加标签。
development- 若Prompt不存在:创建新的Prompt(版本v1)
- 若Prompt已存在:创建新的版本
Setup
前置设置
Set the following environment variables before use:
| Variable | Required | Description |
|---|---|---|
| Yes | Langfuse public key |
| Yes | Langfuse secret key |
| No | Langfuse host URL (default: |
使用前请设置以下环境变量:
| 变量名 | 是否必填 | 说明 |
|---|---|---|
| 是 | Langfuse公钥 |
| 是 | Langfuse密钥 |
| 否 | Langfuse主机地址(默认值: |
When to Use
适用场景
- Creating a new prompt
- Improving/updating an existing prompt
- Changing prompt content
- 创建新的Prompt
- 优化/更新现有Prompt
- 修改Prompt内容
Steps
操作步骤
1. Check Current Prompt (for updates)
1. 查看当前Prompt(用于更新操作)
bash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=developmentbash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development2. Prepare New Prompt Content
2. 准备新的Prompt内容
Use AskUserQuestion to confirm or propose new prompt content.
使用AskUserQuestion工具确认或提交新的Prompt内容。
3. Create/Update Prompt
3. 创建/更新Prompt
Method A: Pipe directly (recommended)
bash
cat << 'EOF' | npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name>
Prompt content goes here...
EOFMethod B: Via file
bash
undefined方法A:直接管道输入(推荐)
bash
cat << 'EOF' | npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name>
Prompt content goes here...
EOF方法B:通过文件导入
bash
undefinedSave to /tmp/new-prompt.txt using the Write tool, then:
使用Write工具将内容保存至/tmp/new-prompt.txt,然后执行:
npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name> /tmp/new-prompt.txt
undefinednpx tsx scripts/langfuse-prompt-upsert.ts <prompt-name> /tmp/new-prompt.txt
undefined4. Verify Result
4. 验证结果
bash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=developmentbash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=developmentTemplate Variables
模板变量
Use format for dynamic values in prompts:
$variableName| Variable | Purpose |
|---|---|
| Title |
| Main content |
| Search results |
| Conversation history |
| User's question |
Variables are replaced in code with .
.replace('$title', value)在Prompt中使用格式表示动态值:
$variableName| 变量 | 用途 |
|---|---|
| 标题 |
| 主要内容 |
| 搜索结果 |
| 对话历史 |
| 用户问题 |
代码中通过方法替换变量。
.replace('$title', value)Notes
注意事项
- This skill only attaches the label
development - Attaching the label should be done manually in the Langfuse UI
production - The existing label is automatically moved to the new version
development
- 本技能仅会附加标签
development - 附加标签需在Langfuse UI中手动操作
production - 已有的标签会自动迁移至新版本
development