/backstage-chatgpt-backend

ChatGPT backend plugin for Backstage. Handles the interaction with OpenAI and exposes an API for the front end plugin

Primary LanguageTypeScript

ChatGPT Plugin Backend

Plugin that exposes an API to interact with OpenAI and serve the frontend chatgpt plugin

Installation

Navigate to root of Backstage installation and run

# From root directory of your Backstage installation
yarn add --cwd packages/backend @enfuse/plugin-chatgpt-backend

Configuration

  1. This plugin requires an OpenAI API Key. This should be provided in the backstage configuration as shown below:
//app-config.yml or app-config-local.yml

openai:
  apiKey: <openai-api-key>
  

This can be generated here: ChatGPT API keys.

  1. Create a chatgpt.ts file inside your packages/backend/src/plugins directory and include the following:
import { createRouter } from '@enfuse/plugin-chatgpt-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  return await createRouter({
    logger: env.logger,
    config: env.config
  });
}
  1. Inside your packages/backend/src/index.ts file, find the section where backend environments and routes are set up and include the following:
import chatGPTBackend from './plugins/chatgpt';

...
  const chatgptEnv = useHotMemoize(module, () => createEnv('chatgpt-backend'));

  apiRouter.use('/chatgpt', await chatGPTBackend(chatgptEnv));
  1. Test your backend plugin installation by having backstage running and curling the endpoint
curl localhost:7007/api/chatgpt/health