godly-ai
TypeScript icon, indicating that this package has built-in type declarations

1.1.15 • Public • Published

GodlyAI

Extend your OpenAI GPT3 completions with custom context to personalize youre responses. Godly.ai

Installation

$ npm install godly-ai

Usage

You need an OpenAI api key which you can generate on the OpenAI Website.

You also need a Godly API key which you can generate on the Godly Dashboard

Create a Project to get started via the Godly Website

Adding Context To a Project

ContextItems are snippets of text with relevant information that may be useful to prompts related to a query.

You can add contextItems via the website, or using the SDK. To use the SDK just call the createContextItem function and pass through the PROJECT_ID you want to add context to. You can find the PROJECT_ID via the Godly Dashboard.

const configuration = new Configuration({
  accessToken: process.env.GODLY_API_KEY,
});
const godlyApi = new GodlyApi(configuration);

// Add some information as conext to the project
await godlyApi.createContextItem(PROJECT_ID, {
  value: 'Some information',
});

Congratulations, you've just uploaded your first piece of context. You're ready to start getting personalized completions.

Using Context with OpenAI Completions

When you send a prompt to OpenAI via Godly it will append the most relevant pieces of Context to your query allowing GPT-3 to better understand the intent of your query and give you more accurate completions.

const { Configuration, GodlyApi } = require('godly-ai');

const configuration = new Configuration({
  accessToken: process.env.GODLY_API_KEY,
});
const godlyApi = new GodlyApi(configuration);

const completion = await godlyApi.completionWithContext(PROJECT_ID, {
  model: 'text-davinci-003',
  prompt: 'Hello world',
});
console.log(completion.data.choices[0].text);

You can manage projects and context items via the Godly API or sdk. Check out the full API documentation for examples of all the available actions.

Error handling

API requests can potentially return errors due to invalid inputs or other issues. These errors can be handled with a try...catch statement, and the error details can be found in either error.response or error.message:

try {
  const completion = await godlyApi.createCompletionWithContext(CONTEXT_ID, {
    model: 'text-davinci-003',
    prompt: 'Hello world',
  });
  console.log(completion.data.choices[0].text);
} catch (error) {
  if (error.response) {
    console.log(error.response.status);
    console.log(error.response.data);
  } else {
    console.log(error.message);
  }
}

Package Sidebar

Install

npm i godly-ai

Weekly Downloads

1

Version

1.1.15

License

MIT

Unpacked Size

269 kB

Total Files

22

Last publish

Collaborators

  • timscullin