langgenius / webapp-text-generator

MIT License
128 stars 347 forks source link

500 Error when workflow uses a number variable #27

Closed sonicviz closed 2 months ago

sonicviz commented 2 months ago

ref: https://discord.com/channels/1082486657678311454/1269851206180929566

If you have an input field of type number image your API will result in a 500 error when trying to parse it image

This is because the code only parses string, select, and paragraph type inputs.

Solution is two parts.

if (item['number']) return ['number', item['number']]

  return ['select', item.select]
})()

- 2  app\components\run-once\index.tsx
Add input of type number here
      {promptConfig.prompt_variables.map(item => (
        <div className='w-full mt-4' key={item.key}>
          <label className='text-gray-900 text-sm font-medium'>{item.name}</label>
          <div className='mt-2'>
            {item.type === 'select' && (
              <Select
                className='w-full'
                defaultValue={inputs[item.key]}
                onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }}
                items={(item.options || []).map(i => ({ name: i, value: i }))}
                allowSearch={false}
                bgClassName='bg-gray-50'
              />
            )}
            {item.type === 'string' && (
              <input
                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 "
                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_VALUE_MAX_LEN}
              />
            )}
            {item.type === 'number' && (
              <input
                type="number"
                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')})` : ''}`}
                value={inputs[item.key]}
                onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
              />
            )}
            {item.type === 'paragraph' && (
iamjoel commented 2 months ago

Fixed by https://github.com/langgenius/webapp-text-generator/pull/28