This commit is contained in:
ajaythapliyal
2023-02-17 01:17:43 +05:30
parent 85b2f54829
commit 1b6a58520c
9 changed files with 301 additions and 6267 deletions

View File

@@ -19,6 +19,12 @@ module.exports = {
plugins: ['react'],
rules: {
'react/react-in-jsx-scope': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
settings: {
'import/parsers': {
@@ -34,10 +40,4 @@ module.exports = {
},
},
},
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -3,16 +3,29 @@ import Navigation from './components/Navigation';
import Conversation from './components/Conversation/Conversation';
import APIKeyModal from './components/APIKeyModal';
import About from './components/About';
import { useState } from 'react';
import { NavState } from './models/misc';
export default function App() {
const [navState, setNavState] = useState<NavState>('OPEN');
return (
<div className="relative flex flex-col transition-all md:flex-row">
<div className="min-h-full min-w-full transition-all">
<APIKeyModal />
<Navigation />
<Routes>
<Route path="/" element={<Conversation />} />
<Route path="/about" element={<About />} />
</Routes>
<Navigation
navState={navState}
setNavState={(val: NavState) => setNavState(val)}
/>
<div
className={`${
navState === 'OPEN' ? 'ml-0 md:ml-72 lg:ml-96' : ' ml-0 md:ml-16'
}`}
>
<Routes>
<Route path="/" element={<Conversation />} />
<Route path="/about" element={<About />} />
</Routes>
</div>
</div>
);
}

View File

@@ -1,63 +1,63 @@
import { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
setApiKey,
toggleApiKeyModal,
selectIsApiKeyModalOpen,
} from '../store';
export default function APIKeyModal({}) {
//TODO - Add form validation?
//TODO - Connect to backend
//TODO - Add link to OpenAI API Key page
const dispatch = useDispatch();
const isApiModalOpen = useSelector(selectIsApiKeyModalOpen);
const [key, setKey] = useState('');
const [formError, setFormError] = useState(false);
function handleSubmit() {
if (key.length < 1) {
setFormError(true);
return;
}
dispatch(setApiKey(key));
dispatch(toggleApiKeyModal());
}
return (
<div
className={`${
isApiModalOpen ? 'visible' : 'hidden'
} absolute z-30 h-screen w-screen bg-gray-alpha`}
>
<article className="mx-auto mt-24 flex w-[90vw] max-w-lg flex-col gap-4 rounded-lg bg-white p-6 shadow-lg">
<p className="text-xl text-jet">OpenAI API Key</p>
<p className="text-lg leading-5 text-gray-500">
Before you can start using DocsGPT we need you to provide an API key
for llm. Currently, we support only OpenAI but soon many more. You can
find it here.
</p>
<input
type="text"
className="h-10 w-full border-b-2 border-jet focus:outline-none"
value={key}
maxLength={100}
placeholder="API Key"
onChange={(e) => setKey(e.target.value)}
/>
<div className="flex justify-between">
{formError && (
<p className="text-sm text-red-500">Please enter a valid API key</p>
)}
<button
onClick={() => handleSubmit()}
className="ml-auto h-10 w-20 rounded-lg bg-violet-800 text-white transition-all hover:bg-violet-700"
>
Save
</button>
</div>
</article>
</div>
);
}
import { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
setApiKey,
toggleApiKeyModal,
selectIsApiKeyModalOpen,
} from '../store';
export default function APIKeyModal() {
//TODO - Add form validation?
//TODO - Connect to backend
//TODO - Add link to OpenAI API Key page
const dispatch = useDispatch();
const isApiModalOpen = useSelector(selectIsApiKeyModalOpen);
const [key, setKey] = useState('');
const [formError, setFormError] = useState(false);
function handleSubmit() {
if (key.length < 1) {
setFormError(true);
return;
}
dispatch(setApiKey(key));
dispatch(toggleApiKeyModal());
}
return (
<div
className={`${
isApiModalOpen ? 'visible' : 'hidden'
} absolute z-30 h-screen w-screen bg-gray-alpha`}
>
<article className="mx-auto mt-24 flex w-[90vw] max-w-lg flex-col gap-4 rounded-lg bg-white p-6 shadow-lg">
<p className="text-xl text-jet">OpenAI API Key</p>
<p className="text-lg leading-5 text-gray-500">
Before you can start using DocsGPT we need you to provide an API key
for llm. Currently, we support only OpenAI but soon many more. You can
find it here.
</p>
<input
type="text"
className="h-10 w-full border-b-2 border-jet focus:outline-none"
value={key}
maxLength={100}
placeholder="API Key"
onChange={(e) => setKey(e.target.value)}
/>
<div className="flex justify-between">
{formError && (
<p className="text-sm text-red-500">Please enter a valid API key</p>
)}
<button
onClick={() => handleSubmit()}
className="ml-auto h-10 w-20 rounded-lg bg-violet-800 text-white transition-all hover:bg-violet-700"
>
Save
</button>
</div>
</article>
</div>
);
}

View File

@@ -1,71 +1,54 @@
import { useSelector } from 'react-redux';
import { useMediaQuery } from '../hooks';
import { selectIsMenuOpen } from '../store';
//TODO - Add hyperlinks to text
//TODO - Styling
export default function About() {
const isMobile = useMediaQuery('(max-width: 768px)');
const isMenuOpen = useSelector(selectIsMenuOpen);
return (
//Parent div for all content shown through App.tsx routing needs to have this styling. Might change when state management is updated.
<div
className={`${
isMobile
? isMenuOpen
? 'mt-80'
: 'mt-16'
: isMenuOpen
? 'md:ml-72 lg:ml-96'
: 'ml-16'
} h-full w-full p-6 transition-all`}
>
<article className="mx-auto my-auto flex w-full max-w-6xl flex-col gap-6 rounded-lg bg-gray-100 p-6 text-jet lg:p-10 xl:p-16">
<p className="text-3xl font-semibold">About DocsGPT 🦖</p>
<p className="mt-4 text-xl font-bold">
Find the information in your documentation through AI-powered
open-source chatbot. Powered by GPT-3, Faiss and LangChain.
</p>
<div>
<p className="text-lg">
If you want to add your own documentation, please follow the
instruction below:
</p>
<p className="mt-4 text-lg">
1. Navigate to{' '}
<span className="bg-gray-200 italic"> /application</span> folder
</p>
<p className="mt-4 text-lg">
2. Install dependencies from{' '}
<span className="bg-gray-200 italic">
pip install -r requirements.txt
</span>
</p>
<p className="mt-4 text-lg">
3. Prepare a <span className="bg-gray-200 italic">.env</span> file.
Copy <span className="bg-gray-200 italic">.env_sample</span> and
create <span className="bg-gray-200 italic">.env</span> with your
OpenAI API token
</p>
<p className="mt-4 text-lg">
4. Run the app with{' '}
<span className="bg-gray-200 italic">python app.py</span>
</p>
</div>
<p className="text-lg">
Currently It uses python pandas documentation, so it will respond to
information relevant to pandas. If you want to train it on different
documentation - please follow this guide.
</p>
<p className="mt-4 text-lg">
If you want to launch it on your own server - follow this guide.
</p>
</article>
</div>
);
}
//TODO - Add hyperlinks to text
//TODO - Styling
export default function About() {
return (
//Parent div for all content shown through App.tsx routing needs to have this styling. Might change when state management is updated.
<div className="grid min-h-screen">
<article className=" mx-auto my-auto flex w-full max-w-6xl flex-col place-items-center gap-6 rounded-lg bg-gray-100 p-6 text-jet lg:p-10 xl:p-16">
<p className="text-3xl font-semibold">About DocsGPT 🦖</p>
<p className="mt-4 text-xl font-bold">
Find the information in your documentation through AI-powered
open-source chatbot. Powered by GPT-3, Faiss and LangChain.
</p>
<div>
<p className="text-lg">
If you want to add your own documentation, please follow the
instruction below:
</p>
<p className="mt-4 text-lg">
1. Navigate to{' '}
<span className="bg-gray-200 italic"> /application</span> folder
</p>
<p className="mt-4 text-lg">
2. Install dependencies from{' '}
<span className="bg-gray-200 italic">
pip install -r requirements.txt
</span>
</p>
<p className="mt-4 text-lg">
3. Prepare a <span className="bg-gray-200 italic">.env</span> file.
Copy <span className="bg-gray-200 italic">.env_sample</span> and
create <span className="bg-gray-200 italic">.env</span> with your
OpenAI API token
</p>
<p className="mt-4 text-lg">
4. Run the app with{' '}
<span className="bg-gray-200 italic">python app.py</span>
</p>
</div>
<p className="text-lg">
Currently It uses python pandas documentation, so it will respond to
information relevant to pandas. If you want to train it on different
documentation - please follow this guide.
</p>
<p className="mt-4 text-lg">
If you want to launch it on your own server - follow this guide.
</p>
</article>
</div>
);
}

View File

@@ -1,25 +1,7 @@
import { useMediaQuery } from '../../hooks';
import { selectIsMenuOpen } from '../../store';
import { useSelector } from 'react-redux';
export default function Conversation() {
const isMobile = useMediaQuery('(max-width: 768px)');
const isMenuOpen = useSelector(selectIsMenuOpen);
return (
//Parent div for all content shown through App.tsx routing needs to have this styling.
<div
className={`${
isMobile
? isMenuOpen
? 'mt-80'
: 'mt-16'
: isMenuOpen
? 'md:ml-72 lg:ml-96'
: 'ml-16'
} h-full w-full p-6 transition-all`}
>
Docs GPT Chat Placeholder
</div>
);
}
export default function Conversation() {
return (
<div className="h-full w-full p-6 text-center transition-all">
Docs GPT Chat Placeholder
</div>
);
}

View File

@@ -1,163 +1,99 @@
import { useDispatch, useSelector } from 'react-redux';
import { NavLink } from 'react-router-dom';
import { useMediaQuery } from '../hooks';
import {
toggleApiKeyModal,
selectIsMenuOpen,
toggleIsMenuOpen,
} from '../store';
import Arrow1 from '../imgs/arrow.svg';
import Hamburger from '../imgs/hamburger.svg';
import Key from '../imgs/key.svg';
import Info from '../imgs/info.svg';
import Link from '../imgs/link.svg';
import Exit from '../imgs/exit.svg';
//TODO - Need to replace Chat button to open secondary nav with scrollable past chats option and new chat at top
//TODO - Need to add Discord and Github links
function MobileNavigation({}) {
const dispatch = useDispatch();
const isMenuOpen = useSelector(selectIsMenuOpen);
return (
<div
className={`${
isMenuOpen ? 'border-b-2 border-gray-100' : 'h-16'
} fixed flex w-full flex-col bg-gray-50 transition-all`}
>
<div className="h-16 w-full border-b-2 border-gray-100">
{isMenuOpen ? (
<>
<button
className="mt-5 ml-6 h-6 w-6"
onClick={() => dispatch(toggleIsMenuOpen())}
>
<img src={Exit} alt="menu toggle" className="w-5" />
</button>
</>
) : (
<>
<button
className="mt-5 ml-6 h-6 w-6"
onClick={() => dispatch(toggleIsMenuOpen())}
>
<img src={Hamburger} alt="menu toggle" className="w-7" />
</button>
</>
)}
</div>
{isMenuOpen && (
<nav className="my-4 flex flex-col">
<NavLink
to="/"
className="flex h-12 cursor-pointer gap-4 rounded-md px-6 hover:bg-gray-100"
>
<img src={Info} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Chat</p>
</NavLink>
<NavLink
to="/about"
className="flex h-12 cursor-pointer gap-4 rounded-md px-6 hover:bg-gray-100"
>
<img src={Info} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">About</p>
</NavLink>
<div className="flex h-12 cursor-pointer gap-4 rounded-md px-6 hover:bg-gray-100">
<img src={Link} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Discord</p>
</div>
<div className="flex h-12 cursor-pointer gap-4 rounded-md px-6 hover:bg-gray-100">
<img src={Link} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Github</p>
</div>
<div
className="flex h-12 cursor-pointer gap-4 rounded-md px-6 hover:bg-gray-100"
onClick={() => dispatch(toggleApiKeyModal())}
>
<img src={Key} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Reset Key</p>
</div>
</nav>
)}
</div>
);
}
function DesktopNavigation() {
const dispatch = useDispatch();
const isMenuOpen = useSelector(selectIsMenuOpen);
return (
<div
className={`${
isMenuOpen ? 'w-72 lg:w-96' : 'w-16'
} fixed flex h-screen flex-col border-r-2 border-gray-100 bg-gray-50 transition-all`}
>
<div
className={`${
isMenuOpen ? 'w-full' : 'w-16'
} ml-auto h-16 border-b-2 border-gray-100`}
>
<button
className="float-right mr-5 mt-5 h-5 w-5"
onClick={() => dispatch(toggleIsMenuOpen())}
>
<img
src={Arrow1}
alt="menu toggle"
className={`${
isMenuOpen ? 'rotate-0' : 'rotate-180'
} m-auto w-3 transition-all`}
/>
</button>
</div>
{isMenuOpen && (
<>
<div className="flex-grow border-b-2 border-gray-100"></div>
<div className="flex h-16 flex-col border-b-2 border-gray-100">
<div
className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100"
onClick={() => dispatch(toggleApiKeyModal())}
>
<img src={Key} alt="key" className="ml-2 w-6" />
<p className="my-auto text-eerie-black">Reset Key</p>
</div>
</div>
<div className="flex h-48 flex-col border-b-2 border-gray-100">
<NavLink
to="/about"
className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100"
>
<img src={Info} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">About</p>
</NavLink>
<div className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100">
<img src={Link} alt="link" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Discord</p>
</div>
<div className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100">
<img src={Link} alt="link" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Github</p>
</div>
</div>
</>
)}
</div>
);
}
export default function Navigation() {
const isMobile = useMediaQuery('(max-width: 768px)');
if (isMobile) {
return <MobileNavigation />;
} else {
return <DesktopNavigation />;
}
}
import { useDispatch, useSelector } from 'react-redux';
import { NavLink } from 'react-router-dom';
import { useMediaQuery } from '../hooks';
import { toggleApiKeyModal } from '../store';
import Arrow1 from '../imgs/arrow.svg';
import Hamburger from '../imgs/hamburger.svg';
import Key from '../imgs/key.svg';
import Info from '../imgs/info.svg';
import Link from '../imgs/link.svg';
import Exit from '../imgs/exit.svg';
import { NavState } from '../models/misc';
//TODO - Need to replace Chat button to open secondary nav with scrollable past chats option and new chat at top
//TODO - Need to add Discord and Github links
export default function Navigation({
navState,
setNavState,
}: {
navState: NavState;
setNavState: (val: NavState) => void;
}) {
const openNav = (
<div className="fixed h-full w-72 flex-col border-r-2 border-gray-100 bg-gray-50 transition-all md:visible md:flex lg:w-96">
<div className={'h-16 w-full border-b-2 border-gray-100'}>
<button
className="float-right mr-5 mt-5 h-5 w-5"
onClick={() => setNavState('CLOSED')}
>
<img
src={Arrow1}
alt="menu toggle"
className={'m-auto w-3 rotate-0 transition-all'}
/>
</button>
</div>
<div className="flex-grow border-b-2 border-gray-100"></div>
<div className="flex h-16 flex-col border-b-2 border-gray-100">
<div
className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100"
onClick={() => {
return;
}}
>
<img src={Key} alt="key" className="ml-2 w-6" />
<p className="my-auto text-eerie-black">Reset Key</p>
</div>
</div>
<div className="flex h-48 flex-col border-b-2 border-gray-100">
<NavLink
to="/about"
className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100"
>
<img src={Info} alt="info" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">About</p>
</NavLink>
<div className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100">
<img src={Link} alt="link" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Discord</p>
</div>
<div className="my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100">
<img src={Link} alt="link" className="ml-2 w-5" />
<p className="my-auto text-eerie-black">Github</p>
</div>
</div>
</div>
);
const closedNav = (
<>
<div className="fixed hidden h-full w-16 flex-col border-r-2 border-gray-100 bg-gray-50 transition-all md:flex">
<div className={'h-16 w-16 border-b-2 border-gray-100'}>
<button
className="float-right mr-5 mt-5 h-5 w-5"
onClick={() => setNavState('OPEN')}
>
<img
src={Arrow1}
alt="menu toggle"
className={'m-auto w-3 rotate-180 transition-all'}
/>
</button>
</div>
</div>
<button
className="fixed mt-5 ml-6 h-6 w-6 md:hidden"
onClick={() => setNavState('OPEN')}
>
<img src={Hamburger} alt="menu toggle" className="w-7" />
</button>
</>
);
return navState === 'OPEN' ? openNav : closedNav;
}

View File

@@ -0,0 +1 @@
export type NavState = 'OPEN' | 'CLOSED';

View File

@@ -1,48 +1,42 @@
import { configureStore, createSlice, PayloadAction } from '@reduxjs/toolkit';
interface State {
isApiKeyModalOpen: boolean;
apiKey: string;
isMenuOpen: boolean;
}
const initialState: State = {
isApiKeyModalOpen: false,
apiKey: '',
isMenuOpen: false,
};
export const slice = createSlice({
name: 'app',
initialState,
reducers: {
toggleApiKeyModal: (state) => {
state.isApiKeyModalOpen = !state.isApiKeyModalOpen;
console.log('showApiKeyModal', state.isApiKeyModalOpen);
},
setApiKey: (state, action: PayloadAction<string>) => {
state.apiKey = action.payload;
console.log('setApiKey', action.payload);
},
toggleIsMenuOpen: (state) => {
state.isMenuOpen = !state.isMenuOpen;
},
},
});
export const { toggleApiKeyModal, setApiKey, toggleIsMenuOpen } = slice.actions;
const store = configureStore({
reducer: {
app: slice.reducer,
},
});
type RootState = ReturnType<typeof store.getState>;
export const selectIsApiKeyModalOpen = (state: RootState) =>
state.app.isApiKeyModalOpen;
export const selectApiKey = (state: RootState) => state.app.apiKey;
export const selectIsMenuOpen = (state: RootState) => state.app.isMenuOpen;
export default store;
import { configureStore, createSlice, PayloadAction } from '@reduxjs/toolkit';
interface State {
isApiKeyModalOpen: boolean;
apiKey: string;
}
const initialState: State = {
isApiKeyModalOpen: false,
apiKey: '',
};
export const slice = createSlice({
name: 'app',
initialState,
reducers: {
toggleApiKeyModal: (state) => {
state.isApiKeyModalOpen = !state.isApiKeyModalOpen;
console.log('showApiKeyModal', state.isApiKeyModalOpen);
},
setApiKey: (state, action: PayloadAction<string>) => {
state.apiKey = action.payload;
console.log('setApiKey', action.payload);
},
},
});
export const { toggleApiKeyModal, setApiKey } = slice.actions;
const store = configureStore({
reducer: {
app: slice.reducer,
},
});
type RootState = ReturnType<typeof store.getState>;
export const selectIsApiKeyModalOpen = (state: RootState) =>
state.app.isApiKeyModalOpen;
export const selectApiKey = (state: RootState) => state.app.apiKey;
export default store;