langfuse-prompt-upsert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Langfuse Prompt Upsert

Langfuse Prompt 新增或更新

Create or update a Langfuse prompt and attach the
development
label.
  • 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:
VariableRequiredDescription
LANGFUSE_PUBLIC_KEY
YesLangfuse public key
LANGFUSE_SECRET_KEY
YesLangfuse secret key
LANGFUSE_HOST
or
LANGFUSE_BASE_URL
NoLangfuse host URL (default:
https://us.cloud.langfuse.com
)
使用前请设置以下环境变量:
变量名是否必填说明
LANGFUSE_PUBLIC_KEY
Langfuse公钥
LANGFUSE_SECRET_KEY
Langfuse密钥
LANGFUSE_HOST
LANGFUSE_BASE_URL
Langfuse主机地址(默认值:
https://us.cloud.langfuse.com

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=development
bash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development

2. 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...
EOF
Method 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
undefined

Save 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
undefined
npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name> /tmp/new-prompt.txt
undefined

4. Verify Result

4. 验证结果

bash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development
bash
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development

Template Variables

模板变量

Use
$variableName
format for dynamic values in prompts:
VariablePurpose
$title
Title
$content
Main content
$searchResult
Search results
$conversation
Conversation history
$userQuestion
User's question
Variables are replaced in code with
.replace('$title', value)
.
在Prompt中使用
$variableName
格式表示动态值:
变量用途
$title
标题
$content
主要内容
$searchResult
搜索结果
$conversation
对话历史
$userQuestion
用户问题
代码中通过
.replace('$title', value)
方法替换变量。

Notes

注意事项

  • This skill only attaches the
    development
    label
  • Attaching the
    production
    label should be done manually in the Langfuse UI
  • The existing
    development
    label is automatically moved to the new version
  • 本技能仅会附加
    development
    标签
  • 附加
    production
    标签需在Langfuse UI中手动操作
  • 已有的
    development
    标签会自动迁移至新版本