Compare commits

..

10 Commits

Author SHA1 Message Date
9c0ea56058 feat: add .env 2023-09-22 16:37:48 +08:00
dfba42c021 Merge pull request #27 from langgenius/feat/support-paragraph-type
feat: support var type paragraph
2023-09-12 10:45:23 +08:00
a01fc9ef49 feat: support var type paragraph 2023-09-12 10:42:57 +08:00
bed53e4ad2 Merge pull request #26 from langgenius/feat/support-setting-app-api-use-env
feat: support setting app api use env
2023-09-07 17:36:29 +08:00
3838537a42 feat: support setting app api use env 2023-09-07 17:34:10 +08:00
8f3dcd5462 Merge pull request #18 from npm-ued/main
set env variable
2023-08-31 16:46:39 +08:00
2a5a282519 Merge pull request #24 from langgenius/fix/the-2th-not-set-inputs
fix: new chat not set input
2023-08-29 13:43:50 +08:00
eeb54bc820 Merge pull request #23 from langgenius/fix/conversations-cache
fix: conversations cache
2023-08-29 12:27:36 +08:00
4867d52b8f fix: conversations cache 2023-08-29 12:24:46 +08:00
bd0b742247 set env variable
set env variable
2023-08-09 18:27:16 +08:00
8 changed files with 59 additions and 30 deletions

6
.env.example Normal file
View File

@ -0,0 +1,6 @@
# APP ID
NEXT_PUBLIC_APP_ID=
# APP API key
NEXT_PUBLIC_APP_KEY=
# API url prefix
NEXT_PUBLIC_API_URL=

3
.gitignore vendored
View File

@ -28,6 +28,7 @@ yarn-error.log*
# local env files # local env files
.env*.local .env*.local
.env
# vercel # vercel
.vercel .vercel
@ -47,4 +48,4 @@ yarn.lock
.yarnrc.yml .yarnrc.yml
# pmpm # pmpm
pnpm-lock.yaml pnpm-lock.yaml

View File

@ -2,18 +2,22 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Config App ## Config App
Config app in `config/index.ts`.Please config: Create a file named `.env.local` in the current directory and copy the contents from `.env.example`. Setting the following content:
- APP_ID ```
- API_KEY # APP ID
NEXT_PUBLIC_APP_ID=
# APP API key
NEXT_PUBLIC_APP_KEY=
```
More config: Config more in `config/index.ts` file:
```js ```js
export const APP_INFO: AppInfo = { export const APP_INFO: AppInfo = {
"title": 'Chat APP', title: 'Chat APP',
"description": '', description: '',
"copyright": '', copyright: '',
"privacy_policy": '', privacy_policy: '',
"default_language": 'zh-Hans' default_language: 'zh-Hans'
} }
export const isShowPrompt = true export const isShowPrompt = true

View File

@ -1,3 +1,5 @@
export const dynamic = 'force-dynamic'
import { type NextRequest } from 'next/server' import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
import { client, getInfo, setSession } from '@/app/api/utils/common' import { client, getInfo, setSession } from '@/app/api/utils/common'

View File

@ -92,10 +92,10 @@ const Welcome: FC<IWelcomeProps> = ({
return ( return (
<div className='space-y-3'> <div className='space-y-3'>
{promptConfig.prompt_variables.map(item => ( {promptConfig.prompt_variables.map(item => (
<div className='tablet:flex tablet:!h-9 mobile:space-y-2 tablet:space-y-0 mobile:text-xs tablet:text-sm' key={item.key}> <div className='tablet:flex items-start mobile:space-y-2 tablet:space-y-0 mobile:text-xs tablet:text-sm' key={item.key}>
<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> <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>
{item.type === 'select' {item.type === 'select'
? ( && (
<Select <Select
className='w-full' className='w-full'
defaultValue={inputs?.[item.key]} defaultValue={inputs?.[item.key]}
@ -104,16 +104,24 @@ const Welcome: FC<IWelcomeProps> = ({
allowSearch={false} allowSearch={false}
bgClassName='bg-gray-50' bgClassName='bg-gray-50'
/> />
)
: (
<input
placeholder={item.name}
value={inputs?.[item.key] || ''}
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
className={'w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50'}
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
/>
)} )}
{item.type === 'string' && (
<input
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
value={inputs?.[item.key] || ''}
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
className={'w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50'}
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
/>
)}
{item.type === 'paragraph' && (
<textarea
className="w-full h-[104px] flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50"
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
value={inputs?.[item.key] || ''}
onChange={(e) => { setInputs({ ...inputs, [item.key]: e.target.value }) }}
/>
)}
</div> </div>
))} ))}
</div> </div>

View File

@ -1,7 +1,7 @@
import type { AppInfo } from '@/types/app' import type { AppInfo } from '@/types/app'
export const APP_ID = '' export const APP_ID = `${process.env.NEXT_PUBLIC_APP_ID}`
export const API_KEY = '' export const API_KEY = `${process.env.NEXT_PUBLIC_APP_KEY}`
export const API_URL = '' export const API_URL = `${process.env.NEXT_PUBLIC_API_URL}`
export const APP_INFO: AppInfo = { export const APP_INFO: AppInfo = {
title: 'Chat APP', title: 'Chat APP',
description: '', description: '',

View File

@ -3,7 +3,7 @@ import type { Locale } from '@/i18n'
export type PromptVariable = { export type PromptVariable = {
key: string key: string
name: string name: string
type: 'string' | 'number' | 'select' type: string
default?: string | number default?: string | number
options?: string[] options?: string[]
max_length?: number max_length?: number

View File

@ -16,14 +16,22 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
return [] return []
const promptVariables: PromptVariable[] = [] const promptVariables: PromptVariable[] = []
useInputs.forEach((item: any) => { useInputs.forEach((item: any) => {
const type = item['text-input'] ? 'string' : 'select' const isParagraph = !!item.paragraph
const content = type === 'string' ? item['text-input'] : item.select const [type, content] = (() => {
if (type === 'string') { if (isParagraph)
return ['paragraph', item.paragraph]
if (item['text-input'])
return ['string', item['text-input']]
return ['select', item.select]
})()
if (type === 'string' || type === 'paragraph') {
promptVariables.push({ promptVariables.push({
key: content.variable, key: content.variable,
name: content.label, name: content.label,
required: content.required, required: content.required,
type: 'string', type,
max_length: content.max_length, max_length: content.max_length,
options: [], options: [],
}) })