1.1.12 • Published 4 months ago

apricoai v1.1.12

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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

OptionTypeDefaultDescription
environment"development" | "production"RequiredSpecifies the API environment.
cacheAgenumberundefinedSets 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

1.1.12

4 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.11

5 months ago

1.1.10

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago