Working with Prompts
Overview
You can pull a prompt version from Confident AI like how you would pull a dataset. It works by:
- Providing Confident AI with the alias and optionally version of the prompt you wish to retrieve
- Confident AI will provide the non-interpolated version of the prompt
- You will then interpolate the variables in code
You should pull prompts once and save it in memory instead of pulling it everytime you need to use it.
Using Prompt Versions
Pull prompt with alias
Pull your prompt version by providing the alias you’ve defined:
Python
TypeScript
curL
By default, Confident AI will return the latest version of your prompt.
However, you can also specify the version to override this behavior.
Interpolate variables
Now that you have your prompt template, interpolate any dynamic variables you may have defined in your prompt version. For example, if this is your prompt version:
Messages
Text
And your interpolation type is {{ variable }}, interpolating the name (e.g. “Joe”) would give you this prompt that is ready for use:
Python
TypeScript
curL
And if you don’t have any variables, you must still use the interpolate() method to create a copy of your prompt template to be used in your LLM application.
Pull Prompts By Label
Previously we saw how we can pull a prompt by supplying the version number. You can also “deploy” a prompt using a label, which allows you to select a specific version without defaulting to the latest one:
You must manually label each prompt version. Click here to learn how to do so.
Logging Prompts in Traces
Setup tracing
Attach the @observe decorator to functions/methods that make up your agent, and specify type llm for your LLM-calling functions.
Specifying the type is necessary because logging prompts is only available for LLM spans.
Prompt caching
Confident AI automatically caches prompts on the client side to minimize API call latency and ensure prompt availability, which is especially useful in production environments.
Cache
No Cache
Customize refresh rate
By default, the cache is refetched every 60 seconds, where DeepEval will automatically update the cached prompt with the up-to-date version from Confident AI. This can be overridden by setting the refresh parameter to a different value. Fetching is done asynchronously, so it will not block your application.
Python
TypeScript
Disable Caching
To disable caching, you can set refresh=0. This will force an API call every time you pull the prompt, which is particularly useful for development and testing.