Skip to content

Commit

Permalink
feat: ChatGPT Plugins/OpenAPI specs for Plugins Endpoint (danny-avila…
Browse files Browse the repository at this point in the history
…#620)

* wip: proof of concept for openapi chain

* chore(api): update langchain dependency to version 0.0.105

* feat(Plugins): use ChatGPT Plugins/OpenAPI specs (first pass)

* chore(manifest.json): update pluginKey for "Browser" tool to "web-browser"
chore(handleTools.js): update customConstructor key for "web-browser" tool

* fix(handleSubmit.js): set unfinished property to false for all endpoints

* fix(handlers.js): remove unnecessary capitalizeWords function and use action.tool directly
refactor(endpoints.js): rename availableTools to tools and transform it into a map

* feat(endpoints): add plugins selector to endpoints file
refactor(CodeBlock.tsx): refactor to typescript
refactor(Plugin.tsx): use recoil Map for plugin name and refactor to typescript
chore(Message.jsx): linting
chore(PluginsOptions/index.jsx): remove comment/linting
chore(svg): export Clipboard and CheckMark components from SVG index and refactor to typescript

* fix(OpenAPIPlugin.js): rename readYamlFile function to readSpecFile
fix(OpenAPIPlugin.js): handle JSON files in readSpecFile function
fix(OpenAPIPlugin.js): handle JSON URLs in getSpec function
fix(OpenAPIPlugin.js): handle JSON variables in createOpenAPIPlugin function
fix(OpenAPIPlugin.js): add description for variables in createOpenAPIPlugin function
fix(OpenAPIPlugin.js): add optional flag for is_user_authenticated and has_user_authentication in ManifestDefinition
fix(loadSpecs.js): add optional flag for is_user_authenticated and has_user_authentication in ManifestDefinition
fix(Plugin.tsx): remove unnecessary callback parameter in getPluginName function
fix(getDefaultConversation.js): fix browser console error: handle null value for lastConversationSetup in getDefaultConversation function

* feat(api): add new tools

Add Ai PDF tool for super-fast, interactive chats with PDFs of any size, complete with page references for fact checking.
Add VoxScript tool for searching through YouTube transcripts, financial data sources, Google Search results, and more.
Add WebPilot tool for browsing and QA of webpages, PDFs, and data. Generate articles from one or more URLs.

feat(api): update OpenAPIPlugin.js

- Add support for bearer token authorization in the OpenAPIPlugin.
- Add support for custom headers in the OpenAPIPlugin.

fix(api): fix loadTools.js

- Pass the user parameter to the loadSpecs function.

* feat(PluginsClient.js): import findMessageContent function from utils
feat(PluginsClient.js): add message parameter to options object in initializeCustomAgent function
feat(PluginsClient.js): add content to errorMessage if message content is found
feat(PluginsClient.js): break out of loop if message content is found
feat(PluginsClient.js): add delay option with value of 8 to generateTextStream function
feat(PluginsClient.js): add support for process.env.PORT environment variable in app.listen function
feat(askyourpdf.json): add askyourpdf plugin configuration
feat(metar.json): add metar plugin configuration
feat(askyourpdf.yaml): add askyourpdf plugin OpenAPI specification
feat(OpenAPIPlugin.js): add message parameter to createOpenAPIPlugin function
feat(OpenAPIPlugin.js): add description_for_model to chain run message
feat(addOpenAPISpecs.js): remove verbose option from loadSpecs function call

fix(loadSpecs.js): add 'message' parameter to the loadSpecs function
feat(findMessageContent.js): add utility function to find message content in JSON objects

* fix(PluginStoreDialog.tsx): update z-index value for the dialog container

The z-index value for the dialog container was updated to "102" to ensure it appears above other elements on the page.

* chore(web_pilot.json): add "params" field with "user_has_request" parameter set to true

* chore(eslintrc.js): update eslint rules
fix(Login.tsx): add missing semicolon after import statement

* fix(package-lock.json): update langchain dependency to version ^0.0.105

* fix(OpenAPIPlugin.js): change header key from 'id' to 'librechat_user_id' for consistency and clarity

feat(plugins): add documentation for using official ChatGPT Plugins with OpenAPI specs

This commit adds a new file `chatgpt_plugins_openapi.md` to the `docs/features/plugins` directory. The file provides detailed information on how to use official ChatGPT Plugins with OpenAPI specifications. It explains the components of a plugin, including the Plugin Manifest file and the OpenAPI spec. It also covers the process of adding a plugin, editing manifest files, and customizing OpenAPI spec files. Additionally, the commit includes disclaimers about the limitations and compatibility of plugins with LibreChat. The documentation also clarifies that the use of ChatGPT Plugins with LibreChat does not violate OpenAI's Terms of Service.

The purpose of this commit is to provide comprehensive documentation for developers who want to integrate ChatGPT Plugins into their projects using OpenAPI specs. It aims to guide them through the process of adding and configuring plugins, as well as addressing potential issues and

chore(introduction.md): update link to ChatGPT Plugins documentation
docs(introduction.md): clarify the purpose of the plugins endpoint and its capabilities

* fix(OpenAPIPlugin.js): update SUFFIX variable to provide a clearer description
docs(chatgpt_plugins_openapi.md): update information about adding plugins via url on the frontend

* feat(PluginsClient.js): sendIntermediateMessage on successful Agent load
fix(PluginsClient.js, server/index.js, gptPlugins.js): linting fixes
docs(chatgpt_plugins_openapi.md): update links and add additional information

* Update chatgpt_plugins_openapi.md

* chore: rebuild package-lock file

* chore: format/lint all files with new rules

* chore: format all files

* chore(README.md): update AI model selection list

The AI model selection list in the README.md file has been updated to reflect the current options available. The "Anthropic" model has been added as an alternative name for the "Claude" model.

* fix(Plugin.tsx): type issue

* feat(tools): add new tool WebPilot

feat(tools): remove tool Weather Report

feat(tools): add new tool Prompt Perfect

feat(tools): add new tool Scholarly Graph Link

* feat(OpenAPIPlugin.js): add getSpec and readSpecFile functions
feat(OpenAPIPlugin.spec.js): add tests for readSpecFile, getSpec, and createOpenAPIPlugin functions

* chore(agent-demo-1.js): remove unused code and dependencies
chore(agent-demo-2.js): remove unused code and dependencies
chore(demo.js): remove unused code and dependencies

* feat(addOpenAPISpecs): add function to transform OpenAPI specs into desired format
feat(addOpenAPISpecs.spec): add tests for transformSpec function
fix(loadSpecs): remove debugging code

* feat(loadSpecs.spec.js): add unit tests for ManifestDefinition, validateJson, and loadSpecs functions

* fix: package file resolution bug

* chore: move scholarly_graph_link manifest to 'has-issues'

* refactor(client/hooks): convert to TS and export from index

* Update introduction.md

* Update chatgpt_plugins_openapi.md
  • Loading branch information
danny-avila authored Jul 16, 2023
1 parent 39ac8d3 commit 514f625
Show file tree
Hide file tree
Showing 165 changed files with 3,003 additions and 713 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ module.exports = {
},
],
'linebreak-style': 0,
'object-curly-spacing': ['error', 'always'],
'curly': ['error', 'all'],
'semi': ['error', 'always'],
'no-trailing-spaces': 'error',
'object-curly-spacing': ['error', 'always'],
'no-multiple-empty-lines': ['error', { max: 1 }],
'comma-dangle': ['error', 'always-multiline'],
// "arrow-parens": [2, "as-needed", { requireForBlockBody: true }],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ https://github.com/danny-avila/LibreChat/assets/110412045/c1eb0c0f-41f6-4335-b98
# Features
- Response streaming identical to ChatGPT through server-sent events
- UI from original ChatGPT, including Dark mode
- AI model selection (through 6 endpoints: OpenAI API, BingAI, ChatGPT Browser, PaLM2, Claude, Plugins)
- AI model selection: OpenAI API, BingAI, ChatGPT Browser, PaLM2, Anthropic (Claude), Plugins
- Create, Save, & Share custom presets - [More info on prompt presets here](https://github.com/danny-avila/LibreChat/releases/tag/v0.3.0)
- Edit and Resubmit messages with conversation branching
- Search all messages/conversations - [More info here](https://github.com/danny-avila/LibreChat/releases/tag/v0.1.0)
Expand Down
4 changes: 2 additions & 2 deletions api/app/bingai.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const askBing = async ({
jailbreakConversationId = false;
}

if (jailbreak)
if (jailbreak) {
options = {
jailbreakConversationId: jailbreakConversationId || jailbreak,
context,
Expand All @@ -48,7 +48,7 @@ const askBing = async ({
toneStyle,
onProgress,
};
else {
} else {
options = {
conversationId,
context,
Expand Down
19 changes: 18 additions & 1 deletion api/app/clients/PluginsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const OpenAIClient = require('./OpenAIClient');
const { ChatOpenAI } = require('langchain/chat_models/openai');
const { CallbackManager } = require('langchain/callbacks');
const { initializeCustomAgent, initializeFunctionsAgent } = require('./agents/');
const { findMessageContent } = require('../../utils');
const { loadTools } = require('./tools/util');
const { SelfReflectionTool } = require('./tools/');
const { HumanChatMessage, AIChatMessage } = require('langchain/schema');
Expand Down Expand Up @@ -193,6 +194,8 @@ Only respond with your conversational reply to the following User Message:
functions: this.functionsAgent,
options: {
openAIApiKey: this.openAIApiKey,
debug: this.options?.debug,
message,
},
});
// load tools
Expand Down Expand Up @@ -266,6 +269,15 @@ Only respond with your conversational reply to the following User Message:
if (this.options.debug) {
console.debug('Loaded agent.');
}

onAgentAction(
{
tool: 'self-reflection',
toolInput: `Processing the User's message:\n"${message}"`,
log: '',
},
true,
);
}

async executorCall(message, signal) {
Expand All @@ -290,6 +302,11 @@ Only respond with your conversational reply to the following User Message:
} catch (err) {
console.error(err);
errorMessage = err.message;
const content = findMessageContent(message);
if (content) {
errorMessage = content;
break;
}
if (attempts === maxAttempts) {
this.result.output = `Encountered an error while attempting to respond. Error: ${err.message}`;
this.result.intermediateSteps = this.actions;
Expand Down Expand Up @@ -408,7 +425,7 @@ Only respond with your conversational reply to the following User Message:
if (this.agentOptions.skipCompletion && this.result.output) {
responseMessage.text = this.result.output;
this.addImages(this.result.intermediateSteps, responseMessage);
await this.generateTextStream(this.result.output, opts.onProgress);
await this.generateTextStream(this.result.output, opts.onProgress, { delay: 8 });
return await this.handleResponseMessage(responseMessage, saveOptions, user);
}

Expand Down
18 changes: 18 additions & 0 deletions api/app/clients/tools/.well-known/Ai_PDF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Ai PDF",
"name_for_model": "Ai_PDF",
"description_for_human": "Super-fast, interactive chats with PDFs of any size, complete with page references for fact checking.",
"description_for_model": "Provide a URL to a PDF and search the document. Break the user question in multiple semantic search queries and calls as needed. Think step by step.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://plugin-3c56b9d4c8a6465998395f28b6a445b2-jexkai4vea-uc.a.run.app/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://plugin-3c56b9d4c8a6465998395f28b6a445b2-jexkai4vea-uc.a.run.app/logo.png",
"contact_email": "support@promptapps.ai",
"legal_info_url": "https://plugin-3c56b9d4c8a6465998395f28b6a445b2-jexkai4vea-uc.a.run.app/legal.html"
}
22 changes: 22 additions & 0 deletions api/app/clients/tools/.well-known/VoxScript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"schema_version": "v1",
"name_for_human": "VoxScript",
"name_for_model": "VoxScript",
"description_for_human": "Enables searching of YouTube transcripts, financial data sources Google Search results, and more!",
"description_for_model": "Plugin for searching through varius data sources.",
"auth": {
"type": "service_http",
"authorization_type": "bearer",
"verification_tokens": {
"openai": "ffc5226d1af346c08a98dee7deec9f76"
}
},
"api": {
"type": "openapi",
"url": "https://voxscript.awt.icu/swagger/v1/swagger.yaml",
"is_user_authenticated": false
},
"logo_url": "https://voxscript.awt.icu/images/VoxScript_logo_32x32.png",
"contact_email": "voxscript@allwiretech.com",
"legal_info_url": "https://voxscript.awt.icu/legal/"
}
18 changes: 18 additions & 0 deletions api/app/clients/tools/.well-known/askyourpdf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_model": "askyourpdf",
"name_for_human": "AskYourPDF",
"description_for_model": "This plugin is designed to expedite the extraction of information from PDF documents. It works by accepting a URL link to a PDF or a document ID (doc_id) from the user. If a URL is provided, the plugin first validates that it is a correct URL. \\nAfter validating the URL, the plugin proceeds to download the PDF and store its content in a vector database. If the user provides a doc_id, the plugin directly retrieves the document from the database. The plugin then scans through the stored PDFs to find answers to user queries or retrieve specific details.\\n\\nHowever, if an error occurs while querying the API, the user is prompted to download their document first, then manually upload it to [![Upload Document](https://raw.githubusercontent.com/AskYourPdf/ask-plugin/main/upload.png)](https://askyourpdf.com/upload). Once the upload is complete, the user should copy the resulting doc_id and paste it back into the chat for further interaction.\nThe plugin is particularly useful when the user's question pertains to content within a PDF document. When providing answers, the plugin also specifies the page number (highlighted in bold) where the relevant information was found. Remember, the URL must be valid for a successful query. Failure to validate the URL may lead to errors or unsuccessful queries.",
"description_for_human": "Unlock the power of your PDFs!, dive into your documents, find answers, and bring information to your fingertips.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "askyourpdf.yaml",
"has_user_authentication": false
},
"logo_url": "https://plugin.askyourpdf.com/.well-known/logo.png",
"contact_email": "plugin@askyourpdf.com",
"legal_info_url": "https://askyourpdf.com/terms"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Scholarly Graph Link",
"name_for_model": "scholarly_graph_link",
"description_for_human": "You can search papers, authors, datasets and software. It has access to Figshare, Arxiv, and many others.",
"description_for_model": "Run GraphQL queries against an API hosted by DataCite API. The API supports most GraphQL query but does not support mutations statements. Use `{ __schema { types { name kind } } }` to get all the types in the GraphQL schema. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{person(id:ORCID) {works(first:50) {nodes {id titles(first: 1){title} publicationYear}}}}` to get the first 50 works of a person based on their ORCID. All Ids are urls, e.g., https://orcid.org/0012-0000-1012-1110. Mutations statements are not allowed.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://api.datacite.org/graphql-openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://raw.githubusercontent.com/kjgarza/scholarly_graph_link/master/logo.png",
"contact_email": "kj.garza@gmail.com",
"legal_info_url": "https://github.com/kjgarza/scholarly_graph_link/blob/master/LICENSE"
}
24 changes: 24 additions & 0 deletions api/app/clients/tools/.well-known/has-issues/web_pilot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"schema_version": "v1",
"name_for_human": "WebPilot",
"name_for_model": "web_pilot",
"description_for_human": "Browse & QA Webpage/PDF/Data. Generate articles, from one or more URLs.",
"description_for_model": "This tool allows users to provide a URL(or URLs) and optionally requests for interacting with, extracting specific information or how to do with the content from the URL. Requests may include rewrite, translate, and others. If there any requests, when accessing the /api/visit-web endpoint, the parameter 'user_has_request' should be set to 'true. And if there's no any requests, 'user_has_request' should be set to 'false'.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://webreader.webpilotai.com/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://webreader.webpilotai.com/logo.png",
"contact_email": "dev@webpilot.ai",
"legal_info_url": "https://webreader.webpilotai.com/legal_info.html",
"headers": {
"id": "WebPilot-Friend-UID"
},
"params": {
"user_has_request": true
}
}
157 changes: 157 additions & 0 deletions api/app/clients/tools/.well-known/openapi/askyourpdf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
openapi: 3.0.2
info:
title: FastAPI
version: 0.1.0
servers:
- url: https://plugin.askyourpdf.com
paths:
/api/download_pdf:
post:
summary: Download Pdf
description: Download a PDF file from a URL and save it to the vector database.
operationId: download_pdf_api_download_pdf_post
parameters:
- required: true
schema:
title: Url
type: string
name: url
in: query
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/FileResponse'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/query:
post:
summary: Perform Query
description: Perform a query on a document.
operationId: perform_query_query_post
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/InputData'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseModel'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
components:
schemas:
DocumentMetadata:
title: DocumentMetadata
required:
- source
- page_number
- author
type: object
properties:
source:
title: Source
type: string
page_number:
title: Page Number
type: integer
author:
title: Author
type: string
FileResponse:
title: FileResponse
required:
- docId
type: object
properties:
docId:
title: Docid
type: string
error:
title: Error
type: string
HTTPValidationError:
title: HTTPValidationError
type: object
properties:
detail:
title: Detail
type: array
items:
$ref: '#/components/schemas/ValidationError'
InputData:
title: InputData
required:
- doc_id
- query
type: object
properties:
doc_id:
title: Doc Id
type: string
query:
title: Query
type: string
ResponseModel:
title: ResponseModel
required:
- results
type: object
properties:
results:
title: Results
type: array
items:
$ref: '#/components/schemas/SearchResult'
SearchResult:
title: SearchResult
required:
- doc_id
- text
- metadata
type: object
properties:
doc_id:
title: Doc Id
type: string
text:
title: Text
type: string
metadata:
$ref: '#/components/schemas/DocumentMetadata'
ValidationError:
title: ValidationError
required:
- loc
- msg
- type
type: object
properties:
loc:
title: Location
type: array
items:
anyOf:
- type: string
- type: integer
msg:
title: Message
type: string
type:
title: Error Type
type: string
Loading

0 comments on commit 514f625

Please sign in to comment.