| 
									
										
										
										
											2024-01-25 12:36:55 +08:00
										 |  |  | import { createContext, useContext } from 'use-context-selector' | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  | import { PromptMode } from '@/models/debug' | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | import type { | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   AnnotationReplyConfig, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   BlockStatus, | 
					
						
							|  |  |  |   ChatPromptConfig, | 
					
						
							|  |  |  |   CitationConfig, | 
					
						
							|  |  |  |   CompletionPromptConfig, | 
					
						
							|  |  |  |   ConversationHistoriesRole, | 
					
						
							|  |  |  |   DatasetConfigs, | 
					
						
							|  |  |  |   Inputs, | 
					
						
							|  |  |  |   ModelConfig, | 
					
						
							|  |  |  |   ModerationConfig, | 
					
						
							|  |  |  |   MoreLikeThisConfig, | 
					
						
							|  |  |  |   PromptConfig, | 
					
						
							|  |  |  |   PromptItem, | 
					
						
							|  |  |  |   SpeechToTextConfig, | 
					
						
							|  |  |  |   SuggestedQuestionsAfterAnswerConfig, | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |   TextToSpeechConfig, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | } from '@/models/debug' | 
					
						
							|  |  |  | import type { ExternalDataTool } from '@/models/common' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import type { DataSet } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2023-11-13 22:32:39 +08:00
										 |  |  | import type { VisionSettings } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | import { ModelModeType, RETRIEVE_TYPE, Resolution, TransferMethod } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import { ANNOTATION_DEFAULT, DEFAULT_AGENT_SETTING, DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config' | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | import type { FormValue } from '@/app/components/header/account-setting/model-provider-page/declarations' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import type { Collection } from '@/app/components/tools/types' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type IDebugConfiguration = { | 
					
						
							|  |  |  |   appId: string | 
					
						
							|  |  |  |   hasSetAPIKEY: boolean | 
					
						
							|  |  |  |   isTrailFinished: boolean | 
					
						
							|  |  |  |   mode: string | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   modelModeType: ModelModeType | 
					
						
							|  |  |  |   promptMode: PromptMode | 
					
						
							|  |  |  |   setPromptMode: (promptMode: PromptMode) => void | 
					
						
							|  |  |  |   isAdvancedMode: boolean | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   isAgent: boolean | 
					
						
							|  |  |  |   isFunctionCall: boolean | 
					
						
							|  |  |  |   isOpenAI: boolean | 
					
						
							|  |  |  |   collectionList: Collection[] | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   conversationId: string | null // after first chat send
 | 
					
						
							|  |  |  |   setConversationId: (conversationId: string | null) => void | 
					
						
							|  |  |  |   introduction: string | 
					
						
							|  |  |  |   setIntroduction: (introduction: string) => void | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   suggestedQuestions: string[] | 
					
						
							|  |  |  |   setSuggestedQuestions: (questions: string[]) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   controlClearChatMessage: number | 
					
						
							|  |  |  |   setControlClearChatMessage: (controlClearChatMessage: number) => void | 
					
						
							|  |  |  |   prevPromptConfig: PromptConfig | 
					
						
							|  |  |  |   setPrevPromptConfig: (prevPromptConfig: PromptConfig) => void | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   moreLikeThisConfig: MoreLikeThisConfig | 
					
						
							|  |  |  |   setMoreLikeThisConfig: (moreLikeThisConfig: MoreLikeThisConfig) => void | 
					
						
							|  |  |  |   suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   setSuggestedQuestionsAfterAnswerConfig: (suggestedQuestionsAfterAnswerConfig: SuggestedQuestionsAfterAnswerConfig) => void | 
					
						
							| 
									
										
										
										
											2023-07-07 17:50:42 +08:00
										 |  |  |   speechToTextConfig: SpeechToTextConfig | 
					
						
							|  |  |  |   setSpeechToTextConfig: (speechToTextConfig: SpeechToTextConfig) => void | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |   textToSpeechConfig: TextToSpeechConfig | 
					
						
							|  |  |  |   setTextToSpeechConfig: (textToSpeechConfig: TextToSpeechConfig) => void | 
					
						
							| 
									
										
										
										
											2023-09-09 19:17:12 +08:00
										 |  |  |   citationConfig: CitationConfig | 
					
						
							|  |  |  |   setCitationConfig: (citationConfig: CitationConfig) => void | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   annotationConfig: AnnotationReplyConfig | 
					
						
							|  |  |  |   setAnnotationConfig: (annotationConfig: AnnotationReplyConfig) => void | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   moderationConfig: ModerationConfig | 
					
						
							|  |  |  |   setModerationConfig: (moderationConfig: ModerationConfig) => void | 
					
						
							|  |  |  |   externalDataToolsConfig: ExternalDataTool[] | 
					
						
							|  |  |  |   setExternalDataToolsConfig: (externalDataTools: ExternalDataTool[]) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   formattingChanged: boolean | 
					
						
							|  |  |  |   setFormattingChanged: (formattingChanged: boolean) => void | 
					
						
							|  |  |  |   inputs: Inputs | 
					
						
							|  |  |  |   setInputs: (inputs: Inputs) => void | 
					
						
							|  |  |  |   query: string // user question
 | 
					
						
							|  |  |  |   setQuery: (query: string) => void | 
					
						
							|  |  |  |   // Belows are draft infos
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |   completionParams: FormValue | 
					
						
							|  |  |  |   setCompletionParams: (completionParams: FormValue) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   // model_config
 | 
					
						
							|  |  |  |   modelConfig: ModelConfig | 
					
						
							|  |  |  |   setModelConfig: (modelConfig: ModelConfig) => void | 
					
						
							|  |  |  |   dataSets: DataSet[] | 
					
						
							|  |  |  |   setDataSets: (dataSet: DataSet[]) => void | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   showSelectDataSet: () => void | 
					
						
							|  |  |  |   // dataset config
 | 
					
						
							|  |  |  |   datasetConfigs: DatasetConfigs | 
					
						
							|  |  |  |   setDatasetConfigs: (config: DatasetConfigs) => void | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |   hasSetContextVar: boolean | 
					
						
							| 
									
										
										
										
											2023-11-13 22:32:39 +08:00
										 |  |  |   isShowVisionConfig: boolean | 
					
						
							|  |  |  |   visionConfig: VisionSettings | 
					
						
							| 
									
										
										
										
											2024-01-30 16:06:01 +08:00
										 |  |  |   setVisionConfig: (visionConfig: VisionSettings, noNotice?: boolean) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const DebugConfigurationContext = createContext<IDebugConfiguration>({ | 
					
						
							|  |  |  |   appId: '', | 
					
						
							|  |  |  |   hasSetAPIKEY: false, | 
					
						
							|  |  |  |   isTrailFinished: false, | 
					
						
							|  |  |  |   mode: '', | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   modelModeType: ModelModeType.chat, | 
					
						
							|  |  |  |   promptMode: PromptMode.simple, | 
					
						
							|  |  |  |   setPromptMode: () => { }, | 
					
						
							|  |  |  |   isAdvancedMode: false, | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   isAgent: false, | 
					
						
							|  |  |  |   isFunctionCall: false, | 
					
						
							|  |  |  |   isOpenAI: false, | 
					
						
							|  |  |  |   collectionList: [], | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   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, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   conversationId: '', | 
					
						
							|  |  |  |   setConversationId: () => { }, | 
					
						
							|  |  |  |   introduction: '', | 
					
						
							|  |  |  |   setIntroduction: () => { }, | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   suggestedQuestions: [], | 
					
						
							|  |  |  |   setSuggestedQuestions: () => {}, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   controlClearChatMessage: 0, | 
					
						
							|  |  |  |   setControlClearChatMessage: () => { }, | 
					
						
							|  |  |  |   prevPromptConfig: { | 
					
						
							|  |  |  |     prompt_template: '', | 
					
						
							|  |  |  |     prompt_variables: [], | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setPrevPromptConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   moreLikeThisConfig: { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     enabled: false, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   setMoreLikeThisConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   suggestedQuestionsAfterAnswerConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setSuggestedQuestionsAfterAnswerConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-07-07 17:50:42 +08:00
										 |  |  |   speechToTextConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setSpeechToTextConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |   textToSpeechConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							| 
									
										
										
										
											2024-02-15 22:41:18 +08:00
										 |  |  |     voice: '', | 
					
						
							|  |  |  |     language: '', | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   setTextToSpeechConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-09-09 19:17:12 +08:00
										 |  |  |   citationConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   setCitationConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   moderationConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   annotationConfig: { | 
					
						
							|  |  |  |     id: '', | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |     score_threshold: ANNOTATION_DEFAULT.score_threshold, | 
					
						
							|  |  |  |     embedding_model: { | 
					
						
							|  |  |  |       embedding_model_name: '', | 
					
						
							|  |  |  |       embedding_provider_name: '', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setAnnotationConfig: () => { }, | 
					
						
							|  |  |  |   setModerationConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   externalDataToolsConfig: [], | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   setExternalDataToolsConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   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'
 | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |     mode: ModelModeType.unset, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     configs: { | 
					
						
							|  |  |  |       prompt_template: '', | 
					
						
							|  |  |  |       prompt_variables: [], | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |     opening_statement: null, | 
					
						
							|  |  |  |     more_like_this: null, | 
					
						
							|  |  |  |     suggested_questions_after_answer: null, | 
					
						
							|  |  |  |     speech_to_text: null, | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |     text_to_speech: null, | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |     retriever_resource: null, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |     sensitive_word_avoidance: null, | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |     dataSets: [], | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |     agentConfig: DEFAULT_AGENT_SETTING, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   setModelConfig: () => { }, | 
					
						
							|  |  |  |   dataSets: [], | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   showSelectDataSet: () => { }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   setDataSets: () => { }, | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   datasetConfigs: { | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  |     retrieval_model: RETRIEVE_TYPE.oneWay, | 
					
						
							|  |  |  |     reranking_model: { | 
					
						
							|  |  |  |       reranking_provider_name: '', | 
					
						
							|  |  |  |       reranking_model_name: '', | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  |     top_k: 2, | 
					
						
							|  |  |  |     score_threshold_enabled: false, | 
					
						
							|  |  |  |     score_threshold: 0.7, | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |     datasets: { | 
					
						
							|  |  |  |       datasets: [], | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   setDatasetConfigs: () => { }, | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |   hasSetContextVar: false, | 
					
						
							| 
									
										
										
										
											2023-11-13 22:32:39 +08:00
										 |  |  |   isShowVisionConfig: false, | 
					
						
							|  |  |  |   visionConfig: { | 
					
						
							|  |  |  |     enabled: false, | 
					
						
							|  |  |  |     number_limits: 2, | 
					
						
							|  |  |  |     detail: Resolution.low, | 
					
						
							|  |  |  |     transfer_methods: [TransferMethod.remote_url], | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   setVisionConfig: () => { }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 12:36:55 +08:00
										 |  |  | export const useDebugConfigurationContext = () => useContext(DebugConfigurationContext) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export default DebugConfigurationContext |