GPT Turbo LogoGPT Turbo Logo
GPT Turbo LogoGPT Turbo Logo

Installation

Setup and use GPT Turbo in your project.

These docs will use npm for conciseness, but you can use yarn or any other package manager.

Since GPT Turbo is a TypeScript-first library, examples will also use TypeScript. You can simply ignore TypeScript specific syntax and use plain JavaScript if you prefer.

Install GPT Turbo

Install GPT Turbo using your favorite package manager:

npm install gpt-turbo

(optional) Environment setup with dotenv

Unless your app is meant to be 100% local, you'll probably ship your app somewhere or at least push it to a git repository. In that case, it is highly recommended to setup environment variables to avoid leaking your API keys. While you may choose process.env directly or another library, it's recommended to use dotenv, which will be shown below.

Install dotenv:

npm install dotenv

Create a .env file in the root of your project and add the following:

OPENAI_API_KEY=sk-...

Add .env to your .gitignore file to avoid committing it to your repository.

Finally, you'll need to call dotenv.config() somewhere in your app, preferably as early as possible (e.g. in your index.ts file). You can also export the specific variables so you don't need to type and call process.env everywhere:

/// config.ts
import dotenv from "dotenv";
dotenv.config();

export const OPENAI_API_KEY = process.env.OPENAI_API_KEY;

/// index.ts
import "./config";

// ...

Usage

You're now ready to use GPT Turbo in your app! You can test out the following basic example:

import { Conversation } from "gpt-turbo";

const apiKey = "sk-1234"; /* Your API key */

const conversation = new Conversation({ config: { apiKey } });
const response = await conversation.prompt(
    "What's the best way to make my code as precise as a Stormtrooper's aim?"
);
console.log(`Response: ${response.content}`);

Advanced Usage

Check out the Examples section for more advanced usage examples.