The Prompt Management feature in RagaAI Catalyst allows you to efficiently manage, retrieve, and use prompts in your projects.
First, set up your RagaAICatalyst instance and create a PromptManager for your project:
from ragaai_catalyst import RagaAICatalyst
from ragaai_catalyst.prompt_manager import PromptManager
catalyst = RagaAICatalyst(
access_key="your_access_key",
secret_key="your_secret_key",
base_url="https://your-api-base-url.com/api"
)
Create a PromptManager for your project:
project_name = "your-project-name"
prompt_manager = PromptManager(project_name)
prompts = prompt_manager.list_prompts()
print("Available prompts:", prompts)
prompt_name = "your_prompt_name"
versions = prompt_manager.list_prompt_versions(prompt_name)
Retrieve a prompt object by name:
prompt_name = "your_prompt_name"
prompt = prompt_manager.get_prompt(prompt_name)
Retrieve a specific prompt object by name and version:
prompt_name = "your_prompt_name"
version = "your_version"
prompt = prompt_manager.get_prompt(prompt_name, version)
prompt_variables = prompt.get_variables()
print("prompt_variables: ",prompt_variables)
Once you have a prompt, you can compile it with variables:
compiled_prompt = prompt.compile(query="What's the weather?", context="sunny", llm_response="It's sunny today")
print("Compiled prompt:", compiled_prompt)
parameters = prompt.get_parameters()
print("parameters: ",parameters)
If the project you are trying to access does not exist, the PromptManager
will raise a ValueError
:
prompt_manager = PromptManager("non_existent_project")
# Error: Project not found. Please enter a valid project name
If the prompt you are trying to access does not exist, the get_prompt
method will raise a ValueError
:
prompt = prompt_manager.get_prompt("non_existent_prompt")
# Error: Prompt not found. Please enter a valid Prompt name
If the prompt version you are trying to access does not exist, the get_prompt
method will raise a ValueError
:
prompt = prompt_manager.get_prompt("your_prompt_name", "non_existent_version")
# Error: Version not found. Please enter a valid version name
If the variables you are trying to compile the prompt with are not found, the compile
method will raise a ValueError
:
prompt = prompt_manager.get_prompt("your_prompt_name", "your_version")
prompt.get_variables()
compiled_prompt = prompt.compile(query="What's the weather?")
# Error: Missing variable(s): context, llm_response
If the variables you are trying to compile the prompt with are not found, the compile
method will raise a ValueError
:
prompt = prompt_manager.get_prompt("your_prompt_name", "your_version")
compiled_prompt = prompt.compile(query="What's the weather?", context="sunny", llm_response="It's sunny today", expected_response="The weather is sunny")
# Error: Extra variable(s) provided: expected_response
If the variables you are trying to compile the prompt with are not 'str', the compile
method will raise a ValueError
:
prompt = prompt_manager.get_prompt("your_prompt_name", "your_version")
compiled_prompt = prompt.compile(query=True, context="sunny", llm_response="It's sunny today")
# Error: Value for variable 'query' must be a string, not bool
You can get the list of prompts in a project by using the list_prompts()
method in the PromptManager
. This method allows you to retrieve the list of prompts in a project.
You can get the versions of a prompt by using the list_prompt_versions(prompt_name)
method in the PromptManager
. This method allows you to retrieve the versions of a prompt.
You can get the default version of a prompt by using the get_prompt(prompt_name)
method in the PromptManager
. This method allows you to retrieve the default version of a prompt. Then you can use compile
method to get the prompt with default variables.
You can get the versions of a prompt by using the get_prompt(prompt_name, version)
method in the PromptManager
. This method allows you to retrieve the versions of a prompt. Then you can use compile
method to get the prompt with default variables.
You can get the variables of a prompt by using the get_variables()
method. This method allows you to retrieve the variables of a prompt.
You can get the parameters of a prompt by using the get_parameters()
method. This method allows you to retrieve the parameters of a prompt.