Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

debug.ts 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 | boolean>
  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. hide?: boolean // used in frontend to hide variable
  56. json_schema?: string
  57. }
  58. export type CompletionParams = {
  59. max_tokens: number
  60. temperature: number
  61. top_p: number
  62. presence_penalty: number
  63. frequency_penalty: number
  64. stop?: string[]
  65. }
  66. export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
  67. export type PromptConfig = {
  68. prompt_template: string
  69. prompt_variables: PromptVariable[]
  70. }
  71. export type MoreLikeThisConfig = {
  72. enabled: boolean
  73. }
  74. export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
  75. export type SpeechToTextConfig = MoreLikeThisConfig
  76. export type TextToSpeechConfig = {
  77. enabled: boolean
  78. voice?: string
  79. language?: string
  80. autoPlay?: TtsAutoPlay
  81. }
  82. export type CitationConfig = MoreLikeThisConfig
  83. export type AnnotationReplyConfig = {
  84. id: string
  85. enabled: boolean
  86. score_threshold: number
  87. embedding_model: {
  88. embedding_provider_name: string
  89. embedding_model_name: string
  90. }
  91. }
  92. export type ModerationContentConfig = {
  93. enabled: boolean
  94. preset_response?: string
  95. }
  96. export type ModerationConfig = MoreLikeThisConfig & {
  97. type?: string
  98. config?: {
  99. keywords?: string
  100. api_based_extension_id?: string
  101. inputs_config?: ModerationContentConfig
  102. outputs_config?: ModerationContentConfig
  103. } & Partial<Record<string, any>>
  104. }
  105. export type RetrieverResourceConfig = MoreLikeThisConfig
  106. export type AgentConfig = {
  107. enabled: boolean
  108. strategy: AgentStrategy
  109. max_iteration: number
  110. tools: ToolItem[]
  111. }
  112. // frontend use. Not the same as backend
  113. export type ModelConfig = {
  114. provider: string // LLM Provider: for example "OPENAI"
  115. model_id: string
  116. mode: ModelModeType
  117. configs: PromptConfig
  118. opening_statement: string | null
  119. more_like_this: MoreLikeThisConfig | null
  120. suggested_questions: string[] | null
  121. suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
  122. speech_to_text: SpeechToTextConfig | null
  123. text_to_speech: TextToSpeechConfig | null
  124. file_upload: FileUpload | null
  125. retriever_resource: RetrieverResourceConfig | null
  126. sensitive_word_avoidance: ModerationConfig | null
  127. annotation_reply: AnnotationReplyConfig | null
  128. dataSets: any[]
  129. agentConfig: AgentConfig
  130. }
  131. export type DatasetConfigItem = {
  132. enable: boolean
  133. value: number
  134. }
  135. export type DatasetConfigs = {
  136. retrieval_model: RETRIEVE_TYPE
  137. reranking_model: {
  138. reranking_provider_name: string
  139. reranking_model_name: string
  140. }
  141. top_k: number
  142. score_threshold_enabled: boolean
  143. score_threshold: number | null | undefined
  144. datasets: {
  145. datasets: {
  146. enabled: boolean
  147. id: string
  148. }[]
  149. }
  150. reranking_mode?: RerankingModeEnum
  151. weights?: {
  152. weight_type: WeightedScoreEnum
  153. vector_setting: {
  154. vector_weight: number
  155. embedding_provider_name: string
  156. embedding_model_name: string
  157. }
  158. keyword_setting: {
  159. keyword_weight: number
  160. }
  161. }
  162. reranking_enable?: boolean
  163. metadata_filtering_mode?: MetadataFilteringModeEnum
  164. metadata_filtering_conditions?: MetadataFilteringConditions
  165. metadata_model_config?: NodeModelConfig
  166. }
  167. export type DebugRequestBody = {
  168. inputs: Inputs
  169. query: string
  170. completion_params: CompletionParams
  171. model_config: ModelConfig
  172. }
  173. export type DebugResponse = {
  174. id: string
  175. answer: string
  176. created_at: string
  177. }
  178. export type DebugResponseStream = {
  179. id: string
  180. data: string
  181. created_at: string
  182. }
  183. export type FeedBackRequestBody = {
  184. message_id: string
  185. rating: 'like' | 'dislike'
  186. content?: string
  187. from_source: 'api' | 'log'
  188. }
  189. export type FeedBackResponse = {
  190. message_id: string
  191. rating: 'like' | 'dislike'
  192. }
  193. // Log session list
  194. export type LogSessionListQuery = {
  195. keyword?: string
  196. start?: string // format datetime(YYYY-mm-dd HH:ii)
  197. end?: string // format datetime(YYYY-mm-dd HH:ii)
  198. page: number
  199. limit: number // default 20. 1-100
  200. }
  201. export type LogSessionListResponse = {
  202. data: {
  203. id: string
  204. conversation_id: string
  205. query: string // user's query question
  206. message: string // prompt send to LLM
  207. answer: string
  208. created_at: string
  209. }[]
  210. total: number
  211. page: number
  212. }
  213. // log session detail and debug
  214. export type LogSessionDetailResponse = {
  215. id: string
  216. conversation_id: string
  217. model_provider: string
  218. query: string
  219. inputs: Record<string, string | number | object>[]
  220. message: string
  221. message_tokens: number // number of tokens in message
  222. answer: string
  223. answer_tokens: number // number of tokens in answer
  224. provider_response_latency: number // used time in ms
  225. from_source: 'api' | 'log'
  226. }
  227. export type SavedMessage = {
  228. id: string
  229. answer: string
  230. }