提示引导大型语言模型(LLM)的行为。提示工程是制作、测试和优化您给 LLM 的指令的过程,以便它产生可靠和有用的响应。 LangSmith 提供工具来创建、版本化、测试和协作提示。您还会遇到常见概念,如提示模板,它让您重用结构化提示,以及变量,它允许您动态地将值(例如用户的问题)插入提示中。 在本快速入门中,您将使用 UI 或 SDK 创建、测试和改进提示。本快速入门将使用 OpenAI 作为示例 LLM 提供商,但相同的工作流程适用于其他提供商。
如果您更喜欢观看有关提示工程入门的视频,请参阅快速入门视频指南

先决条件

在开始之前,请确保您具备: Select the tab for UI or SDK workflows:
  • UI
  • SDK

1. Set workspace secret

LangSmith UI 中,确保您的 OpenAI API 密钥设置为工作区密钥
  1. 导航到 Settings,然后移至 Secrets 选项卡。
  2. 选择 Add secret 并输入 OPENAI_API_KEY 以及您的 API 密钥作为 Value
  3. 选择 Save secret
在 LangSmith UI 中添加工作区密钥时,请确保密钥键与模型提供商预期的环境变量名称匹配。

2. Create a prompt

  1. In the LangSmith UI, navigate to the Prompts section in the left-hand menu.
  2. Click on + Prompt to create a prompt.
  3. Modify the prompt by editing or adding prompts and input variables as needed.
Prompt playground with the system prompt ready for editing.

3. Test a prompt

  1. Under the Prompts heading select the gear icon next to the model name, which will launch the Prompt Settings window on the Model Configuration tab.
  2. Set the model configuration you want to use. The Provider and Model you select will determine the parameters that are configurable on this configuration page. Once set, click Save as.
    Model Configuration window in the LangSmith UI, settings for Provider, Model, Temperature, Max Output Tokens, Top P, Presence Penalty, Frequency Penalty, Reasoning Effort, etc.
  3. Specify the input variables you would like to test in the Inputs box and then click Start.
    The input box with a question entered. The output box contains the response to the prompt.
    To learn about more options for configuring your prompt in the Playground, refer to Configure prompt settings.
  4. After testing and refining your prompt, click Save to store it for future use.

4. Iterate on a prompt

LangSmith allows for team-based prompt iteration. Workspace members can experiment with prompts in the playground and save their changes as a new commit when ready.To improve your prompts:
  • Reference the documentation provided by your model provider for best practices in prompt creation, such as:
  • Build and refine your prompts with the Prompt Canvas—an interactive tool in LangSmith. Learn more in the Prompt Canvas guide.
  • Tag specific commits to mark important moments in your commit history.
    1. To create a commit, navigate to the Playground and select Commit. Choose the prompt to commit changes to and then Commit.
    2. Navigate to Prompts in the left-hand menu. Select the prompt. Once on the prompt’s detail page, move to the Commits tab. Find the tag icon to Add a Commit Tag.
    The tag, the commit tag box with the commit label, and the commit tag name box to create the tag.

Next steps

Video guide


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.