1.1.12 • Published 4 months ago
apricoai v1.1.12
Aprico prompt management platform SDK
Aprico is a prompt management platform and this package is an API wrapper that allows you to fetch AI prompts dynamically from Aprico's API. The SDK provides support for different environments (development, production), caching options, and prompt interpolation.
Installation
npm install apricoai
Usage
Import and Initialize the SDK
import Apricoai from "apricoai";
const apricoai = new Apricoai("your-secret-key");
Fetch a Prompt
async function fetchPrompt() {
try {
const prompt = await apricoai.getPrompt("your-prompt-id", {
environment: "production",
cacheAge: 3600, // Cache for 1 hour
});
console.log("Fetched Prompt:", prompt);
} catch (error) {
console.error("Error:", error);
}
}
fetchPrompt();
Compile a prompt
const prompt = "Hello {{name}}, welcome to {{location}}!";
const defaultVariables = {location: "Aprico HQ"};
const variables = {name: "John"};
const compiledPrompt = apricoai.compilePrompt(
prompt,
variables,
defaultVariables
);
console.log(compiledPrompt); // "Hello John, welcome to Aprico HQ!"
Compile messages
const compiledPrompt = apricoai.compileMessages(
messages,
variables,
defaultVariables
);
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
environment | "development" | "production" | Required | Specifies the API environment. |
cacheAge | number | undefined | Sets cache duration in seconds. |
Error Handling
If an API request fails, an error will be thrown. Ensure you handle errors properly in your application:
try {
const prompt = await client.getPrompt("invalid-id", {
environment: "production",
});
} catch (error) {
console.error("Failed to fetch prompt:", error);
}
License
MIT