Prompt engineering involves trial and error. Keep track of your experimentation and save model-and-prompt combinations that generate the output you want.
When you save your work, you can choose to save it as different asset types. Saving your work as an asset makes it possible to share your work with collaborators in the current project.
Asset type | When to use this asset type | What is saved | How to retrieve the asset |
---|---|---|---|
Prompt template asset | When you find a combination of prompt static text, prompt variables, and prompt engineering parameters that generate the results you want from a specific model and want to reuse it. | Prompt text, model, prompt engineering parameters, prompt variables, and AI guardrails settings.
Note: The output that is generated by the model is not saved as part of the prompt template unless the prompt was created in chat mode.
|
From the Saved prompt templates tab |
Prompt session asset | When you want to keep track of the steps involved with your experimentation so you know what you've tried and what you haven't. | Prompt text, model, prompt engineering parameters, AI guardrails settings, and model output for up to 500 prompts that are submitted during a prompt engineering session. | From the History tab |
Notebook asset | When you want to work with models programmatically, but want to start from the Prompt Lab interface for a better prompt engineering experience. | • Prompt text, model, prompt engineering parameters, and prompt variable names and default values are formatted as Python code and stored as a standard notebook. • A deployable Python function that mimics a prompt template and can be consumed by REST APIs and stored as a deployable gen AI flow notebook. Note: You can save your work as a deployable gen AI flow notebook only when you select a vector index and use a chat model.
|
From the Assets page of the project |
Each of these asset types is available from the project's Assets page. Project collaborators with the Admin or Editor role can open and work with them. Your prompt template and prompt session assets are locked automatically, but you can unlock them by clicking the Lock icon .
Editors and Admins can use locked prompt template assets to generate inferences. Only the lock owner can use a locked prompt session asset to generate inferences.
Saving your work
To save your prompt engineering work, complete the following steps:
-
From the header of the prompt editor, click the Save work icon , and then click Save as.
-
Choose an asset type.
If you choose to create a deployable Gen AI flow notebook, you must associate the prompt with a deployment space. For more information, see Deployment spaces.
-
Name the asset, and then optionally add a description.
-
Watsonx.governance only: Choose the task type that best matches your goal.
-
If you save the prompt as a notebook asset only: Select View in project after saving.
-
Click Save.
Working with prompts saved in a notebook
When you save your work as a notebook asset, a Python notebook is built.
To work with a prompt notebook asset, complete the following steps depending on the type of notebook:
Standard notebook
-
Open the notebook asset from the Assets tab of your project.
-
Click the Edit icon to instantiate the notebook so you can step through the code.
The notebook contains runnable code that manages the following steps for you:
- Authenticates with the service.
- Defines a Python class.
- Defines the input text for the model and declares any prompt variables. You can edit the static prompt text and assign values to prompt variables.
- Uses the defined class to call the watsonx.ai inferencing API and pass your input to the foundation model.
- Shows the output that is generated by the foundation model.
Note: For prompts that inference tuned models that are stored in the project, replace the space ID with the project ID. -
Use the notebook as is, or change it to meet the needs of your use case.
The Python code that is generated by using the Prompt Lab executes successfully. You must test and validate any changes that you make to the code.
Deployable gen AI flow notebook
-
Open the notebook asset from the Assets tab of your project.
-
Click the Edit icon to instantiate the notebook so you can step through the code.
The notebook contains runnable code that manages the following steps for you:
- Authenticates with the service.
- Connects to the target space and promotes the vector index.
- Defines the python function to be deployed. This includes code to initialize the vector index, make queries against the vector index, format the input for the model, and run inferences.
- Tests the python function locally.
- Deploys the python function to the target space.
- Tests the deployed python function.
-
Use the notebook as is, or change it to meet the needs of your use case.
The Python code that is generated by using the Prompt Lab executes successfully. You must test and validate any changes that you make to the code.
-
The Python function deployed by the notebook can be consumed using a REST API. The following is an example cURL request to call your deployment:
curl --location '${PUBLIC_ENDPOINT}' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ${IAM_TOKEN}' \ --data '{ \ "input_data": [{ "fields": ["Search", "Access token"], "values": [ [${MESSAGES}], [${IAM_TOKEN}]] }] }'
where
- PUBLIC_ENDPOINT is the public endpoint of your deployment. See Creating online deployments.
- IAM_TOKEN is the authentication token to access IBM Cloud services. See Credentials for programmatic access.
- MESSAGES is an array of the chat history text entries with the following schema:
{ "role": type, // "user" or "assistant" "content": content // The text content of the message }
Working with saved prompt templates
To continue working with a saved prompt, open it from the Saved prompt templates tab of the Prompt Lab.
When you open a saved prompt template, Autosave is on, which means that any changes you make to the prompt will be reflected in the saved prompt template asset. If you want the prompt template that you saved to remain unchanged, click New prompt to start a new prompt.
You cannot change edit modes from a saved prompt template.
Unlike other edit modes, a prompt template that is saved in chat mode also stores the model output. You cannot switch to a different mode from a prompt template that was saved in chat mode.
When watsonx.governance is provisioned, if your prompt template includes at least one prompt variable, you can evaluate the effectiveness of model responses.
- For more information about prompt variables, see Building reusable prompts.
- For more information about evaluating model responses, see Evaluating prompt templates in projects.
Working with saved prompt sessions
To continue working with a saved prompt session, open it from the History tab of the Prompt Lab.
To review previous prompt submissions, you can click a prompt entry from the history to open it in the prompt editor. If you prefer the results from the earlier prompt, you can reset it as your current prompt by clicking Restore. When you restore an earlier prompt, your current prompt session is replaced by the earlier version of the prompt session.
Learn more
Parent topic: Prompt Lab