Prompt Management
Guaranteed Availability
6 min
implementing this is usually not necessary as it adds complexity to your application the abv prompt management is highly available due to multiple caching of prompts in client sdks docid\ e2mzrcu6jgq6cybjic1wt and we closely monitor its performance ( status page status page ) however, if you require 100% availability, you can use the following options the abv api has high uptime and prompts are caching of prompts in client sdks docid\ e2mzrcu6jgq6cybjic1wt in the sdks to prevent network issues from affecting your application however, get prompt() / getprompt() will throw an exception if no local (fresh or stale) cached prompt is available > new application instance fetching prompt for the first time and network request fails > networking or abv api issue (after retries) to guarantee 100% availability, there are two options pre fetch prompts on application startup and exit the application if the prompt is not available provide a fallback prompt that will be used in these cases option 1 pre fetch prompts pre fetch prompts on application startup and exit the application if the prompt is not available python (flask) from flask import flask, jsonify from abvdev import abv \# initialize the flask app and abv client app = flask( name ) abv = abv() def fetch prompts on startup() try \# fetch and cache the production version of the prompt abv get prompt("movie critic") except exception as e print(f"failed to fetch prompt on startup {e}") sys exit(1) # exit the application if the prompt is not available \# call the function during application startup fetch prompts on startup() @app route('/get movie prompt/\<movie>', methods=\['get']) def get movie prompt(movie) prompt = abv get prompt("movie critic") compiled prompt = prompt compile(criticlevel="expert", movie=movie) return jsonify({"prompt" compiled prompt}) if name == ' main ' app run(debug=true) js/ts (express) import express from "express"; import { abvclient } from "@abvdev/client"; // initialize the express app and abv client const app = express(); const abv = new abvclient(); async function fetchpromptsonstartup() { try { // fetch and cache the production version of the prompt await abv prompt get("movie critic"); } catch (error) { console error("failed to fetch prompt on startup ", error); process exit(1); // exit the application if the prompt is not available } } // call the function during application startup fetchpromptsonstartup(); app get("/get movie prompt/\ movie", async (req, res) => { const movie = req params movie; const prompt = await abv prompt get("movie critic"); const compiledprompt = prompt compile({ criticlevel "expert", movie }); res json({ prompt compiledprompt }); }); app listen(3000, () => { console log("server is running on port 3000"); }); option 2 fallback provide a fallback prompt that will be used in these cases python sdk from abvdev import abv abv = abv() \# get `text` prompt with fallback prompt = abv get prompt( "movie critic", fallback="do you like {{movie}}?" ) \# get `chat` prompt with fallback chat prompt = abv get prompt( "movie critic chat", type="chat", fallback=\[{"role" "system", "content" "you are an expert on {{movie}}"}] ) \# true if the prompt is a fallback prompt is fallback js/ts sdk import { abvclient } from "@abvdev/client"; const abv = new abvclient(); // get `text` prompt with fallback const prompt = await abv prompt get("movie critic", { fallback "do you like {{movie}}?", }); // get `chat` prompt with fallback const chatprompt = await abv prompt get("movie critic chat", { type "chat", fallback \[{ role "system", content "you are an expert on {{movie}}" }], }); // true if the prompt is a fallback prompt isfallback;