debug.ts 5.4 KB

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