Commit 60f6ab03 authored by Joel's avatar Joel

feat: webapp support paragraph

parent cb86a80c
...@@ -8,23 +8,19 @@ import Select from '@/app/components/base/select' ...@@ -8,23 +8,19 @@ import Select from '@/app/components/base/select'
import type { SiteInfo } from '@/models/share' import type { SiteInfo } from '@/models/share'
import type { PromptConfig } from '@/models/debug' import type { PromptConfig } from '@/models/debug'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import { DEFAULT_VALUE_MAX_LEN } from '@/config' import { DEFAULT_PARAGRAPH_VALUE_MAX_LEN, DEFAULT_VALUE_MAX_LEN } from '@/config'
export type IConfigSenceProps = { export type IConfigSenceProps = {
siteInfo: SiteInfo siteInfo: SiteInfo
promptConfig: PromptConfig promptConfig: PromptConfig
inputs: Record<string, any> inputs: Record<string, any>
onInputsChange: (inputs: Record<string, any>) => void onInputsChange: (inputs: Record<string, any>) => void
query: string
onQueryChange: (query: string) => void
onSend: () => void onSend: () => void
} }
const ConfigSence: FC<IConfigSenceProps> = ({ const ConfigSence: FC<IConfigSenceProps> = ({
promptConfig, promptConfig,
inputs, inputs,
onInputsChange, onInputsChange,
query,
onQueryChange,
onSend, onSend,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
...@@ -38,61 +34,59 @@ const ConfigSence: FC<IConfigSenceProps> = ({ ...@@ -38,61 +34,59 @@ const ConfigSence: FC<IConfigSenceProps> = ({
<div className='w-full mt-4' key={item.key}> <div className='w-full mt-4' key={item.key}>
<label className='text-gray-900 text-sm font-medium'>{item.name}</label> <label className='text-gray-900 text-sm font-medium'>{item.name}</label>
<div className='mt-2'> <div className='mt-2'>
{item.type === 'select' {item.type === 'select' && (
? ( <Select
<Select className='w-full'
className='w-full' defaultValue={inputs[item.key]}
defaultValue={inputs[item.key]} onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }}
onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }} items={(item.options || []).map(i => ({ name: i, value: i }))}
items={(item.options || []).map(i => ({ name: i, value: i }))} allowSearch={false}
allowSearch={false} bgClassName='bg-gray-50'
bgClassName='bg-gray-50' />
/> )}
) {item.type === 'string' && (
: ( <input
<input type="text"
type="text" className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 "
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 " placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} value={inputs[item.key]}
value={inputs[item.key]} onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} />
/> )}
)} {item.type === 'paragraph' && (
<textarea
className="block w-full h-[104px] p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 "
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
value={inputs[item.key]}
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
maxLength={item.max_length || DEFAULT_PARAGRAPH_VALUE_MAX_LEN}
/>
)}
</div> </div>
</div> </div>
))} ))}
{promptConfig.prompt_variables.length > 0 && ( {promptConfig.prompt_variables.length > 0 && (
<div className='mt-6 h-[1px] bg-gray-100'></div> <div className='mt-4 h-[1px] bg-gray-100'></div>
)} )}
<div className='w-full mt-5'> <div className='w-full mt-4'>
<label className='text-gray-900 text-sm font-medium'>{t('share.generation.queryTitle')}</label> <div className="flex items-center justify-between">
<div className="mt-2 overflow-hidden rounded-lg bg-gray-50 "> <Button
<div className="px-4 py-2 bg-gray-50 rounded-t-lg"> className='w-[58px] !h-8 !p-3'
<textarea onClick={onSend}
value={query} disabled={false}
onChange={(e) => { onQueryChange(e.target.value) }} >
rows={4} <span className='text-[13px]'>{t('common.operation.clear')}</span>
className="w-full px-0 text-sm text-gray-900 border-0 bg-gray-50 focus:outline-none placeholder:bg-gray-50" </Button>
placeholder={t('share.generation.queryPlaceholder') as string} <Button
required type="primary"
> className='!h-8 !pl-3 !pr-4'
</textarea> onClick={onSend}
</div> disabled={false}
<div className="flex items-center justify-between px-3 py-2"> >
<div className="flex pl-0 space-x-1 sm:pl-2"> <PlayIcon className="shrink-0 w-4 h-4 mr-1" aria-hidden="true" />
<span className="bg-gray-100 text-gray-500 text-xs font-medium mr-2 px-2.5 py-0.5 rounded cursor-pointer">{query?.length}</span> <span className='text-[13px]'>{t('share.generation.run')}</span>
</div> </Button>
<Button
type="primary"
className='w-[80px] !h-8 !p-0'
onClick={onSend}
disabled={!query || query === ''}
>
<PlayIcon className="shrink-0 w-4 h-4 mr-1" aria-hidden="true" />
<span className='uppercase text-[13px]'>{t('share.generation.run')}</span>
</Button>
</div>
</div> </div>
</div> </div>
</form> </form>
......
...@@ -49,7 +49,6 @@ const TextGeneration: FC<IMainProps> = ({ ...@@ -49,7 +49,6 @@ const TextGeneration: FC<IMainProps> = ({
const [promptConfig, setPromptConfig] = useState<PromptConfig | null>(null) const [promptConfig, setPromptConfig] = useState<PromptConfig | null>(null)
const [moreLikeThisConfig, setMoreLikeThisConfig] = useState<MoreLikeThisConfig | null>(null) const [moreLikeThisConfig, setMoreLikeThisConfig] = useState<MoreLikeThisConfig | null>(null)
const [isResponsing, { setTrue: setResponsingTrue, setFalse: setResponsingFalse }] = useBoolean(false) const [isResponsing, { setTrue: setResponsingTrue, setFalse: setResponsingFalse }] = useBoolean(false)
const [query, setQuery] = useState('')
const [completionRes, setCompletionRes] = useState('') const [completionRes, setCompletionRes] = useState('')
const { notify } = Toast const { notify } = Toast
const isNoData = !completionRes const isNoData = !completionRes
...@@ -125,14 +124,8 @@ const TextGeneration: FC<IMainProps> = ({ ...@@ -125,14 +124,8 @@ const TextGeneration: FC<IMainProps> = ({
if (!checkCanSend()) if (!checkCanSend())
return return
if (!query) {
logError(t('appDebug.errorMessage.queryRequired'))
return false
}
const data = { const data = {
inputs, inputs,
query,
} }
setMessageId(null) setMessageId(null)
...@@ -188,7 +181,11 @@ const TextGeneration: FC<IMainProps> = ({ ...@@ -188,7 +181,11 @@ const TextGeneration: FC<IMainProps> = ({
changeLanguage(siteInfo.default_language) changeLanguage(siteInfo.default_language)
const { user_input_form, more_like_this }: any = appParams const { user_input_form, more_like_this }: any = appParams
const prompt_variables = userInputsFormToPromptVariables(user_input_form) // TODO: test paragraph type
const prompt_variables = userInputsFormToPromptVariables(user_input_form).map(item => ({
...item,
type: 'paragraph',
}))
setPromptConfig({ setPromptConfig({
prompt_template: '', // placeholder for feture prompt_template: '', // placeholder for feture
prompt_variables, prompt_variables,
...@@ -331,8 +328,6 @@ const TextGeneration: FC<IMainProps> = ({ ...@@ -331,8 +328,6 @@ const TextGeneration: FC<IMainProps> = ({
inputs={inputs} inputs={inputs}
onInputsChange={setInputs} onInputsChange={setInputs}
promptConfig={promptConfig} promptConfig={promptConfig}
query={query}
onQueryChange={setQuery}
onSend={handleSend} onSend={handleSend}
/> />
)} )}
......
const translation = { const translation = {
common: { common: {
welcome: "Welcome to use", welcome: 'Welcome to use',
appUnavailable: "App is unavailable", appUnavailable: 'App is unavailable',
appUnkonwError: "App is unavailable" appUnkonwError: 'App is unavailable',
}, },
chat: { chat: {
newChat: "New chat", newChat: 'New chat',
newChatDefaultName: "New conversation", newChatDefaultName: 'New conversation',
powerBy: "Powered by", powerBy: 'Powered by',
prompt: "Prompt", prompt: 'Prompt',
privatePromptConfigTitle: "Conversation settings", privatePromptConfigTitle: 'Conversation settings',
publicPromptConfigTitle: "Initial Prompt", publicPromptConfigTitle: 'Initial Prompt',
configStatusDes: "Before start, you can modify conversation settings", configStatusDes: 'Before start, you can modify conversation settings',
configDisabled: configDisabled:
"Previous session settings have been used for this session.", 'Previous session settings have been used for this session.',
startChat: "Start Chat", startChat: 'Start Chat',
privacyPolicyLeft: privacyPolicyLeft:
"Please read the ", 'Please read the ',
privacyPolicyMiddle: privacyPolicyMiddle:
"privacy policy", 'privacy policy',
privacyPolicyRight: privacyPolicyRight:
" provided by the app developer.", ' provided by the app developer.',
}, },
generation: { generation: {
tabs: { tabs: {
create: "Create", create: 'Create',
saved: "Saved", saved: 'Saved',
}, },
savedNoData: { savedNoData: {
title: "You haven't saved a result yet!", title: 'You haven\'t saved a result yet!',
description: 'Start generating content, and find your saved results here.', description: 'Start generating content, and find your saved results here.',
startCreateContent: 'Start create content' startCreateContent: 'Start create content',
}, },
title: "AI Completion", title: 'AI Completion',
queryTitle: "Query content", queryTitle: 'Query content',
queryPlaceholder: "Write your query content...", queryPlaceholder: 'Write your query content...',
run: "RUN", run: 'Execute',
copy: "Copy", copy: 'Copy',
resultTitle: "AI Completion", resultTitle: 'AI Completion',
noData: "AI will give you what you want here.", noData: 'AI will give you what you want here.',
}, },
}; }
export default translation; export default translation
const translation = { const translation = {
common: { common: {
welcome: "欢迎使用", welcome: '欢迎使用',
appUnavailable: "应用不可用", appUnavailable: '应用不可用',
appUnkonwError: "应用不可用", appUnkonwError: '应用不可用',
}, },
chat: { chat: {
newChat: "新对话", newChat: '新对话',
newChatDefaultName: "新的对话", newChatDefaultName: '新的对话',
powerBy: "Powered by", powerBy: 'Powered by',
prompt: "提示词", prompt: '提示词',
privatePromptConfigTitle: "对话设置", privatePromptConfigTitle: '对话设置',
publicPromptConfigTitle: "对话前提示词", publicPromptConfigTitle: '对话前提示词',
configStatusDes: "开始前,您可以修改对话设置", configStatusDes: '开始前,您可以修改对话设置',
configDisabled: "此次会话已使用上次会话表单", configDisabled: '此次会话已使用上次会话表单',
startChat: "开始对话", startChat: '开始对话',
privacyPolicyLeft: "请阅读由该应用开发者提供的", privacyPolicyLeft: '请阅读由该应用开发者提供的',
privacyPolicyMiddle: "隐私政策", privacyPolicyMiddle: '隐私政策',
privacyPolicyRight: "。", privacyPolicyRight: '。',
}, },
generation: { generation: {
tabs: { tabs: {
create: "创建", create: '创建',
saved: "已保存", saved: '已保存',
}, },
savedNoData: { savedNoData: {
title: "您还没有保存结果!", title: '您还没有保存结果!',
description: '开始生成内容,您可以在这里找到保存的结果。', description: '开始生成内容,您可以在这里找到保存的结果。',
startCreateContent: '开始生成内容' startCreateContent: '开始生成内容',
}, },
title: "AI 智能书写", title: 'AI 智能书写',
queryTitle: "查询内容", queryTitle: '查询内容',
queryPlaceholder: "请输入文本内容", queryPlaceholder: '请输入文本内容',
run: "运行", run: '运行',
copy: "拷贝", copy: '拷贝',
resultTitle: "AI 书写", resultTitle: 'AI 书写',
noData: "AI 会在这里给你惊喜。", noData: 'AI 会在这里给你惊喜。',
}, },
}; }
export default translation; export default translation
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment