From d3b1708261f167f02d6e5cac365631a8ca3157b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Ferna=CC=81ndez?= Date: Fri, 14 Apr 2023 14:54:08 +0200 Subject: [PATCH 1/3] feat: add role types --- src/services/prompts.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/services/prompts.ts b/src/services/prompts.ts index e1433dc5..b124618b 100644 --- a/src/services/prompts.ts +++ b/src/services/prompts.ts @@ -1,10 +1,12 @@ import Browser from 'webextension-polyfill' import { ofetch } from 'ofetch' +export type PromptRole = 'system' | 'user' export interface Prompt { id: string title: string prompt: string + role: PromptRole } export async function loadLocalPrompts() { @@ -19,6 +21,7 @@ export async function saveLocalPrompt(prompt: Prompt) { if (p.id === prompt.id) { p.title = prompt.title p.prompt = prompt.prompt + p.role = prompt.role existed = true break } From 7594f86132e46e4d839bb53baf151f68f93f12cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Ferna=CC=81ndez?= Date: Fri, 14 Apr 2023 14:54:32 +0200 Subject: [PATCH 2/3] feat: collect role on prompt library --- src/app/components/PromptLibrary/Library.tsx | 30 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app/components/PromptLibrary/Library.tsx b/src/app/components/PromptLibrary/Library.tsx index 241ed666..d901d477 100644 --- a/src/app/components/PromptLibrary/Library.tsx +++ b/src/app/components/PromptLibrary/Library.tsx @@ -1,13 +1,21 @@ -import { Suspense, useCallback, useMemo, useState } from 'react' +import { Suspense, useCallback, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { BeatLoader } from 'react-spinners' import useSWR from 'swr' import closeIcon from '~/assets/icons/close.svg' import { trackEvent } from '~app/plausible' -import { Prompt, loadLocalPrompts, loadRemotePrompts, removeLocalPrompt, saveLocalPrompt } from '~services/prompts' +import { + Prompt, + PromptRole, + loadLocalPrompts, + loadRemotePrompts, + removeLocalPrompt, + saveLocalPrompt, +} from '~services/prompts' import { uuid } from '~utils' import Button from '../Button' import { Input, Textarea } from '../Input' +import Select from '../Select' import Tabs, { Tab } from '../Tabs' const ActionButton = (props: { text: string; onClick: () => void }) => { @@ -58,8 +66,14 @@ const PromptItem = (props: { ) } +const PROMPT_ROLE_OPTIONS = [ + { value: 'user', name: 'User' }, + { value: 'system', name: 'System' }, +] + function PromptForm(props: { initialData: Prompt; onSubmit: (data: Prompt) => void }) { const { t } = useTranslation() + const roleRef = useRef(null) const onSubmit = useCallback( (e: React.FormEvent) => { e.preventDefault() @@ -71,6 +85,7 @@ function PromptForm(props: { initialData: Prompt; onSubmit: (data: Prompt) => vo id: props.initialData.id, title: json.title as string, prompt: json.prompt as string, + role: json.role as PromptRole, }) } }, @@ -82,6 +97,15 @@ function PromptForm(props: { initialData: Prompt; onSubmit: (data: Prompt) => vo Prompt {t('Title')} +
+ Prompt {t('Role')} + + +
Prompt {t('Content')}