debug.ts 5.8 KB

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