Prompt Bundling
Read prompt templates directly from your filesystem in production instead of fetching them from the freeplay server
Prompt Bundling enables you to fetch prompt templates once from the Freeplay server during your build process and store them directly in the filesystem of your deployed artifact.
Advantages of Prompt Bundling
- Increased Resilience
- By decoupling the fetching of prompt templates from Freeplay, you ensure your application can keep serving requests if Freeplay is unavailable.
- Unintended prompt changes cannot hurt production because prompts are only refreshed during your application build process.
- Reduced Latency
- By reading the prompt template from your application filesystem instead of fetching it from Freeplay in real time, you can slightly reduce latency overhead.
Disadvantages of Prompt Bundling
- Increased Cycle Time from Experimentation to Production
- Requiring a build process to get new prompts into production increases cycle time between prompt updates and the deployment of those updates into production
Implementation
Downloading of prompts is handled by the Freeplay Python SDK
Install the Python SDK
Python will be used for to download the prompts for all SDKs
pip install freeplay
Download the Prompt Templates
# Set necessary enviornment variables
export FREEPLAY_API_KEY=$FREEPLAY_API_KEY
export FREEPLAY_SUBDOMAIN=$FREEPLAY_SUBDOMAIN
export FREEPLAY_PROJECT_ID=$FREEPLAY_PROJECT_ID
# Run the command with your project and environment settings, specifying where you want the prompts to be placed.
freeplay download --project-id=<your-project-id> --output-dir=my_freeplay_prompts --environment=prod
Point your Freeplay Client at your Prompt Directory
from freeplay.thin import Freeplay
from freeplay.thin.resources.prompts import FilesystemTemplateResolver
from pathlib import Path
# create a freeplay client link to local filesystem
fpClientLocal = Freeplay(
freeplay_api_key=freeplay_key,
api_base=freeplay_api_base,
template_resolver=FilesystemTemplateResolver(Path(freeplay_template_path))
)
import Freeplay, { FilesystemTemplateResolver } from "freeplay/thin";
const fpClient = new Freeplay({
freeplayApiKey: process.env["FREEPLAY_KEY"],
baseUrl: process.env["FREEPLAY_URL"],
templateResolver: new FilesystemTemplateResolver(templatePath),
});
// create the client
Path templateDir = Paths.get(outputDirectory);
Freeplay localClient = new Freeplay(Config()
.freeplayAPIKey(freeplayApiKey)
.customerDomain(freeplaySubdomain)
.templateResolver(new FilesystemTemplateResolver(templateDir))
.providerConfigs(new ProviderConfigs(new AnthropicProviderConfig(anthropicApiKey)))
);
Updated 5 months ago
What’s Next
Learn how to use Mustache syntax for advanced prompt templating or move onto the next section on Evaluations.