debug.ts 4.9 KB

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