mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
feat: chat app struct into installed
This commit is contained in:
parent
4ad1bb7c83
commit
28bf9f0267
@ -1,12 +1,15 @@
|
|||||||
import React, { FC } from 'react'
|
import React, { FC } from 'react'
|
||||||
|
import Main from '@/app/components/explore/installed-app'
|
||||||
|
|
||||||
export interface IInstalledAppProps { }
|
export interface IInstalledAppProps {
|
||||||
|
params: {
|
||||||
|
appId: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const InstalledApp: FC<IInstalledAppProps> = ({ }) => {
|
const InstalledApp: FC<IInstalledAppProps> = ({ params: {appId} }) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Main id={appId} />
|
||||||
InstalledApp
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default React.memo(InstalledApp)
|
export default React.memo(InstalledApp)
|
||||||
|
|||||||
@ -4,12 +4,10 @@ import React from 'react'
|
|||||||
import type { IMainProps } from '@/app/components/share/chat'
|
import type { IMainProps } from '@/app/components/share/chat'
|
||||||
import Main from '@/app/components/share/chat'
|
import Main from '@/app/components/share/chat'
|
||||||
|
|
||||||
const Chat: FC<IMainProps> = ({
|
const Chat: FC<IMainProps> = () => {
|
||||||
params,
|
|
||||||
}: any) => {
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Main params={params} />
|
<Main />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
63
web/app/components/explore/installed-app/index.tsx
Normal file
63
web/app/components/explore/installed-app/index.tsx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
'use client'
|
||||||
|
import React, { FC, useEffect } from 'react'
|
||||||
|
import { App } from '@/types/app'
|
||||||
|
import ChatApp from '@/app/components/share/chat'
|
||||||
|
|
||||||
|
export interface IInstalledAppProps {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const isMock = true
|
||||||
|
const appDetail = {
|
||||||
|
"id": "4dcc2bac-0a48-4633-8e0b-0f4335669335",
|
||||||
|
"name": "Interviewer",
|
||||||
|
"mode": "chat",
|
||||||
|
"icon": null,
|
||||||
|
"icon_background": null,
|
||||||
|
"app_model_config": {
|
||||||
|
"opening_statement": null,
|
||||||
|
"suggested_questions": [],
|
||||||
|
"suggested_questions_after_answer": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"more_like_this": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"provider": "openai",
|
||||||
|
"name": "gpt-3.5-turbo",
|
||||||
|
"completion_params": {
|
||||||
|
"max_tokens": 512,
|
||||||
|
"temperature": 1,
|
||||||
|
"top_p": 1,
|
||||||
|
"presence_penalty": 0,
|
||||||
|
"frequency_penalty": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"user_input_form": [],
|
||||||
|
"pre_prompt": null,
|
||||||
|
"agent_mode": {
|
||||||
|
"enabled": false,
|
||||||
|
"tools": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as any
|
||||||
|
|
||||||
|
const InstalledApp: FC<IInstalledAppProps> = ({
|
||||||
|
id,
|
||||||
|
}) => {
|
||||||
|
const [app, setApp] = React.useState<App | null>(isMock ? appDetail : null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// TODO
|
||||||
|
if(!isMock) {
|
||||||
|
setApp(appDetail)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return (
|
||||||
|
<div className='h-full'>
|
||||||
|
<ChatApp isInstalledApp installedAppInfo={appDetail}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(InstalledApp)
|
||||||
@ -23,16 +23,17 @@ import { replaceStringWithValues } from '@/app/components/app/configuration/prom
|
|||||||
import AppUnavailable from '../../base/app-unavailable'
|
import AppUnavailable from '../../base/app-unavailable'
|
||||||
import { userInputsFormToPromptVariables } from '@/utils/model-config'
|
import { userInputsFormToPromptVariables } from '@/utils/model-config'
|
||||||
import { SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'
|
import { SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'
|
||||||
|
import { App } from '@/types/app'
|
||||||
|
|
||||||
export type IMainProps = {
|
export type IMainProps = {
|
||||||
params: {
|
isInstalledApp?: boolean,
|
||||||
locale: string
|
installedAppInfo? : App
|
||||||
appId: string
|
|
||||||
conversationId: string
|
|
||||||
token: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Main: FC<IMainProps> = () => {
|
const Main: FC<IMainProps> = ({
|
||||||
|
isInstalledApp,
|
||||||
|
installedAppInfo
|
||||||
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const media = useBreakpoints()
|
const media = useBreakpoints()
|
||||||
const isMobile = media === MediaType.mobile
|
const isMobile = media === MediaType.mobile
|
||||||
@ -222,19 +223,39 @@ const Main: FC<IMainProps> = () => {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchInitData = () => {
|
||||||
|
if(isInstalledApp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// TODO: fetchConversations
|
||||||
|
resolve([{
|
||||||
|
app_id: installedAppInfo?.id,
|
||||||
|
site: {
|
||||||
|
title: installedAppInfo?.name,
|
||||||
|
prompt_public: false,
|
||||||
|
copyright: ''
|
||||||
|
},
|
||||||
|
model_config: installedAppInfo?.app_model_config,
|
||||||
|
plan: 'basic',
|
||||||
|
}, {
|
||||||
|
data: []
|
||||||
|
}, installedAppInfo?.app_model_config])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Promise.all([fetchAppInfo(), fetchConversations(), fetchAppParams()])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// init
|
// init
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const [appData, conversationData, appParams] = await Promise.all([fetchAppInfo(), fetchConversations(), fetchAppParams()])
|
const [appData, conversationData, appParams]: any = await fetchInitData()
|
||||||
const { app_id: appId, site: siteInfo, model_config, plan }: any = appData
|
const { app_id: appId, site: siteInfo, model_config, plan }: any = appData
|
||||||
setAppId(appId)
|
setAppId(appId)
|
||||||
setPlan(plan)
|
setPlan(plan)
|
||||||
const tempIsPublicVersion = siteInfo.prompt_public
|
const tempIsPublicVersion = siteInfo.prompt_public
|
||||||
setIsPublicVersion(tempIsPublicVersion)
|
setIsPublicVersion(tempIsPublicVersion)
|
||||||
const prompt_template = tempIsPublicVersion ? model_config.pre_prompt : ''
|
const prompt_template = tempIsPublicVersion ? model_config.pre_prompt : ''
|
||||||
|
|
||||||
// handle current conversation id
|
// handle current conversation id
|
||||||
const { data: conversations } = conversationData as { data: ConversationItem[] }
|
const { data: conversations } = conversationData as { data: ConversationItem[] }
|
||||||
const _conversationId = getConversationIdFromStorage(appId)
|
const _conversationId = getConversationIdFromStorage(appId)
|
||||||
@ -243,7 +264,9 @@ const Main: FC<IMainProps> = () => {
|
|||||||
// fetch new conversation info
|
// fetch new conversation info
|
||||||
const { user_input_form, opening_statement: introduction, suggested_questions_after_answer }: any = appParams
|
const { user_input_form, opening_statement: introduction, suggested_questions_after_answer }: any = appParams
|
||||||
const prompt_variables = userInputsFormToPromptVariables(user_input_form)
|
const prompt_variables = userInputsFormToPromptVariables(user_input_form)
|
||||||
changeLanguage(siteInfo.default_language)
|
if(siteInfo.default_language) {
|
||||||
|
changeLanguage(siteInfo.default_language)
|
||||||
|
}
|
||||||
setNewConversationInfo({
|
setNewConversationInfo({
|
||||||
name: t('share.chat.newChatDefaultName'),
|
name: t('share.chat.newChatDefaultName'),
|
||||||
introduction,
|
introduction,
|
||||||
|
|||||||
@ -204,6 +204,7 @@ export type App = {
|
|||||||
is_demo: boolean
|
is_demo: boolean
|
||||||
/** Model configuration */
|
/** Model configuration */
|
||||||
model_config: ModelConfig
|
model_config: ModelConfig
|
||||||
|
app_model_config: ModelConfig
|
||||||
/** Timestamp of creation */
|
/** Timestamp of creation */
|
||||||
created_at: number
|
created_at: number
|
||||||
/** Web Application Configuration */
|
/** Web Application Configuration */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user