diff --git a/docs/prompt_engineering/quickstarts/quickstart_sdk.mdx b/docs/prompt_engineering/quickstarts/quickstart_sdk.mdx new file mode 100644 index 00000000..928fd2cf --- /dev/null +++ b/docs/prompt_engineering/quickstarts/quickstart_sdk.mdx @@ -0,0 +1,245 @@ +--- +sidebar_label: Quick Start (SDK) +sidebar_position: 0 +table_of_contents: true +--- + +import { + CodeTabs, + python, + typescript, + ShellBlock, +} from "@site/src/components/InstructionsWithCode"; +import { RegionalUrl } from "@site/src/components/RegionalUrls"; + +# Prompt Engineering Quick Start (SDK) + +This quick start will walk through how to create, test, and iterate on prompts using the SDK. In this tutorial we will use OpenAI, but you can use whichever LLM you want. + +:::info QuickStart +This tutorial uses the SDK for prompt engineering, if you are interested in using the UI instead, read [this guide](./quickstart_ui). +::: + +## 1. Setup + +First, install the required packages: + + + +Next, make sure you have signed up for a [LangSmith](https://langsmith.com) account, then [create](../../administration/how_to_guides/organization_management/create_account_api_key#create-an-api-key) and set your API key. +You will also want to sign up for an OpenAI API key to run the code in this tutorial. + +```bash +LANGSMITH_API_KEY = '' +OPENAI_API_KEY = '' +``` + +## 2. Create a prompt + +To create a prompt in LangSmith, define the list of messages you want in your prompt and then wrap them using the +`ChatPromptTemplate` function ([Python](https://python.langchain.com/api_reference/core/prompts/langchain_core.prompts.chat.ChatPromptTemplate.html)) or [TypeScript](https://v03.api.js.langchain.com/classes/_langchain_core.prompts.ChatPromptTemplate.html) function. +Then all you have to do is call [`push_prompt`](https://docs.smith.langchain.com/reference/python/client/langsmith.client.Client#langsmith.client.Client.push_prompt) (Python) or [`pushPrompt`](https://langsmith-docs-7jgx2bq8f-langchain.vercel.app/reference/js/classes/client.Client#pushprompt) (TypeScript) to send your prompt to LangSmith! + + + +## 3. Test a prompt + +To test a prompt, you need to pull the prompt, invoke it with the input values you want to test and then call the model with those input values. +your LLM or application expects. + +" + +prompt = client.pull_prompt("my-prompt") + +# Since our prompt only has one variable we could also pass in the value directly + +# The code below is equivalent to formatted_prompt = prompt.invoke("What is the color of the sky?") + +formatted_prompt = prompt.invoke({"question": "What is the color of the sky?"}) + +# Test the prompt + +response = oai_client.chat.completions.create( +model="gpt-4o", +messages=convert_to_openai_messages(formatted_prompt.messages), +)`, + }, + { + value: "typescript", + label: "TypeScript", + language: "typescript", + content: `import { OpenAI } from "openai"; +import { pull } from "langchain/hub" +import { convertPromptToOpenAI } from "@langchain/openai"; + +// Connect to LangSmith and OpenAI +const oaiClient = new OpenAI(); + +// Pull the prompt to use +// You can also specify a specific commit by passing the commit hash "my-prompt:" +const prompt = await pull("my-prompt"); + +// Format the prompt with the question +const formattedPrompt = await prompt.invoke({ question: "What is the color of the sky?" }); + +// Test the prompt +const response = await oaiClient.chat.completions.create({ +model: "gpt-4o", +messages: convertPromptToOpenAI(formattedPrompt).messages, +});`, +}, +]} +groupId="client-language" +/> + +## 4. Iterate on a prompt + +LangSmith makes it easy to iterate on prompts with your entire team. Members of your workspace can select a prompt to iterate on, and once they are happy with their changes, they can simply save it as a new commit. + +To improve your prompts: + +- We recommend referencing the documentation provided by your model provider for best practices in prompt creation, + such as [Best practices for prompt engineering with the OpenAI API](https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-the-openai-api) and [Gemini’s Introduction to prompt design](https://ai.google.dev/gemini-api/docs/prompting-intro). + +- To help with iterating on your prompts in LangSmith, we've created Prompt Canvas — an interactive tool to build and optimize your prompts. Learn about how to use [Prompt Canvas](../concepts#prompt-canvas). + +To add a new commit to a prompt, you can use the same [`push_prompt`](https://docs.smith.langchain.com/reference/python/client/langsmith.client.Client#langsmith.client.Client.push_prompt) (Python) or [`pushPrompt`](https://langsmith-docs-7jgx2bq8f-langchain.vercel.app/reference/js/classes/client.Client#pushprompt) (TypeScript) methods as +when you first created the prompt. + + + +## 5. Next steps + +- Learn more about how to store and manage prompts using the Prompt Hub in [these how-to guides](../how_to_guides#prompt-hub) +- Learn more about how to use the playground for prompt engineering in [these how-to guides](../how_to_guides#playground) diff --git a/docs/prompt_engineering/quickstarts/quickstart_ui.mdx b/docs/prompt_engineering/quickstarts/quickstart_ui.mdx new file mode 100644 index 00000000..a298145c --- /dev/null +++ b/docs/prompt_engineering/quickstarts/quickstart_ui.mdx @@ -0,0 +1,71 @@ +--- +sidebar_label: Quick Start (UI) +sidebar_position: 0 +table_of_contents: true +--- + +import { + CodeTabs, + python, + typescript, + ShellBlock, +} from "@site/src/components/InstructionsWithCode"; +import { RegionalUrl } from "@site/src/components/RegionalUrls"; + +# Prompt Engineering Quick Start (UI) + +This quick start will walk through how to create, test, and iterate on prompts in LangSmith. + +:::info QuickStart +This tutorial uses the UI for prompt engineering, if you are interested in using the SDK instead, read [this guide](./quickstart_sdk). +::: + +## 1. Setup + +The only setup needed for this guide is to make sure you have signed up for a [LangSmith](https://langsmith.com) account. + +## 2. Create a prompt + +To create a prompt in LangSmith, navigate to the **Prompts** section of the left-hand sidebar and click on the “+ New Prompt” button. +You can then modify the prompt by editing/adding messages and input variables. + +![](./static/create_prompt_ui.gif) + +## 3. Test a prompt + +To test a prompt, set the model configuration you want to use, add your LLM provider's API key, specify the prompt input values you want to test, and then click "Start". + +To learn about more options for configuring your prompt in the playground, check out this [guide](../how_to_guides/playground/managing_model_configurations). +If you are interested in testing how your prompt performs over a dataset instead of individual examples, read [this page](../how_to_guides/playground/testing_over_dataset). + +![](./static/test_prompt_ui.gif) + +## 4. Save a prompt + +One you have run some tests and made your desired changes to your prompt you can click the “Save” button to save your prompt for future use. + +![](./static/save_prompt_ui.gif) + +## 5. Iterate on a prompt + +LangSmith makes it easy to iterate on prompts with your entire team. Members of your workspace can select a prompt to iterate on in the playground, +and once they are happy with their changes, they can simply save it as a new commit. + +To improve your prompts: + +- We recommend referencing the documentation provided by your model provider for best practices in prompt creation, + such as [Best practices for prompt engineering with the OpenAI API](https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-the-openai-api) and [Gemini’s Introduction to prompt design](https://ai.google.dev/gemini-api/docs/prompting-intro). + +- To help with iterating on your prompts in LangSmith, we've created Prompt Canvas — an interactive tool to build and optimize your prompts. + Learn about how to use [Prompt Canvas](../concepts#prompt-canvas). + +![](./static/save_prompt_commit_ui.gif) + +You can also tag specific commits to mark important moments in your commit history: + +![](./static/tag_prompt_ui.gif) + +## 6. Next steps + +- Learn more about how to store and manage prompts using the Prompt Hub in [these how-to guides](../how_to_guides#prompt-hub) +- Learn more about how to use the playground for prompt engineering in [these how-to guides](../how_to_guides#playground) diff --git a/docs/prompt_engineering/quickstarts/static/create_prompt_ui.gif b/docs/prompt_engineering/quickstarts/static/create_prompt_ui.gif new file mode 100644 index 00000000..571206f7 Binary files /dev/null and b/docs/prompt_engineering/quickstarts/static/create_prompt_ui.gif differ diff --git a/docs/prompt_engineering/quickstarts/static/save_prompt_commit_ui.gif b/docs/prompt_engineering/quickstarts/static/save_prompt_commit_ui.gif new file mode 100644 index 00000000..c2fe8ba2 Binary files /dev/null and b/docs/prompt_engineering/quickstarts/static/save_prompt_commit_ui.gif differ diff --git a/docs/prompt_engineering/quickstarts/static/save_prompt_ui.gif b/docs/prompt_engineering/quickstarts/static/save_prompt_ui.gif new file mode 100644 index 00000000..251c896b Binary files /dev/null and b/docs/prompt_engineering/quickstarts/static/save_prompt_ui.gif differ diff --git a/docs/prompt_engineering/quickstarts/static/tag_prompt_ui.gif b/docs/prompt_engineering/quickstarts/static/tag_prompt_ui.gif new file mode 100644 index 00000000..4ad6462b Binary files /dev/null and b/docs/prompt_engineering/quickstarts/static/tag_prompt_ui.gif differ diff --git a/docs/prompt_engineering/quickstarts/static/test_prompt_ui.gif b/docs/prompt_engineering/quickstarts/static/test_prompt_ui.gif new file mode 100644 index 00000000..a8f9895a Binary files /dev/null and b/docs/prompt_engineering/quickstarts/static/test_prompt_ui.gif differ diff --git a/sidebars.js b/sidebars.js index 97d7fe80..b681a02c 100644 --- a/sidebars.js +++ b/sidebars.js @@ -121,6 +121,19 @@ const sidebars = { type: "category", label: "Prompt Engineering", items: [ + { + type: "category", + label: "Quickstarts", + collapsible: true, + items: [ + "prompt_engineering/quickstarts/quickstart_ui", + "prompt_engineering/quickstarts/quickstart_sdk", + ], + link: { + type: "doc", + id: "prompt_engineering/quickstarts/quickstart_ui", + }, + }, { type: "category", label: "Tutorials", @@ -161,7 +174,7 @@ const sidebars = { link: { type: "doc", id: "prompt_engineering/concepts/index" }, }, ], - link: { type: "doc", id: "prompt_engineering/tutorials/index" }, + link: { type: "doc", id: "prompt_engineering/quickstarts/quickstart_ui" }, }, "langgraph_cloud", {