@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
8
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 thevariables
object.replaceVariablesInPrompts(prompts: OuteropMessage[], variables: Record<string, string>): OuteropMessage[]
: Replaces variables in an array ofOuteropMessage
objects with their corresponding values from thevariables
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.