Initial commit
This commit is contained in:
27
web/context/app-context.ts
Normal file
27
web/context/app-context.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import type { App } from '@/types/app'
|
||||
import type { UserProfileResponse } from '@/models/common'
|
||||
|
||||
export type AppContextValue = {
|
||||
apps: App[]
|
||||
mutateApps: () => void
|
||||
userProfile: UserProfileResponse
|
||||
mutateUserProfile: () => void
|
||||
}
|
||||
|
||||
const AppContext = createContext<AppContextValue>({
|
||||
apps: [],
|
||||
mutateApps: () => { },
|
||||
userProfile: {
|
||||
id: '',
|
||||
name: '',
|
||||
email: '',
|
||||
},
|
||||
mutateUserProfile: () => { },
|
||||
})
|
||||
|
||||
export const useAppContext = () => useContext(AppContext)
|
||||
|
||||
export default AppContext
|
5
web/context/dataset-detail.ts
Normal file
5
web/context/dataset-detail.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createContext } from 'use-context-selector'
|
||||
|
||||
const DatasetDetailContext = createContext<{ indexingTechnique?: string; }>({})
|
||||
|
||||
export default DatasetDetailContext
|
20
web/context/datasets-context.tsx
Normal file
20
web/context/datasets-context.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import type { DataSet } from '@/models/datasets'
|
||||
|
||||
export type DatasetsContextValue = {
|
||||
datasets: DataSet[]
|
||||
mutateDatasets: () => void
|
||||
currentDataset?: DataSet
|
||||
}
|
||||
|
||||
const DatasetsContext = createContext<DatasetsContextValue>({
|
||||
datasets: [],
|
||||
mutateDatasets: () => {},
|
||||
currentDataset: undefined
|
||||
})
|
||||
|
||||
export const useDatasetsContext = () => useContext(DatasetsContext)
|
||||
|
||||
export default DatasetsContext
|
89
web/context/debug-configuration.ts
Normal file
89
web/context/debug-configuration.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { createContext } from 'use-context-selector'
|
||||
import type { CompletionParams, Inputs, ModelConfig, PromptConfig, MoreLikeThisConfig, SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'
|
||||
import type { DataSet } from '@/models/datasets'
|
||||
|
||||
type IDebugConfiguration = {
|
||||
appId: string
|
||||
hasSetAPIKEY: boolean
|
||||
isTrailFinished: boolean
|
||||
mode: string
|
||||
conversationId: string | null // after first chat send
|
||||
setConversationId: (conversationId: string | null) => void
|
||||
introduction: string
|
||||
setIntroduction: (introduction: string) => void
|
||||
controlClearChatMessage: number
|
||||
setControlClearChatMessage: (controlClearChatMessage: number) => void
|
||||
prevPromptConfig: PromptConfig
|
||||
setPrevPromptConfig: (prevPromptConfig: PromptConfig) => void
|
||||
moreLikeThisConifg: MoreLikeThisConfig,
|
||||
setMoreLikeThisConifg: (moreLikeThisConfig: MoreLikeThisConfig) => void
|
||||
suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig,
|
||||
setSuggestedQuestionsAfterAnswerConfig: (suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig) => void
|
||||
formattingChanged: boolean
|
||||
setFormattingChanged: (formattingChanged: boolean) => void
|
||||
inputs: Inputs
|
||||
setInputs: (inputs: Inputs) => void
|
||||
query: string // user question
|
||||
setQuery: (query: string) => void
|
||||
// Belows are draft infos
|
||||
completionParams: CompletionParams
|
||||
setCompletionParams: (completionParams: CompletionParams) => void
|
||||
// model_config
|
||||
modelConfig: ModelConfig
|
||||
setModelConfig: (modelConfig: ModelConfig) => void
|
||||
dataSets: DataSet[]
|
||||
setDataSets: (dataSet: DataSet[]) => void
|
||||
}
|
||||
|
||||
const DebugConfigurationContext = createContext<IDebugConfiguration>({
|
||||
appId: '',
|
||||
hasSetAPIKEY: false,
|
||||
isTrailFinished: false,
|
||||
mode: '',
|
||||
conversationId: '',
|
||||
setConversationId: () => { },
|
||||
introduction: '',
|
||||
setIntroduction: () => { },
|
||||
controlClearChatMessage: 0,
|
||||
setControlClearChatMessage: () => { },
|
||||
prevPromptConfig: {
|
||||
prompt_template: '',
|
||||
prompt_variables: [],
|
||||
},
|
||||
setPrevPromptConfig: () => { },
|
||||
moreLikeThisConifg: {
|
||||
enabled: false,
|
||||
},
|
||||
setMoreLikeThisConifg: () => { },
|
||||
suggestedQuestionsAfterAnswerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
setSuggestedQuestionsAfterAnswerConfig: () => { },
|
||||
formattingChanged: false,
|
||||
setFormattingChanged: () => { },
|
||||
inputs: {},
|
||||
setInputs: () => { },
|
||||
query: '',
|
||||
setQuery: () => { },
|
||||
completionParams: {
|
||||
max_tokens: 16,
|
||||
temperature: 1, // 0-2
|
||||
top_p: 1,
|
||||
presence_penalty: 1, // -2-2
|
||||
frequency_penalty: 1, // -2-2
|
||||
},
|
||||
setCompletionParams: () => { },
|
||||
modelConfig: {
|
||||
provider: 'OPENAI', // 'OPENAI'
|
||||
model_id: 'gpt-3.5-turbo', // 'gpt-3.5-turbo'
|
||||
configs: {
|
||||
prompt_template: '',
|
||||
prompt_variables: [],
|
||||
},
|
||||
},
|
||||
setModelConfig: () => { },
|
||||
dataSets: [],
|
||||
setDataSets: () => { },
|
||||
})
|
||||
|
||||
export default DebugConfigurationContext
|
18
web/context/i18n.ts
Normal file
18
web/context/i18n.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createContext } from 'use-context-selector'
|
||||
import type { Locale } from '@/i18n'
|
||||
|
||||
type II18NContext = {
|
||||
locale: Locale
|
||||
i18n: Record<string, any>,
|
||||
setLocaleOnClient: (locale: Locale) => void
|
||||
// setI8N: (i18n: Record<string, string>) => void,
|
||||
}
|
||||
|
||||
const I18NContext = createContext<II18NContext>({
|
||||
locale: 'en',
|
||||
i18n: {},
|
||||
setLocaleOnClient: (lang: Locale) => { }
|
||||
// setI8N: () => {},
|
||||
})
|
||||
|
||||
export default I18NContext
|
35
web/context/workspace-context.tsx
Normal file
35
web/context/workspace-context.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import useSWR from 'swr'
|
||||
import { fetchWorkspaces } from '@/service/common'
|
||||
import type { IWorkspace } from '@/models/common'
|
||||
|
||||
export type WorkspacesContextValue = {
|
||||
workspaces: IWorkspace[]
|
||||
}
|
||||
|
||||
const WorkspacesContext = createContext<WorkspacesContextValue>({
|
||||
workspaces: []
|
||||
})
|
||||
|
||||
interface IWorkspaceProviderProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
export const WorkspaceProvider = ({
|
||||
children
|
||||
}: IWorkspaceProviderProps) => {
|
||||
const { data } = useSWR({ url: '/workspaces' }, fetchWorkspaces)
|
||||
|
||||
return (
|
||||
<WorkspacesContext.Provider value={{
|
||||
workspaces: data?.workspaces || []
|
||||
}}>
|
||||
{children}
|
||||
</WorkspacesContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useWorkspacesContext = () => useContext(WorkspacesContext)
|
||||
|
||||
export default WorkspacesContext
|
Reference in New Issue
Block a user