debug.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem, TtsAutoPlay } from '@/types/app'
  2. import type {
  3. RerankingModeEnum,
  4. WeightedScoreEnum,
  5. } from '@/models/datasets'
  6. import type { FileUpload } from '@/app/components/base/features/types'
  7. import type {
  8. MetadataFilteringConditions,
  9. MetadataFilteringModeEnum,
  10. } from '@/app/components/workflow/nodes/knowledge-retrieval/types'
  11. import type { ModelConfig as NodeModelConfig } from '@/app/components/workflow/types'
  12. export type Inputs = Record<string, string | number | object>
  13. export enum PromptMode {
  14. simple = 'simple',
  15. advanced = 'advanced',
  16. }
  17. export type PromptItem = {
  18. role?: PromptRole
  19. text: string
  20. }
  21. export type ChatPromptConfig = {
  22. prompt: PromptItem[]
  23. }
  24. export type ConversationHistoriesRole = {
  25. user_prefix: string
  26. assistant_prefix: string
  27. }
  28. export type CompletionPromptConfig = {
  29. prompt: PromptItem
  30. conversation_histories_role: ConversationHistoriesRole
  31. }
  32. export type BlockStatus = {
  33. context: boolean
  34. history: boolean
  35. query: boolean
  36. }
  37. export enum PromptRole {
  38. system = 'system',
  39. user = 'user',
  40. assistant = 'assistant',
  41. }
  42. export type PromptVariable = {
  43. key: string
  44. name: string
  45. type: string // "string" | "number" | "select",
  46. default?: string | number
  47. required?: boolean
  48. options?: string[]
  49. max_length?: number
  50. is_context_var?: boolean
  51. enabled?: boolean
  52. config?: Record<string, any>
  53. icon?: string
  54. icon_background?: string
  55. }
  56. export type CompletionParams = {
  57. max_tokens: number
  58. temperature: number
  59. top_p: number
  60. presence_penalty: number
  61. frequency_penalty: number
  62. stop?: string[]
  63. }
  64. export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
  65. export type PromptConfig = {
  66. prompt_template: string
  67. prompt_variables: PromptVariable[]
  68. }
  69. export type MoreLikeThisConfig = {
  70. enabled: boolean
  71. }
  72. export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
  73. export type SpeechToTextConfig = MoreLikeThisConfig
  74. export type TextToSpeechConfig = {
  75. enabled: boolean
  76. voice?: string
  77. language?: string
  78. autoPlay?: TtsAutoPlay
  79. }
  80. export type CitationConfig = MoreLikeThisConfig
  81. export type AnnotationReplyConfig = {
  82. id: string
  83. enabled: boolean
  84. score_threshold: number
  85. embedding_model: {
  86. embedding_provider_name: string
  87. embedding_model_name: string
  88. }
  89. }
  90. export type ModerationContentConfig = {
  91. enabled: boolean
  92. preset_response?: string
  93. }
  94. export type ModerationConfig = MoreLikeThisConfig & {
  95. type?: string
  96. config?: {
  97. keywords?: string
  98. api_based_extension_id?: string
  99. inputs_config?: ModerationContentConfig
  100. outputs_config?: ModerationContentConfig
  101. } & Partial<Record<string, any>>
  102. }
  103. export type RetrieverResourceConfig = MoreLikeThisConfig
  104. export type AgentConfig = {
  105. enabled: boolean
  106. strategy: AgentStrategy
  107. max_iteration: number
  108. tools: ToolItem[]
  109. }
  110. // frontend use. Not the same as backend
  111. export type ModelConfig = {
  112. provider: string // LLM Provider: for example "OPENAI"
  113. model_id: string
  114. mode: ModelModeType
  115. configs: PromptConfig
  116. opening_statement: string | null
  117. more_like_this: MoreLikeThisConfig | null
  118. suggested_questions: string[] | null
  119. suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
  120. speech_to_text: SpeechToTextConfig | null
  121. text_to_speech: TextToSpeechConfig | null
  122. file_upload: FileUpload | null
  123. retriever_resource: RetrieverResourceConfig | null
  124. sensitive_word_avoidance: ModerationConfig | null
  125. annotation_reply: AnnotationReplyConfig | null
  126. dataSets: any[]
  127. agentConfig: AgentConfig
  128. }
  129. export type DatasetConfigItem = {
  130. enable: boolean
  131. value: number
  132. }
  133. export type DatasetConfigs = {
  134. retrieval_model: RETRIEVE_TYPE
  135. reranking_model: {
  136. reranking_provider_name: string
  137. reranking_model_name: string
  138. }
  139. top_k: number
  140. score_threshold_enabled: boolean
  141. score_threshold: number | null | undefined
  142. datasets: {
  143. datasets: {
  144. enabled: boolean
  145. id: string
  146. }[]
  147. }
  148. reranking_mode?: RerankingModeEnum
  149. weights?: {
  150. weight_type: WeightedScoreEnum
  151. vector_setting: {
  152. vector_weight: number
  153. embedding_provider_name: string
  154. embedding_model_name: string
  155. }
  156. keyword_setting: {
  157. keyword_weight: number
  158. }
  159. }
  160. reranking_enable?: boolean
  161. metadata_filtering_mode?: MetadataFilteringModeEnum
  162. metadata_filtering_conditions?: MetadataFilteringConditions
  163. metadata_model_config?: NodeModelConfig
  164. }
  165. export type DebugRequestBody = {
  166. inputs: Inputs
  167. query: string
  168. completion_params: CompletionParams
  169. model_config: ModelConfig
  170. }
  171. export type DebugResponse = {
  172. id: string
  173. answer: string
  174. created_at: string
  175. }
  176. export type DebugResponseStream = {
  177. id: string
  178. data: string
  179. created_at: string
  180. }
  181. export type FeedBackRequestBody = {
  182. message_id: string
  183. rating: 'like' | 'dislike'
  184. content?: string
  185. from_source: 'api' | 'log'
  186. }
  187. export type FeedBackResponse = {
  188. message_id: string
  189. rating: 'like' | 'dislike'
  190. }
  191. // Log session list
  192. export type LogSessionListQuery = {
  193. keyword?: string
  194. start?: string // format datetime(YYYY-mm-dd HH:ii)
  195. end?: string // format datetime(YYYY-mm-dd HH:ii)
  196. page: number
  197. limit: number // default 20. 1-100
  198. }
  199. export type LogSessionListResponse = {
  200. data: {
  201. id: string
  202. conversation_id: string
  203. query: string // user's query question
  204. message: string // prompt send to LLM
  205. answer: string
  206. created_at: string
  207. }[]
  208. total: number
  209. page: number
  210. }
  211. // log session detail and debug
  212. export type LogSessionDetailResponse = {
  213. id: string
  214. conversation_id: string
  215. model_provider: string
  216. query: string
  217. inputs: Record<string, string | number | object>[]
  218. message: string
  219. message_tokens: number // number of tokens in message
  220. answer: string
  221. answer_tokens: number // number of tokens in answer
  222. provider_response_latency: number // used time in ms
  223. from_source: 'api' | 'log'
  224. }
  225. export type SavedMessage = {
  226. id: string
  227. answer: string
  228. }