3. First Prompty¶
In the last section, we Setup our development environment by installing the Visual Studio Code extension. In this section, we'll create, configure, and run, our first Prompty asset.
1. Pre-requisites¶
To run the Prompty, you will need a valid Large Language Model deployed endpoint you can configure. The Prompty specification currently supports three model providers:
- OpenAI - requires the endpoint and key configuration properties
- Azure OpenAI - requires the endpoint and uses keyless auth (with login)
- Serverless - requires a GitHub Personal Access Token, uses Marketplaces models
For our first Prompty, we'll focus on the Azure OpenAI option. - we assume you've deployed an Azure OpenAI model - we assume you've retrieved its Endpoint URL information - we assume you've installed the Prompty extension in VS Code
2. Create a Prompty asset¶
Open the Visual Studio Code editor, then click the File Explorer
icon to view your project filesystem. Select a destination folder (e.g., could be the repository root) and right-click to get a drop-down menu. Look for the New Prompty
option and click it.
β **You should see this `basic.prompty` file created** (click to expand)
Markdown | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
3. Update the default Prompty¶
You can now update the file contents as shown below. Here, we have made three changes:
- We changed the frontmatter (metadata) to customize name, description, authors
- We updated the model (configuration) to reflect the endpoint, deployment
- We updated the content (template) to tailor response behavior with examples
Note that we updated the model to get its endpoint information from a AZURE_OPENAI_ENDPOINT
environment variable. Make sure you set this in the terminal, or in a .env
file at the root of the repo.
β **This is our updated `shakespeare.prompty` asset** (click to expand)
Markdown | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
4. Run the Prompty¶
You can now run the Prompty by clicking the Play
button (top right) in the editor pane of your .prompty
file.
- You will see a pop-up asking you to authenticate with Azure. Sign in
- You will see the VS Code terminal switch to the
Outputs
tab. View output The first step ensures that we use Azure managed identity to authenticate with the specified Azure OpenAI endpoint - and don't need to use explicitly defined keys. You only need to authenticate once. You can then iterate rapidly on prompty content ("prompt engineering") and run it for instant responses. We recommend clearing the output terminal after each run, for clarity.
βοΈ **This is a sample response from one prompty run**. (click to expand)
Bash | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
5. How Prompty assets work¶
The .prompty
file is an example of a Prompty asset that respects the schema defined in the Prompty specification. The asset class is language-agnostic (not tied to any language or framework), using a markdown format with YAML to specify metadata ("frontmatter") and content ("template") for a single prompt-based interaction with a Large Language Model. By doing this, it unifies the prompt content and its execution context in a single asset package, making it easy for developers to rapidly iterate on prompts for prototyping.
The frontmatter (metadata) is structured as YAML, and specifies the prompt inputs, outputs, and model configuration parameters - with optional sample data for testing. The content (template) forms the body of the asset and is a Jnja template that allows for dynamic data binding of variables from Prompty asset inputs. The ability to specify sample data for testing (as an inline object or an external filename) allows us to use Prompty to iteratively define the shape of the data required in complex flows at the granularity of single LLM calls.
The asset is then activated by a Prompty runtime as follows: 1. The file asset is loaded, converting it into an executable function. 1. The asset is now rendered, using function parameters to fill in the template data. 1. The asset is then executed, invoking the configured model with the rendered template. The returned result can then be displayed to the caller (single node) or can be passed as the input to a different Prompty asset (chained flow) to support more complex orchestration.
6. How Models Are Configured¶
Prompty assets must be configured with a model that is the target for the prompt request. However, this configuration can happen at different levels, with a hierarchy that decides which value takes final precedence during execution.
- The Visual Studio Code environment defines a default configuration that you can view by clicking on the
Prompty default
tab in the bottom toolbar. If a Prompty asset does not specify an explicit model configuration, the invocation will use the default model. - When we convert a Prompty asset to code, you may see a
prompty.json
file with a default configuration. This is equivalent to the Visual Studio Code default, but applied to the case when we execute the Prompty from code (vs. VS Code editor). - The Prompty file can itself define model configuration in the frontmatter as seen in our example Prompty (see snippet below). When specified, this value will override other defaults.
In our example asset (snippet below), the Prompty file explicitly defines model configuration properties, giving it precedence. Note also that property values can be specified as constants (
gpt-4
) or reference environment variables (${env:AZURE_OPENAI_ENDPOINT}
). The latter is the recommended approach, ensuring that secrets don't get checked into version control with asset file updates.
YAML | |
---|---|
1 2 3 4 5 6 7 8 |
|
Tip 1: Configure Model in VS Code. If you use the same model configuration repeatedly, or across multiple Prompty assets, consider setting it up as a named model in Visual Studio Code.To configure your model, navigate to and edit your settings.json
file. You can edit this by navigating to settings > Extensions > Prompty > Edit in settings.json
. Update an existing named model (e.g., default
) or create a new one. You can update this at user level (across your assets) or workspace level (across team assets).
Tip 2: Use Azure Managed Identity. If you are using Azure OpenAI or Azure-managed models, opt for keyless authentication by logging into Azure Active Directory (from Prompty extension, once per session) and using that credential to authenticate with your Azure OpenAI model deployments. To trigger this authflow, leave the api_key
property value empty in your model configuration.
Tip 3: Use Environment Variables. As shown above, property values can be defined using environment variables in the format ${env:ENVAR_NAME}
. By default, the Visual Studio Code extension will look for a .env
file in the root folder of the repository containing Prompty assets - create and update that file (and ensure it is .gitignore-d by default). If you use GitHub Codespaces, you can also store environment variables as Codespaces secrets that get automatically injected into the runtime at launch.
7. How To Observe Output¶
By default, executing the Prompty will open the Output tab on the Visual Studio Code terminal and show a brief response with the model output. But what if you want more detail? Prompty provides two features that can help.
- Terminal Options - Look for the
Prompty Output (verbose)
option in a drop-down menu in the Visual Studio Code terminal (at top left of terminal). Selecting this option gives you verbose output which includes the request details and response details, including useful information like token usage for execution. - Code Options - When assets are converted to code, you can take advantage of Prompty Tracer features to log execution traces to the console, or to a JSON file, that can then be visualized for richer analysis of the flow steps and performance.
8. How To Generate Code¶
In this section, we focused on Prompty asset creation and execution from the Visual Studio Code editor (no coding involved). Here, the Visual Studio Code extension acts as the default runtime, loading the asset, rendering the template, and executing the model invocation transparently. But this approach will not work when we need to orchestrate complex flows with multiple assets, or when we need to automate execution in CI/CD pipelines.
This is where the Prompty Runtime comes in. The runtime converts the Prompty asset into code that uses a preferred language or framework. We can think of "runtimes" in two categories:
- Core Runtimes - generate basic code in the target language. Examples: Python, C#
- Framework-Enabled - generate code for a specific framework. Examples: LangChain, Semantic Kernel
In the next section, we'll explore how to go from Prompty To Code, using the core Python runtime.