Skip to content

Commit dfba42c

Browse files
authored
Merge pull request langgenius#27 from langgenius/feat/support-paragraph-type
feat: support var type paragraph
2 parents bed53e4 + a01fc9e commit dfba42c

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

app/components/welcome/index.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ const Welcome: FC<IWelcomeProps> = ({
9292
return (
9393
<div className='space-y-3'>
9494
{promptConfig.prompt_variables.map(item => (
95-
<div className='tablet:flex tablet:!h-9 mobile:space-y-2 tablet:space-y-0 mobile:text-xs tablet:text-sm' key={item.key}>
96-
<label className={`flex-shrink-0 flex items-center mobile:text-gray-700 tablet:text-gray-900 mobile:font-medium pc:font-normal ${s.formLabel}`}>{item.name}</label>
95+
<div className='tablet:flex items-start mobile:space-y-2 tablet:space-y-0 mobile:text-xs tablet:text-sm' key={item.key}>
96+
<label className={`flex-shrink-0 flex items-center tablet:leading-9 mobile:text-gray-700 tablet:text-gray-900 mobile:font-medium pc:font-normal ${s.formLabel}`}>{item.name}</label>
9797
{item.type === 'select'
98-
? (
98+
&& (
9999
<Select
100100
className='w-full'
101101
defaultValue={inputs?.[item.key]}
@@ -104,16 +104,24 @@ const Welcome: FC<IWelcomeProps> = ({
104104
allowSearch={false}
105105
bgClassName='bg-gray-50'
106106
/>
107-
)
108-
: (
109-
<input
110-
placeholder={item.name}
111-
value={inputs?.[item.key] || ''}
112-
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
113-
className={'w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50'}
114-
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
115-
/>
116107
)}
108+
{item.type === 'string' && (
109+
<input
110+
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
111+
value={inputs?.[item.key] || ''}
112+
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
113+
className={'w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50'}
114+
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
115+
/>
116+
)}
117+
{item.type === 'paragraph' && (
118+
<textarea
119+
className="w-full h-[104px] flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50"
120+
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
121+
value={inputs?.[item.key] || ''}
122+
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
123+
/>
124+
)}
117125
</div>
118126
))}
119127
</div>

types/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Locale } from '@/i18n'
33
export type PromptVariable = {
44
key: string
55
name: string
6-
type: 'string' | 'number' | 'select'
6+
type: string
77
default?: string | number
88
options?: string[]
99
max_length?: number

utils/prompt.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
1616
return []
1717
const promptVariables: PromptVariable[] = []
1818
useInputs.forEach((item: any) => {
19-
const type = item['text-input'] ? 'string' : 'select'
20-
const content = type === 'string' ? item['text-input'] : item.select
21-
if (type === 'string') {
19+
const isParagraph = !!item.paragraph
20+
const [type, content] = (() => {
21+
if (isParagraph)
22+
return ['paragraph', item.paragraph]
23+
24+
if (item['text-input'])
25+
return ['string', item['text-input']]
26+
27+
return ['select', item.select]
28+
})()
29+
if (type === 'string' || type === 'paragraph') {
2230
promptVariables.push({
2331
key: content.variable,
2432
name: content.label,
2533
required: content.required,
26-
type: 'string',
34+
type,
2735
max_length: content.max_length,
2836
options: [],
2937
})

0 commit comments

Comments
 (0)