https://github.com/studiomaxio/build-a-bot
Custom GPT bot template
https://github.com/studiomaxio/build-a-bot
ai chatbot chatgpt gpt gpt-4 gpt-4-api openai openai-api
Last synced: about 2 months ago
JSON representation
Custom GPT bot template
- Host: GitHub
- URL: https://github.com/studiomaxio/build-a-bot
- Owner: StudioMaxIO
- License: gpl-3.0
- Created: 2023-07-13T18:06:43.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-11T15:44:53.000Z (almost 3 years ago)
- Last Synced: 2023-08-11T22:47:34.055Z (almost 3 years ago)
- Topics: ai, chatbot, chatgpt, gpt, gpt-4, gpt-4-api, openai, openai-api
- Language: JavaScript
- Homepage:
- Size: 135 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🤖💬 Build-a-Bot 🤖💬
### _Quickly prototype custom chatbots connected to OpenAI's API._
## Quick Start
Create a `.env.local` file in the root of the project and add the following, replacing `` with your actual OpenAI API key.
```bash
echo "OPENAI_API_KEY=" .env.local
```
Install dependencies:
```bash
npm install
# or
yarn
```
Start the local development server:
```bash
npm run dev
# or
yarn dev
```
Open [http://localhost:3000](http://localhost:3000) in your browser to start interacting with your chatbot(s).
## Creating a Custom Chatbot
### Create a New Bot File
Copy `Template.js` in the `bots` directory and rename it something useful, e.g. `CareerCoach.js` or `CustomerSupport.js`. Replace `YourBot.js` with the name of your bot file.
```bash
cp bots/Template.js bots/YourBot.js
```
### Customize Your Bot
```javascript
import GPTBot from "./GPTBot";
import { functions } from "../botFunctions";
class YourBot extends GPTBot {
constructor() {
// Change the name of your bot here. This is how it will be referenced throughout the app.
// Second argument is the default temperature to use for this bot.
super("YourBot", 0.2);
// You can also set the temperature with the temperatureDefault property.
this.temperatureDefault = 0.2;
// Set the system message to describe your bot.
this.setSystemMessage(`You are a template of a GPT chatbot...`);
// Add functions from botFunctions.js
this.accessFunctions([functions.getCurrentDate]);
// Add custom functions
this.addFunction(
yourFunction,
"yourFunction",
"Description of yourFunction",
{
type: "object",
properties: {
// Add parameters. if none, pass empty object
someInput: {
type: "string",
description: "Some input to yourFunction"
},
someOtherInput: {
type: "string",
description: "Some other input to yourFunction",
enum: ["option1", "option2", "option3"] // can be used to limit input to a set of options
},
someOptionalInput: {
type: "string",
description: "Some optional input to yourFunction"
}
},
required: ["someInput", "someOtherInput"] // Add required parameters here
}
);
}
}
function yourFunction(args) {
// Add function logic here
console.log("yourFunction called with args:", args);
const response = {
output: "Hello World!"
};
// Should always return a string. Objects can be stringified.
return JSON.stringify(response, null, 2);
}
export default YourBot;
```
### Import Your Chatbot
Open `pages/index.js` and import your bot:
```javascript
// index.js
import Chat from "../components/Chat";
import React, { useState } from "react";
import YourBot from "../bots/Template";
const ChatBot = ({}) => {
const [view, setView] = useState("YourBot");
const yourBot = new YourBot();
const renderView = () => {
switch (view) {
case "YourBot":
default:
return ;
}
};
return (
setView("YourBot")}>Your Bot
{renderView()}
);
};
export default ChatBot;
```