Spaces:
Build error
Build error
File size: 8,124 Bytes
a8b3f00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
import { createContext, useContext } from 'use-context-selector'
import { PromptMode } from '@/models/debug'
import type {
AnnotationReplyConfig,
BlockStatus,
ChatPromptConfig,
CitationConfig,
CompletionPromptConfig,
ConversationHistoriesRole,
DatasetConfigs,
Inputs,
ModelConfig,
ModerationConfig,
MoreLikeThisConfig,
PromptConfig,
PromptItem,
SpeechToTextConfig,
SuggestedQuestionsAfterAnswerConfig,
TextToSpeechConfig,
} from '@/models/debug'
import type { ExternalDataTool } from '@/models/common'
import type { DataSet } from '@/models/datasets'
import type { VisionSettings } from '@/types/app'
import { ModelModeType, RETRIEVE_TYPE, Resolution, TransferMethod } from '@/types/app'
import { ANNOTATION_DEFAULT, DEFAULT_AGENT_SETTING, DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
import type { FormValue } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { Collection } from '@/app/components/tools/types'
type IDebugConfiguration = {
appId: string
isAPIKeySet: boolean
isTrailFinished: boolean
mode: string
modelModeType: ModelModeType
promptMode: PromptMode
setPromptMode: (promptMode: PromptMode) => void
isAdvancedMode: boolean
isAgent: boolean
isFunctionCall: boolean
isOpenAI: boolean
collectionList: Collection[]
canReturnToSimpleMode: boolean
setCanReturnToSimpleMode: (canReturnToSimpleMode: boolean) => void
chatPromptConfig: ChatPromptConfig
completionPromptConfig: CompletionPromptConfig
currentAdvancedPrompt: PromptItem | PromptItem[]
setCurrentAdvancedPrompt: (prompt: PromptItem | PromptItem[], isUserChanged?: boolean) => void
showHistoryModal: () => void
conversationHistoriesRole: ConversationHistoriesRole
setConversationHistoriesRole: (conversationHistoriesRole: ConversationHistoriesRole) => void
hasSetBlockStatus: BlockStatus
conversationId: string | null // after first chat send
setConversationId: (conversationId: string | null) => void
introduction: string
setIntroduction: (introduction: string) => void
suggestedQuestions: string[]
setSuggestedQuestions: (questions: string[]) => void
controlClearChatMessage: number
setControlClearChatMessage: (controlClearChatMessage: number) => void
prevPromptConfig: PromptConfig
setPrevPromptConfig: (prevPromptConfig: PromptConfig) => void
moreLikeThisConfig: MoreLikeThisConfig
setMoreLikeThisConfig: (moreLikeThisConfig: MoreLikeThisConfig) => void
suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig
setSuggestedQuestionsAfterAnswerConfig: (suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig) => void
speechToTextConfig: SpeechToTextConfig
setSpeechToTextConfig: (speechToTextConfig: SpeechToTextConfig) => void
textToSpeechConfig: TextToSpeechConfig
setTextToSpeechConfig: (textToSpeechConfig: TextToSpeechConfig) => void
citationConfig: CitationConfig
setCitationConfig: (citationConfig: CitationConfig) => void
annotationConfig: AnnotationReplyConfig
setAnnotationConfig: (annotationConfig: AnnotationReplyConfig) => void
moderationConfig: ModerationConfig
setModerationConfig: (moderationConfig: ModerationConfig) => void
externalDataToolsConfig: ExternalDataTool[]
setExternalDataToolsConfig: (externalDataTools: ExternalDataTool[]) => 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: FormValue
setCompletionParams: (completionParams: FormValue) => void
// model_config
modelConfig: ModelConfig
setModelConfig: (modelConfig: ModelConfig) => void
dataSets: DataSet[]
setDataSets: (dataSet: DataSet[]) => void
showSelectDataSet: () => void
// dataset config
datasetConfigs: DatasetConfigs
setDatasetConfigs: (config: DatasetConfigs) => void
hasSetContextVar: boolean
isShowVisionConfig: boolean
visionConfig: VisionSettings
setVisionConfig: (visionConfig: VisionSettings, noNotice?: boolean) => void
rerankSettingModalOpen: boolean
setRerankSettingModalOpen: (rerankSettingModalOpen: boolean) => void
}
const DebugConfigurationContext = createContext<IDebugConfiguration>({
appId: '',
isAPIKeySet: false,
isTrailFinished: false,
mode: '',
modelModeType: ModelModeType.chat,
promptMode: PromptMode.simple,
setPromptMode: () => { },
isAdvancedMode: false,
isAgent: false,
isFunctionCall: false,
isOpenAI: false,
collectionList: [],
canReturnToSimpleMode: false,
setCanReturnToSimpleMode: () => { },
chatPromptConfig: DEFAULT_CHAT_PROMPT_CONFIG,
completionPromptConfig: DEFAULT_COMPLETION_PROMPT_CONFIG,
currentAdvancedPrompt: [],
showHistoryModal: () => { },
conversationHistoriesRole: {
user_prefix: 'user',
assistant_prefix: 'assistant',
},
setConversationHistoriesRole: () => { },
setCurrentAdvancedPrompt: () => { },
hasSetBlockStatus: {
context: false,
history: false,
query: false,
},
conversationId: '',
setConversationId: () => { },
introduction: '',
setIntroduction: () => { },
suggestedQuestions: [],
setSuggestedQuestions: () => { },
controlClearChatMessage: 0,
setControlClearChatMessage: () => { },
prevPromptConfig: {
prompt_template: '',
prompt_variables: [],
},
setPrevPromptConfig: () => { },
moreLikeThisConfig: {
enabled: false,
},
setMoreLikeThisConfig: () => { },
suggestedQuestionsAfterAnswerConfig: {
enabled: false,
},
setSuggestedQuestionsAfterAnswerConfig: () => { },
speechToTextConfig: {
enabled: false,
},
setSpeechToTextConfig: () => { },
textToSpeechConfig: {
enabled: false,
voice: '',
language: '',
},
setTextToSpeechConfig: () => { },
citationConfig: {
enabled: false,
},
setCitationConfig: () => { },
moderationConfig: {
enabled: false,
},
annotationConfig: {
id: '',
enabled: false,
score_threshold: ANNOTATION_DEFAULT.score_threshold,
embedding_model: {
embedding_model_name: '',
embedding_provider_name: '',
},
},
setAnnotationConfig: () => { },
setModerationConfig: () => { },
externalDataToolsConfig: [],
setExternalDataToolsConfig: () => { },
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'
mode: ModelModeType.unset,
configs: {
prompt_template: '',
prompt_variables: [],
},
more_like_this: null,
opening_statement: '',
suggested_questions: [],
sensitive_word_avoidance: null,
speech_to_text: null,
text_to_speech: null,
file_upload: null,
suggested_questions_after_answer: null,
retriever_resource: null,
annotation_reply: null,
dataSets: [],
agentConfig: DEFAULT_AGENT_SETTING,
},
setModelConfig: () => { },
dataSets: [],
showSelectDataSet: () => { },
setDataSets: () => { },
datasetConfigs: {
retrieval_model: RETRIEVE_TYPE.multiWay,
reranking_model: {
reranking_provider_name: '',
reranking_model_name: '',
},
top_k: 2,
score_threshold_enabled: false,
score_threshold: 0.7,
datasets: {
datasets: [],
},
},
setDatasetConfigs: () => { },
hasSetContextVar: false,
isShowVisionConfig: false,
visionConfig: {
enabled: false,
number_limits: 2,
detail: Resolution.low,
transfer_methods: [TransferMethod.remote_url],
},
setVisionConfig: () => { },
rerankSettingModalOpen: false,
setRerankSettingModalOpen: () => { },
})
export const useDebugConfigurationContext = () => useContext(DebugConfigurationContext)
export default DebugConfigurationContext
|