@@ -211,6 +185,8 @@ const General: React.FC = () => {
setSelectedTheme(option);
option !== selectedTheme && toggleTheme();
}}
+ size="w-56"
+ rounded="3xl"
/>
@@ -221,9 +197,11 @@ const General: React.FC = () => {
options={languages}
selectedValue={selectedLanguage}
onSelect={setSelectedLanguage}
+ size="w-56"
+ rounded="3xl"
/>
-
+
Chunks processed per query
@@ -231,6 +209,19 @@ const General: React.FC = () => {
options={chunks}
selectedValue={selectedChunks}
onSelect={(value: string) => dispatch(setChunks(value))}
+ size="w-56"
+ rounded="3xl"
+ />
+
+
+
+ dispatch(setPrompt({ name: name, id: id, type: type }))
+ }
+ setPrompts={setPrompts}
+ apiHost={apiHost}
/>
@@ -238,12 +229,6 @@ const General: React.FC = () => {
};
export default Setting;
-type PromptProps = {
- prompts: { name: string; id: string; type: string }[];
- selectedPrompt: { name: string; id: string; type: string };
- onSelectPrompt: (name: string, id: string, type: string) => void;
- setPrompts: (prompts: { name: string; id: string; type: string }[]) => void;
-};
const Prompts: React.FC
= ({
prompts,
@@ -260,11 +245,20 @@ const Prompts: React.FC = ({
id: string;
type: string;
}) => {
- setNewPromptName(name);
+ setEditPromptName(name);
onSelectPrompt(name, id, type);
};
- const [newPromptName, setNewPromptName] = useState(selectedPrompt.name);
+ const [newPromptName, setNewPromptName] = useState('');
const [newPromptContent, setNewPromptContent] = useState('');
+ const [editPromptName, setEditPromptName] = useState('');
+ const [editPromptContent, setEditPromptContent] = useState('');
+ const [currentPromptEdit, setCurrentPromptEdit] = useState({
+ id: '',
+ name: '',
+ type: '',
+ });
+ const [modalType, setModalType] = useState<'ADD' | 'EDIT'>('ADD');
+ const [modalState, setModalState] = useState('INACTIVE');
const handleAddPrompt = async () => {
try {
@@ -295,16 +289,14 @@ const Prompts: React.FC = ({
}
};
- const handleDeletePrompt = () => {
- setPrompts(prompts.filter((prompt) => prompt.id !== selectedPrompt.id));
- console.log('selectedPrompt.id', selectedPrompt.id);
-
+ const handleDeletePrompt = (id: string) => {
+ setPrompts(prompts.filter((prompt) => prompt.id !== id));
fetch(`${apiHost}/api/delete_prompt`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
- body: JSON.stringify({ id: selectedPrompt.id }),
+ body: JSON.stringify({ id: id }),
})
.then((response) => {
if (!response.ok) {
@@ -321,50 +313,45 @@ const Prompts: React.FC = ({
});
};
- useEffect(() => {
- const fetchPromptContent = async () => {
- console.log('fetching prompt content');
- try {
- const response = await fetch(
- `${apiHost}/api/get_single_prompt?id=${selectedPrompt.id}`,
- {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- },
+ const fetchPromptContent = async (name: string) => {
+ console.log('fetching prompt content');
+ try {
+ const response = await fetch(
+ `${apiHost}/api/get_single_prompt?id=${name}`,
+ {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
},
- );
- if (!response.ok) {
- throw new Error('Failed to fetch prompt content');
- }
- const promptContent = await response.json();
- setNewPromptContent(promptContent.content);
- } catch (error) {
- console.error(error);
+ },
+ );
+ if (!response.ok) {
+ throw new Error('Failed to fetch prompt content');
}
- };
+ const promptContent = await response.json();
+ setEditPromptContent(promptContent.content);
+ } catch (error) {
+ console.error(error);
+ }
+ };
- fetchPromptContent();
- }, [selectedPrompt]);
-
- const handleSaveChanges = () => {
+ const handleSaveChanges = (id: string, type: string) => {
fetch(`${apiHost}/api/update_prompt`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
- id: selectedPrompt.id,
- name: newPromptName,
- content: newPromptContent,
+ id: id,
+ name: editPromptName,
+ content: editPromptContent,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error('Failed to update prompt');
}
- onSelectPrompt(newPromptName, selectedPrompt.id, selectedPrompt.type);
- setNewPromptName(newPromptName);
+ onSelectPrompt(editPromptName, id, type);
})
.catch((error) => {
console.error(error);
@@ -372,76 +359,65 @@ const Prompts: React.FC = ({
};
return (
-
-
-
Active Prompt
-
+ <>
+
+
+
+
Active Prompt
+
{
+ setModalType('EDIT');
+ setEditPromptName(name);
+ fetchPromptContent(name);
+ setCurrentPromptEdit({ id: id, name: name, type: type });
+ setModalState('ACTIVE');
+ }}
+ onDelete={handleDeletePrompt}
+ />
+
+
+
-
-
-
Prompt name
{' '}
-
- start by editing name
-
-
setNewPromptName(e.target.value)}
- />
-
-
-
-
-
-
-
-
-
-
+
+ >
);
};
@@ -496,10 +472,8 @@ const Documents: React.FC
= ({
}) => {
return (
-
- {/*
Documents
*/}
-
-
+
+
diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx
index 060919da..f14df984 100644
--- a/frontend/src/components/Dropdown.tsx
+++ b/frontend/src/components/Dropdown.tsx
@@ -1,10 +1,16 @@
import { useState } from 'react';
import Arrow2 from '../assets/dropdown-arrow.svg';
+import Edit from '../assets/edit.svg';
+import Trash from '../assets/trash.svg';
function Dropdown({
options,
selectedValue,
onSelect,
+ size = 'w-32',
+ rounded = 'xl',
+ showEdit,
+ onEdit,
showDelete,
onDelete,
placeholder,
@@ -18,6 +24,10 @@ function Dropdown({
| ((value: string) => void)
| ((value: { name: string; id: string; type: string }) => void)
| ((value: { label: string; value: string }) => void);
+ size?: string;
+ rounded?: 'xl' | '3xl';
+ showEdit?: boolean;
+ onEdit?: (value: { name: string; id: string; type: string }) => void;
showDelete?: boolean;
onDelete?: (value: string) => void;
placeholder?: string;
@@ -27,26 +37,21 @@ function Dropdown({
const [isOpen, setIsOpen] = useState(false);
return (
))}
diff --git a/frontend/src/preferences/PromptsModal.tsx b/frontend/src/preferences/PromptsModal.tsx
new file mode 100644
index 00000000..ce0ecb47
--- /dev/null
+++ b/frontend/src/preferences/PromptsModal.tsx
@@ -0,0 +1,213 @@
+import { ActiveState } from '../models/misc';
+
+function AddPrompt({
+ setModalState,
+ handleAddPrompt,
+ newPromptName,
+ setNewPromptName,
+ newPromptContent,
+ setNewPromptContent,
+}: {
+ setModalState: (state: ActiveState) => void;
+ handleAddPrompt?: () => void;
+ newPromptName: string;
+ setNewPromptName: (name: string) => void;
+ newPromptContent: string;
+ setNewPromptContent: (content: string) => void;
+}) {
+ return (
+
+
Add Prompt
+
+ Add your custom prompt and save it to DocsGPT
+
+
+
setNewPromptName(e.target.value)}
+ >
+
+
+ Prompt Name
+
+
+
+
+ Prompt Text
+
+
+
+
+
+
+ Save
+
+ {
+ setModalState('INACTIVE');
+ }}
+ className="cursor-pointer font-medium dark:text-light-gray"
+ >
+ Cancel
+
+
+
+ );
+}
+
+function EditPrompt({
+ setModalState,
+ handleEditPrompt,
+ editPromptName,
+ setEditPromptName,
+ editPromptContent,
+ setEditPromptContent,
+ currentPromptEdit,
+}: {
+ setModalState: (state: ActiveState) => void;
+ handleEditPrompt?: (id: string, type: string) => void;
+ editPromptName: string;
+ setEditPromptName: (name: string) => void;
+ editPromptContent: string;
+ setEditPromptContent: (content: string) => void;
+ currentPromptEdit: { name: string; id: string; type: string };
+}) {
+ return (
+
+
Edit Prompt
+
+ Edit your custom prompt and save it to DocsGPT.
+
+
+
setEditPromptName(e.target.value)}
+ >
+
+
+ Prompt Name
+
+
+
+
+ Prompt Text
+
+
+
+
+
+ {
+ handleEditPrompt &&
+ handleEditPrompt(currentPromptEdit.id, currentPromptEdit.type);
+ }}
+ disabled={currentPromptEdit.type === 'public'}
+ >
+ Save
+
+ {
+ setModalState('INACTIVE');
+ }}
+ className="cursor-pointer font-medium dark:text-light-gray"
+ >
+ Cancel
+
+
+
+ );
+}
+
+export default function PromptsModal({
+ modalState,
+ setModalState,
+ type,
+ newPromptName,
+ setNewPromptName,
+ newPromptContent,
+ setNewPromptContent,
+ editPromptName,
+ setEditPromptName,
+ editPromptContent,
+ setEditPromptContent,
+ currentPromptEdit,
+ handleAddPrompt,
+ handleEditPrompt,
+}: {
+ modalState: ActiveState;
+ setModalState: (state: ActiveState) => void;
+ type: 'ADD' | 'EDIT';
+ newPromptName: string;
+ setNewPromptName: (name: string) => void;
+ newPromptContent: string;
+ setNewPromptContent: (content: string) => void;
+ editPromptName: string;
+ setEditPromptName: (name: string) => void;
+ editPromptContent: string;
+ setEditPromptContent: (content: string) => void;
+ currentPromptEdit: { name: string; id: string; type: string };
+ handleAddPrompt?: () => void;
+ handleEditPrompt?: (id: string, type: string) => void;
+}) {
+ let view;
+
+ if (type === 'ADD') {
+ view = (
+
+ );
+ } else if (type === 'EDIT') {
+ view = (
+
+ );
+ } else {
+ view = <>>;
+ }
+ return (
+
+
+ {view}
+
+
+ );
+}
diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx
index 45fc4e1a..15ae206b 100644
--- a/frontend/src/upload/Upload.tsx
+++ b/frontend/src/upload/Upload.tsx
@@ -307,6 +307,8 @@ export default function Upload({
onSelect={(value: { label: string; value: string }) =>
setUrlType(value)
}
+ size="w-full"
+ rounded="3xl"
/>
{urlType.label !== 'Reddit' ? (
<>