debug-configuration.ts 8.1 KB

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