-added manage system prompt per workspace

This commit is contained in:
sherifButt 2024-03-26 12:43:45 +00:00
parent d1eb389f23
commit 17c089c3fb
7 changed files with 195 additions and 16 deletions

View File

@ -27,7 +27,6 @@ const inputComponents = {
const MetaInputs = ({
inputs,
isMetaInputs,
submit,
setMessage,
workspace,
@ -51,9 +50,7 @@ const MetaInputs = ({
// Condition to show the dynamic input or the forced text input
const shouldShowMetaInputs =
workspace?.metaResponse && inputs !== undefined && !isForcedTextInput
workspace?.metaResponse && inputs !== undefined && !isForcedTextInput;
return (
<div className="w-full md:px-4 fixed md:absolute bottom-10 left-0 z-10 md:z-0 flex justify-center items-center">

View File

@ -15,9 +15,9 @@ export default function ChatEnableMetaResponse({ workspace, setHasChanges }) {
}
onToggle={toggleMetaResponse}
name="metaResponse"
description="Turn on this feature to dynamically adjust the chat interface based on conversation context, using options like dropdowns, sliders, and suggestions for a tailored user experience."
// badge
// badgeLabel="New"
description="Turn on this feature to dynamically adjust the chat interface based on conversation context, using options like dropdowns, sliders, and suggestions for a tailored user experience. For Better experience, use GPT-4 or any advanced LLM model."
badge
badgeLabel="New"
// badgeAnimated
/>
</div>

View File

@ -9,7 +9,9 @@ export default function EnableSystemPrompt({
}) {
const [isEnabled, setIsEnabled] = useState(
settings.config.systemPrompt.isEnabled ||
settings.config.systemPrompt.content !== ""
settings.config.systemPrompt.list[
settings.config.systemPrompt.active
].content
);
const toggleSystemPrompt = () => {
@ -47,6 +49,9 @@ export default function EnableSystemPrompt({
description="Specify the context and instructions for the AI in this workspace. A well-defined prompt ensures the AI delivers relevant and precise responses."
inline
content={content}
disabled={settings.config.systemPrompt.list[
settings.config.systemPrompt.active
].content}
/>
</div>
);

View File

@ -20,10 +20,12 @@ export default function FeatureSettings({
settings={settings}
onUpdateSettings={onUpdateSettings}
/>
{settings.config.systemPrompt.content !== "" ||
{settings.config.systemPrompt.list[
settings.config.systemPrompt.active
].content ||
settings.config.systemPrompt.isEnabled ? (
<div className="flex flex-col gap-2">
<TextAreaBlock
{/* <TextAreaBlock
workspace={workspace}
name="systemPrompt"
value={settings.config.systemPrompt.content}
@ -41,7 +43,175 @@ export default function FeatureSettings({
}}
code
initialRows={6}
/>
/> */}
<div>
<div className=" flex gap-1 -mb-1 mt-4 flex-wrap items-center">
{settings.config.systemPrompt.list.map((item, index) => (
<Badge
key={`schema_${index}`}
showClose
size="md"
rounded="md"
label={`${item?.title}`}
active={settings.config.systemPrompt.active === index}
onSelect={
// fill systemPrompt.active with index of selected item
(e) => {
e.stopPropagation();
console.log("selected item", item);
onUpdateSettings({
...settings,
config: {
...settings.config,
systemPrompt: {
...settings.config.systemPrompt,
active: index,
},
},
});
showToast(
`Schema ${item.title} has been selected`,
"success",
{ clear: true }
);
}
}
onDoubleClick={() => {
// rename item
console.log("renaming item", item);
const newSchemas = settings.config.systemPrompt.list.map(
(s, i) => {
if (i === index) {
return {
...s,
title:
prompt("Enter new item title", s.title) ||
s.title,
};
}
return s;
}
);
console.log("New item", newSchemas);
onUpdateSettings({
...settings,
config: {
...settings.config,
systemPrompt: {
...settings.config.systemPrompt,
list: newSchemas,
},
},
});
}}
onClose={(e) => {
e.stopPropagation();
if (settings.config.systemPrompt.list.length === 1) {
showToast("Cannot remove last schema", "error", {
clear: true,
});
return;
}
const newSchemas =
settings.config.systemPrompt.list.filter(
(_, i) => i !== index
);
const active = settings.config.systemPrompt.active;
const newActive = active === index ? active - 1 : active;
onUpdateSettings({
...settings,
config: {
...settings.config,
systemPrompt: {
...settings.config.systemPrompt,
list: newSchemas,
active: newActive,
},
},
});
showToast(
`Schema ${item.title} has been removed`,
"success",
{
clear: true,
}
);
}}
/>
))}
<Button
text="+"
onClick={() => {
const newSchema = {
title: prompt("Enter new item title"),
content: "",
};
// if cancel is clicked
if (!newSchema.title) return;
const newSchemas = [
...settings.config.systemPrompt.list,
newSchema,
];
onUpdateSettings({
...settings,
config: {
...settings.config,
systemPrompt: {
...settings.config.systemPrompt,
list: newSchemas,
active: newSchemas.length - 1,
},
},
});
showToast(
`Schema ${newSchema.title} has been added`,
"success",
{
clear: true,
}
);
}}
/>
</div>
<TextArea
name="openAiPrompt"
value={
// use value instead of defaultValue
settings.config.systemPrompt.list[
settings.config.systemPrompt.active
].content
}
placeholder="Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed."
onSave={
// fill systemPrompt.list[active].content with new content
(newContent) => {
const newSchemas = settings.config.systemPrompt.list.map(
(item, idx) => {
if (idx === settings.config.systemPrompt.active) {
return {
...item,
content: newContent,
};
}
return item;
}
);
onUpdateSettings({
...settings,
config: {
...settings.config,
systemPrompt: {
...settings.config.systemPrompt,
list: newSchemas,
},
},
});
}
}
code
initialRows={6}
/>
</div>
</div>
) : null}
</div>

View File

@ -108,7 +108,9 @@ export default function MetaResponseSettings({ workspace, setWorkspace }) {
Object.keys(settings).map((feature) => {
const featureSettings = settings[feature];
if (featureSettings.isEnabled) {
openAiPrompt += featureSettings.config.systemPrompt.content;
openAiPrompt += featureSettings.config.systemPrompt.list[
featureSettings.config.systemPrompt.active
].content;
openAiPrompt +=
featureSettings.config.promptSchema.list[
featureSettings.config.promptSchema.active

View File

@ -101,7 +101,7 @@ function workspaceEndpoints(app) {
WorkspaceMetaResponse.defaultSystemPrompt;
Object.keys(metaResponseDefaultSettings).map((feature) => {
metaResponseDefaultSettings[feature].config.systemPrompt.content = currentSystemPrompt;
metaResponseDefaultSettings[feature].config.promptSchema.list[0] = {
metaResponseDefaultSettings[feature].config.systemPrompt.list[0] = {
title: "Default",
content: currentSystemPrompt,
}

View File

@ -80,6 +80,10 @@ const WorkspaceMetaResponse = {
title: "Default",
content: "",
},
{
title: "Sequence Example",
content:"### Interaction Sequence\n1. if list is not provided, ask the user to provide a list, be helpful by providing some suggestions to start with, ask user to chose one, or just click \"use Keyboard input\" to type any other list.\n return: options of 4 best lists in full markdown, associated with json options of dispayType buttons in json object\n3. complement the user about his choice and proceed by presenting the list items, ask user to chose one, or just click \"use Keyboard input\" to type any other item if they has one in mind.\n return: options of 4 items in full markdown, associated with json options of dispayType buttons in json object\n4. Provide information about the item, break down the information to options.\n return: information about the item in full markdown add simplified comparison table with closest item add as well fun fact, associated with break down of the information to list of options, displayType checkbox with sub-label \"I can break down this information further\".\n1. Provide information about what they asked.\n Return: information in full markdown, references, and simplified example if possible, a mermaid chart for illustration. associated with two options ether to dig deeper where you will go back to step 5, or start over where you will go back to step 1, displayType dropdown with sub-label \"would you like top know more...\", \n3. give user a 1. Dig deeper or 2. switch to a new topic, options.\n return: give user 2 options ether to displayType dropdown with sub-label \"would you like top know more...\", ask the user if they want to know about something else then go to Next step 1, or dig deeper about [topic], so go to step 3.\n ",
}
],
canEdit: ["admin", "manager"],
},
@ -91,7 +95,7 @@ const WorkspaceMetaResponse = {
content: "## Prompt Guidelines\n- you are a helpful assistant, you will be provided a question to create a list of four elements\n- when requested to return structured data return them in a JSON object code block , don't introduce them or label them, just return them at the end of your response.\n- When presenting choices or detailed information, encapsulate the data in JSON format, aiming for a user-friendly interaction through:\n\t- type options: you will use this if options are a better way to seak users interaction, include displayTypess: buttons, list,checkbox, or dropdown based on the context.\n\t- type range: you will use this if the user is required to input a numeric between a certain range.\n\t- type rating: you will use this if the user should insert a rating, uswaly between one and five.\n\t- type date: you will use this if the user should insert a date.\n- if asked to return options return them as structured data, only when asked.\n- always return response as normal in markdown first then associate the data structure object below.\n- make your response rich in markdown.\n- if you find that your response at any time contain options follow the instructions above.\n- Important follow strictly the json schema examples provided below\n---\n### Response Example\n#### Discover More\n**Fascinating Topic**\nExplore intriguing facts and details about your chosen subject, enhancing your understanding and curiosity.\n\n```json\n{\n \"inputs\": {\n \"type\": \"options\",\n \"data\": {\n \"options\": [\n {\n \"label\": \"Restart Router\",\n \"value\": \"restart router\"\n },\n {\n \"label\": \"Check Service Status\",\n \"value\": \"check service status\"\n },\n ... \n ],\n \"label\":\"Select Server \",\n \"description\":\"list of servers as described\"\n \n },\n \"settings\": {\n \"allowMultiple\": false,\n \"displayType\": \"chose one, buttons/list/dropdown\"\n }\n },\n \"sentiment\": \"happy\",\n \"style\": \"text\"\n}\n```\n\ninput types:\n```json\n{\n \"inputs\": {\n \"type\":\"options\",\n \"data\":{\n \"options\":[\n {\n \"label\":\"Restart Router\",\n \"value\":\"restart_router\"\n },\n {\n \"label\":\"Check Service Status\",\n \"value\":\"check_service_status\"\n },\n {\n \"label\":\"Contact Support\",\n \"value\":\"contact_support\"\n }\n ]\n },\n \"settings\":{\n \"allowMultiple\":false,\n \"displayType\":\"buttons\"\n }\n }\n}\n```\n\n```json\n{\n \"inputs\": {\n \"type\":\"range\",\n \"data\":{\n \"min\":1,\n \"max\":10,\n \"step\":1\n },\n \"settings\":{\n \"showValue\":true\n }\n }\n}\n```\n\n```json\n{\n\"inputs\": {\n \"type\":\"rating\",\n \"data\":{\n \"max\":5,\n \"defaultValue\":3,\n \"icon\":\"star\"\n }\n }\n}\n```\n\n```json\n{\n\"inputs\": {\n \"type\":\"date\",\n \"settings\":{\n \"format\":\"YYYY-MM-DD\",\n \"minDate\":\"2021-01-01\",\n \"maxDate\":\"2023-12-31\"\n }\n}\n}\n```\n---\n",
},
{
title: "Suggestions Buttons Type",
title: "Suggestions Buttons",
content: "## Prompt Guidelines Suggestions Buttons Type\n- you are a helpful assistant, you will be provided a question to create a list of four elements\n- when requested to return structured data return them in a JSON object code block , don't introduce them or label them, just return them at the end of your response.\n- When presenting choices or detailed information, encapsulate the data in JSON format, aiming for a user-friendly interaction through:\n\t- type options: you will use this if options are a better way to seak users interaction, include displayTypess: buttons, list,checkbox, or dropdown based on the context.\n\t- type range: you will use this if the user is required to input a numeric between a certain range.\n\t- type rating: you will use this if the user should insert a rating, uswaly between one and five.\n\t- type date: you will use this if the user should insert a date.\n- if asked to return options return them as structured data, only when asked.\n- always return response as normal in markdown first then associate the data structure object below.\n- make your response rich in markdown.\n- if you find that your response at any time contain options follow the instructions above.\n- Important follow strictly the json schema examples provided below\n---\n### Response Example\n#### Discover More\n**Fascinating Topic**\nExplore intriguing facts and details about your chosen subject, enhancing your understanding and curiosity.\n\n```json\n{\n \"inputs\": {\n \"type\": \"options\",\n \"data\": {\n \"options\": [\n {\n \"label\": \"Restart Router\",\n \"value\": \"restart router\"\n },\n {\n \"label\": \"Check Service Status\",\n \"value\": \"check service status\"\n },\n ... \n ],\n \"label\":\"Select Server \",\n \"description\":\"list of servers as described\"\n \n },\n \"settings\": {\n \"allowMultiple\": false,\n \"displayType\": \"chose one, buttons/list/dropdown\"\n }\n },\n \"sentiment\": \"happy\",\n \"style\": \"text\"\n}\n```",
},
],
@ -133,7 +137,8 @@ const WorkspaceMetaResponse = {
description: "Traditionally, interaction with AnythingLLM occurs through a text area. Meta Inputs enhance this by offering alternative interaction methods, including option buttons, multi-select checkboxes, sliders, drop-down menus, and date/time selectors. To utilize these components, you'll need to guide the LLM on incorporating them into its responses with a specific schema",
infoLink: "https://docs.anythingllm.com/docs/meta-response/inputs",
},
sentiments: {
// Example of adding more meta response settings
/* sentiments: {
isEnabled: false,
config: {
systemPrompt: {
@ -266,7 +271,7 @@ const WorkspaceMetaResponse = {
permissions: ["user"],
description: "Enable avatars to reflect user sentiments, allowing the AI to visually empathize and convey understanding through changes in its profile image based on the meta object's sentiment data.",
infoLink: "https://docs.anythingllm.com/docs/meta-response/avatars",
},
},*/
},
};