npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@outerop/js

v0.1.24

Published

The Outerop JavaScript SDK provides a convenient way to interact with the Outerop API and integrate prompts into your JavaScript applications. It allows you to fetch prompts, replace variables within the prompts, and call the OpenAI API with the updated p

Downloads

3

Readme

Outerop JavaScript SDK

The Outerop JavaScript SDK provides a convenient way to interact with the Outerop API and integrate prompts into your JavaScript applications. It allows you to fetch prompts, replace variables within the prompts, and call the OpenAI API with the updated prompts.

Installation

To install the Outerop JavaScript SDK, you can use npm or yarn:

npm install @outerop/js

or

yarn add @outerop/js

Usage

To use the Outerop JavaScript SDK, you need to import it into your JavaScript file and create an instance of the Outerop class:

import Outerop from '@outerop/js';

const outerop = new Outerop('your-outerop-api-key', {
  // options
});

Make sure to replace "your-outerop-api-key" and "your-openai-api-key" with your actual API keys.

Using the SDK

To call the OpenAI API with a specific prompt and variables, you can use the chat method:

const variables = {
  // Define your variables here
};

const teamPromptName = 'your-prompt-uuid';
const promptEnvironment = 'production';

outerop
  .chat(teamPromptName, promptEnvironment, variables)
  .then((response) => {
    console.log('API response:', response);
  })
  .catch((error) => {
    console.error('Error calling API:', error);
  });

Replace "your-prompt-uuid" with the UUID of the prompt you want to use and define your variables in the variables object.

This will automatically fetch the prompt, replace variables in the prompt messages, and call the OpenAI API with the updated prompt and variables.

Pinning a specific version in version control

You can replace the promptEnvironment with a specific version number to pin a specific version of the prompt.

const versionId = 'o-1234567890';
const teamPromptName = 'your-prompt-uuid';

outerop
  .chat(teamPromptName, versionId, variables)
  .then((response) => {
    console.log('API response:', response);
  })
  .catch((error) => {
    console.error('Error calling API:', error);
  });

We recommend keeping the instantiation of the Outerop class outside your main event loop to allow the caching to work

Response format

We standardise responses based on the OpenAI SDK for both python and JS. Other models outputs will be transformed to fit the schema. However if you need to, you can access the raw return from the API in the "raw" property of the response.

However we highly recommend using the standardised format, as it will allow you to switch models without changing your code.

outerop
  .chat(teamPromptName, promptEnvironment, variables)
  .then((response) => {
    console.log('API response:', response);
    console.log('Raw API response:', response.raw);
  })
  .catch((error) => {
    console.error('Error calling API:', error);
  });

Utility Functions

The SDK provides utility functions for extracting and replacing variables in prompts:

  • extractVariables(content: string): string[]: Extracts variables from the given content string.
  • replaceVariables(content: string, variables: Record<string, string>): string: Replaces variables in the content string with their corresponding values from the variables object.
  • replaceVariablesInPrompts(prompts: OuteropMessage[], variables: Record<string, string>): OuteropMessage[]: Replaces variables in an array of OuteropMessage objects with their corresponding values from the variables object.

Error Handling

The SDK throws errors if there are any issues with the API requests. You can catch and handle these errors using a try-catch block or by chaining a .catch() method to the promise returned by the SDK methods.

Default Environments

The default environments are: testing development staging production

Summary

The Outerop JavaScript SDK simplifies the process of integrating prompts into your JavaScript applications. By providing methods for fetching prompts, replacing variables, and calling the OpenAI API, it enables you to easily incorporate prompts and generate responses based on user input.

If you have any further questions or need assistance, please refer to the Outerop documentation or reach out to the Outerop support team.