Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ChatGPT Plugins/OpenAPI specs for Plugins Endpoint #620

Merged
merged 33 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
152e20a
wip: proof of concept for openapi chain
danny-avila Jul 5, 2023
ddfb2ee
chore(api): update langchain dependency to version 0.0.105
danny-avila Jul 9, 2023
a9c8c36
feat(Plugins): use ChatGPT Plugins/OpenAPI specs (first pass)
danny-avila Jul 10, 2023
985553c
chore(manifest.json): update pluginKey for "Browser" tool to "web-bro…
danny-avila Jul 10, 2023
75ae5c8
fix(handleSubmit.js): set unfinished property to false for all endpoints
danny-avila Jul 10, 2023
1d7e33a
fix(handlers.js): remove unnecessary capitalizeWords function and use…
danny-avila Jul 10, 2023
1c7280d
feat(endpoints): add plugins selector to endpoints file
danny-avila Jul 10, 2023
0b9aedf
fix(OpenAPIPlugin.js): rename readYamlFile function to readSpecFile
danny-avila Jul 10, 2023
7dd27f9
feat(api): add new tools
danny-avila Jul 11, 2023
4bacbfa
feat(PluginsClient.js): import findMessageContent function from utils
danny-avila Jul 11, 2023
9b869d4
fix(PluginStoreDialog.tsx): update z-index value for the dialog conta…
danny-avila Jul 11, 2023
04238b0
chore(web_pilot.json): add "params" field with "user_has_request" par…
danny-avila Jul 11, 2023
44d2728
chore(eslintrc.js): update eslint rules
danny-avila Jul 12, 2023
d6fa947
fix(package-lock.json): update langchain dependency to version ^0.0.105
danny-avila Jul 12, 2023
a694305
fix(OpenAPIPlugin.js): change header key from 'id' to 'librechat_user…
danny-avila Jul 12, 2023
4af56a1
fix(OpenAPIPlugin.js): update SUFFIX variable to provide a clearer de…
danny-avila Jul 12, 2023
2289b84
feat(PluginsClient.js): sendIntermediateMessage on successful Agent load
danny-avila Jul 12, 2023
425f306
Update chatgpt_plugins_openapi.md
danny-avila Jul 13, 2023
2dc4220
chore: rebuild package-lock file
danny-avila Jul 14, 2023
ab9a88d
chore: format/lint all files with new rules
danny-avila Jul 14, 2023
c981102
chore: format all files
danny-avila Jul 14, 2023
0bc6f71
chore(README.md): update AI model selection list
danny-avila Jul 14, 2023
5863f08
fix(Plugin.tsx): type issue
danny-avila Jul 14, 2023
e3e9f07
feat(tools): add new tool WebPilot
danny-avila Jul 14, 2023
33f6aab
feat(OpenAPIPlugin.js): add getSpec and readSpecFile functions
danny-avila Jul 14, 2023
6772438
chore(agent-demo-1.js): remove unused code and dependencies
danny-avila Jul 14, 2023
65824d4
feat(addOpenAPISpecs): add function to transform OpenAPI specs into d…
danny-avila Jul 14, 2023
4722289
feat(loadSpecs.spec.js): add unit tests for ManifestDefinition, valid…
danny-avila Jul 14, 2023
2ba240e
fix: package file resolution bug
danny-avila Jul 14, 2023
1ae0348
chore: move scholarly_graph_link manifest to 'has-issues'
danny-avila Jul 14, 2023
f67ae4a
refactor(client/hooks): convert to TS and export from index
danny-avila Jul 15, 2023
dbcc3ef
Update introduction.md
danny-avila Jul 15, 2023
1b552be
Update chatgpt_plugins_openapi.md
danny-avila Jul 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
danny-avila committed Jul 15, 2023
commit 1c7280d09b6ce8d5111020d64811cb94567cd906
1 change: 0 additions & 1 deletion client/src/components/Input/PluginsOptions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function PluginsOptions() {

if (endpoint !== 'gptPlugins') return null;
const models = endpointsConfig?.['gptPlugins']?.['availableModels'] || [];
// const availableTools = endpointsConfig?.['gptPlugins']?.['availableTools'] || [];

const triggerAdvancedMode = () => setAdvancedMode((prev) => !prev);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React, { useRef, useState } from 'react';
import Clipboard from '~/components/svg/Clipboard';
import CheckMark from '~/components/svg/CheckMark';
import React, { useRef, useState, RefObject } from 'react';
import { Clipboard, CheckMark } from '~/components';
import { InfoIcon } from 'lucide-react';
import { cn } from '~/utils/';

const CodeBar = React.memo(({ lang, codeRef, plugin = null }) => {
interface CodeBarProps {
lang: string;
codeRef: RefObject<HTMLElement>;
plugin?: boolean;
}

const CodeBar: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, plugin = null }) => {
const [isCopied, setIsCopied] = useState(false);
return (
<div className="relative flex items-center rounded-tl-md rounded-tr-md bg-gray-800 px-4 py-2 font-sans text-xs text-gray-200">
Expand Down Expand Up @@ -40,13 +45,20 @@ const CodeBar = React.memo(({ lang, codeRef, plugin = null }) => {
);
});

const CodeBlock = ({ lang, codeChildren, classProp = '', plugin = null }) => {
const codeRef = useRef(null);
interface CodeBlockProps {
lang: string;
codeChildren: string;
classProp?: string;
plugin?: boolean;
}

const CodeBlock: React.FC<CodeBlockProps> = ({ lang, codeChildren, classProp = '', plugin = null }) => {
const codeRef = useRef<HTMLElement>(null);
const language = plugin ? 'json' : lang;

return (
<div className="rounded-md bg-black">
<CodeBar lang={lang} codeRef={codeRef} plugin={plugin} />
<CodeBar lang={lang} codeRef={codeRef} plugin={!!plugin} />
<div className={cn(classProp, 'overflow-y-auto p-4')}>
<code ref={codeRef} className={`hljs !whitespace-pre language-${language}`}>
{codeChildren}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Messages/Message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useState, useEffect, useRef } from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import copy from 'copy-to-clipboard';
import Plugin from './Plugin.jsx';
import Plugin from './Plugin';
import SubRow from './Content/SubRow';
import Content from './Content/Content';
import MultiMessage from './MultiMessage';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { useState } from 'react';
import React, { useState, useCallback, memo, ReactNode } from 'react';
import { Spinner } from '~/components';
import { useRecoilValue } from 'recoil';
import CodeBlock from './Content/CodeBlock.jsx';
import { Disclosure } from '@headlessui/react';
import { ChevronDownIcon } from 'lucide-react';
import { cn } from '~/utils/';
import store from '~/store';

function formatInputs(inputs) {
interface Input {
inputStr: string;
}

interface PluginProps {
plugin: {
plugin: string;
input: string;
thought: string;
loading?: boolean;
outputs?: string;
latest?: string;
inputs?: Input[];
};
}

type PluginsMap = {
[pluginKey: string]: string;
};

function formatInputs(inputs: Input[]) {
let output = '';

for (let i = 0; i < inputs.length; i++) {
Expand All @@ -19,27 +41,46 @@ function formatInputs(inputs) {
return output;
}

export default function Plugin({ plugin }) {
const Plugin: React.FC<PluginProps> = ({ plugin }) => {
const [loading, setLoading] = useState(plugin.loading);
const finished = plugin.outputs && plugin.outputs.length > 0;
const plugins: PluginsMap = useRecoilValue(store.plugins);

const getPluginName = useCallback((currentTool: string) => {
const pluginKey = currentTool?.toLowerCase();
if (!pluginKey) {
return null;
}

if (!plugin.latest || (plugin.latest && plugin.latest.toLowerCase() === 'n/a')) {
if (pluginKey === 'n/a' || pluginKey === 'self reflection') {
return pluginKey;
}
return plugins[pluginKey] ?? 'self reflection';
}, [plugins]);

if (!plugin || !plugin.latest) {
return null;
}

const latestPlugin = getPluginName(plugin.latest);

if (!latestPlugin || (latestPlugin && latestPlugin === 'n/a')) {
return null;
}

if (finished && loading) {
setLoading(false);
}

const generateStatus = () => {
if (!loading && plugin.latest === 'Self Reflection') {
const generateStatus = (): ReactNode => {
if (!loading && latestPlugin === 'self reflection') {
return 'Finished';
} else if (plugin.latest === 'Self Reflection') {
} else if (latestPlugin === 'self reflection') {
return 'I\'m thinking...';
} else {
return (
<>
{loading ? 'Using' : 'Used'} <b>{plugin.latest}</b>
{loading ? 'Using' : 'Used'} <b>{latestPlugin}</b>
{loading ? '...' : ''}
</>
);
Expand All @@ -54,7 +95,7 @@ export default function Plugin({ plugin }) {
<div
className={cn(
loading ? 'bg-green-100' : 'bg-[#ECECF1]',
'flex items-center rounded p-3 text-sm text-gray-900',
'flex items-center rounded p-3 text-sm text-gray-900'
)}
>
<div>
Expand All @@ -70,15 +111,15 @@ export default function Plugin({ plugin }) {

<Disclosure.Panel className="my-3 flex max-w-full flex-col gap-3">
<CodeBlock
lang={plugin.latest?.toUpperCase() || 'INPUTS'}
codeChildren={formatInputs(plugin.inputs)}
lang={latestPlugin?.toUpperCase() || 'INPUTS'}
codeChildren={formatInputs(plugin.inputs ?? [])}
plugin={true}
classProp="max-h-[450px]"
/>
{finished && (
<CodeBlock
lang="OUTPUTS"
codeChildren={plugin.outputs}
codeChildren={plugin.outputs ?? ''}
plugin={true}
classProp="max-h-[450px]"
/>
Expand All @@ -90,3 +131,5 @@ export default function Plugin({ plugin }) {
</div>
);
}

export default memo(Plugin);
2 changes: 2 additions & 0 deletions client/src/components/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export { default as GPTIcon } from './GPTIcon';
export { default as CogIcon } from './CogIcon';
export { default as Panel } from './Panel';
export { default as Spinner } from './Spinner';
export { default as Clipboard } from './Clipboard';
export { default as CheckMark } from './CheckMark';
export { default as MessagesSquared } from './MessagesSquared';
export { default as StopGeneratingIcon } from './StopGeneratingIcon';
export { default as GoogleIcon } from './GoogleIcon';
Expand Down
9 changes: 9 additions & 0 deletions client/src/store/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const endpointsConfig = atom({
},
});

const plugins = selector({
key: 'plugins',
get: ({ get }) => {
const config = get(endpointsConfig) || {};
return config?.gptPlugins?.plugins || {};
}
});

const endpointsFilter = selector({
key: 'endpointsFilter',
get: ({ get }) => {
Expand All @@ -35,6 +43,7 @@ const availableEndpoints = selector({
// const modelAvailable

export default {
plugins,
endpointsConfig,
endpointsFilter,
availableEndpoints,
Expand Down