Skip to content

Instantly share code, notes, and snippets.

@gp187
Created April 18, 2023 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gp187/9a264e69a235e48ebee52625f5e5c12c to your computer and use it in GitHub Desktop.
Save gp187/9a264e69a235e48ebee52625f5e5c12c to your computer and use it in GitHub Desktop.
ChatGPT plugin
  1. Instal NestJS
  2. Create new controller using the sample
  3. Add the 2 files in to the root
  4. Use ngrok to port forward to https
  5. Install plugin
{
"schema_version": "v1",
"name_for_human": "Margherita",
"name_for_model": "Margherita",
"description_for_human": "Plugin for finding the optimum time to take time off from work",
"description_for_model": "Plugin for finding the optimum time to take time off from work",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://235a-12-94-170-82.ngrok.io/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://notion-emojis.s3-us-west-2.amazonaws.com/prod/svg-twitter/1f379.svg",
"contact_email": "admin@naologic.com",
"legal_info_url": "https://naologic.com/legal"
}
import {Controller, Get, Param, Query} from "@nestjs/common";
import {createReadStream} from "fs-extra"
import {random} from "lodash";
const promptBadRequest = `Say: No margherita for you! I can't figure out which dates you want to go on vacation. Try again`
@Controller("")
export class OpenaiController {
/**
* Return the read stream
*/
@Get(".well-known/ai-plugin.json")
public returnAiPlugin() {
return createReadStream('ai-plugin.json')
}
@Get("openapi.yaml")
public openAIYaml() {
return createReadStream('openapi.yaml')
}
/**
* How it works
*
* Receive an incoming GET request from OpenAI plugin with the query details.
* If the details are invalid return a bad request prompt, don't throw HTTP error.
*
* Get the employee by name with the role and team attached.
* Get all calendar logs between the fromDate and toDate, regardless of employee id
*
* Start building the prompt text using the pre-defined prompt story.
* If the user already has away time in the calendar, add a notification but don't end
*
*
* @example
* I am Harris Halligan and I want to vacation on the 2nd week of May
*
*
*/
@Get("get_vacation")
public async get_vacation(
@Query() query: { employeeName: string, fromDate: string, toDate: string }, // { employeeName: 'mary', fromDate: '2023-05-01', toDate: '2023-05-07' }
) {
console.warn(`query > `, query);
/**
* Return a prompt to explain why this query can't be performed
*/
if (!query.employeeName || !query.fromDate || !query.toDate) {
return promptBadRequest;
}
const promptText = `
I am a teapot and I will return the text
`
return promptText
}
}
openapi: 3.0.1
info:
title: Employee Vacation
description: Get the best time for an employee to go on vacation.
version: 'v1'
servers:
- url: https://235a-12-94-170-82.ngrok.io
paths:
/get_vacation:
get:
operationId: getVacation
summary: Find the best time to take a vacation.
parameters:
- in: query
name: employeeName
schema:
type: string
description: Used to filter employees based on their name. For example, ?employeeName=davis will return employees that have 'davis' in their first or last name.
- in: query
name: fromDate
schema:
type: string
description: Used to determine between what dates that employee wants to take a vacation. For example, ?fromDate=2023-02-22 will return the list of calendar events from this date to the endDate.
- in: query
name: toDate
schema:
type: string
description: Used to determine what date the employee's vacation will end. For example, ?toDate=2023-02-24 will return the list of calendar events that end at that date and start at the startDate.
responses:
"200":
description: OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment