debug-configuration.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. rerankSettingModalOpen: boolean
  100. setRerankSettingModalOpen: (rerankSettingModalOpen: boolean) => void
  101. }
  102. const DebugConfigurationContext = createContext<IDebugConfiguration>({
  103. appId: '',
  104. isAPIKeySet: false,
  105. isTrailFinished: false,
  106. mode: '',
  107. modelModeType: ModelModeType.chat,
  108. promptMode: PromptMode.simple,
  109. setPromptMode: () => { },
  110. isAdvancedMode: false,
  111. isAgent: false,
  112. isFunctionCall: false,
  113. isOpenAI: false,
  114. collectionList: [],
  115. canReturnToSimpleMode: false,
  116. setCanReturnToSimpleMode: () => { },
  117. chatPromptConfig: DEFAULT_CHAT_PROMPT_CONFIG,
  118. completionPromptConfig: DEFAULT_COMPLETION_PROMPT_CONFIG,
  119. currentAdvancedPrompt: [],
  120. showHistoryModal: () => { },
  121. conversationHistoriesRole: {
  122. user_prefix: 'user',
  123. assistant_prefix: 'assistant',
  124. },
  125. setConversationHistoriesRole: () => { },
  126. setCurrentAdvancedPrompt: () => { },
  127. hasSetBlockStatus: {
  128. context: false,
  129. history: false,
  130. query: false,
  131. },
  132. conversationId: '',
  133. setConversationId: () => { },
  134. introduction: '',
  135. setIntroduction: () => { },
  136. suggestedQuestions: [],
  137. setSuggestedQuestions: () => { },
  138. controlClearChatMessage: 0,
  139. setControlClearChatMessage: () => { },
  140. prevPromptConfig: {
  141. prompt_template: '',
  142. prompt_variables: [],
  143. },
  144. setPrevPromptConfig: () => { },
  145. moreLikeThisConfig: {
  146. enabled: false,
  147. },
  148. setMoreLikeThisConfig: () => { },
  149. suggestedQuestionsAfterAnswerConfig: {
  150. enabled: false,
  151. },
  152. setSuggestedQuestionsAfterAnswerConfig: () => { },
  153. speechToTextConfig: {
  154. enabled: false,
  155. },
  156. setSpeechToTextConfig: () => { },
  157. textToSpeechConfig: {
  158. enabled: false,
  159. voice: '',
  160. language: '',
  161. },
  162. setTextToSpeechConfig: () => { },
  163. citationConfig: {
  164. enabled: false,
  165. },
  166. setCitationConfig: () => { },
  167. moderationConfig: {
  168. enabled: false,
  169. },
  170. annotationConfig: {
  171. id: '',
  172. enabled: false,
  173. score_threshold: ANNOTATION_DEFAULT.score_threshold,
  174. embedding_model: {
  175. embedding_model_name: '',
  176. embedding_provider_name: '',
  177. },
  178. },
  179. setAnnotationConfig: () => { },
  180. setModerationConfig: () => { },
  181. externalDataToolsConfig: [],
  182. setExternalDataToolsConfig: () => { },
  183. formattingChanged: false,
  184. setFormattingChanged: () => { },
  185. inputs: {},
  186. setInputs: () => { },
  187. query: '',
  188. setQuery: () => { },
  189. completionParams: {
  190. max_tokens: 16,
  191. temperature: 1, // 0-2
  192. top_p: 1,
  193. presence_penalty: 1, // -2-2
  194. frequency_penalty: 1, // -2-2
  195. },
  196. setCompletionParams: () => { },
  197. modelConfig: {
  198. provider: 'OPENAI', // 'OPENAI'
  199. model_id: 'gpt-3.5-turbo', // 'gpt-3.5-turbo'
  200. mode: ModelModeType.unset,
  201. configs: {
  202. prompt_template: '',
  203. prompt_variables: [],
  204. },
  205. more_like_this: null,
  206. opening_statement: '',
  207. suggested_questions: [],
  208. sensitive_word_avoidance: null,
  209. speech_to_text: null,
  210. text_to_speech: null,
  211. file_upload: null,
  212. suggested_questions_after_answer: null,
  213. retriever_resource: null,
  214. annotation_reply: null,
  215. dataSets: [],
  216. agentConfig: DEFAULT_AGENT_SETTING,
  217. },
  218. setModelConfig: () => { },
  219. dataSets: [],
  220. showSelectDataSet: () => { },
  221. setDataSets: () => { },
  222. datasetConfigs: {
  223. retrieval_model: RETRIEVE_TYPE.multiWay,
  224. reranking_model: {
  225. reranking_provider_name: '',
  226. reranking_model_name: '',
  227. },
  228. top_k: 2,
  229. score_threshold_enabled: false,
  230. score_threshold: 0.7,
  231. datasets: {
  232. datasets: [],
  233. },
  234. },
  235. setDatasetConfigs: () => { },
  236. hasSetContextVar: false,
  237. isShowVisionConfig: false,
  238. visionConfig: {
  239. enabled: false,
  240. number_limits: 2,
  241. detail: Resolution.low,
  242. transfer_methods: [TransferMethod.remote_url],
  243. },
  244. setVisionConfig: () => { },
  245. rerankSettingModalOpen: false,
  246. setRerankSettingModalOpen: () => { },
  247. })
  248. export const useDebugConfigurationContext = () => useContext(DebugConfigurationContext)
  249. export default DebugConfigurationContext