debug.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem } 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 = MoreLikeThisConfig
  65. export type CitationConfig = MoreLikeThisConfig
  66. export type AnnotationReplyConfig = {
  67. id: string
  68. enabled: boolean
  69. score_threshold: number
  70. embedding_model: {
  71. embedding_provider_name: string
  72. embedding_model_name: string
  73. }
  74. }
  75. export type ModerationContentConfig = {
  76. enabled: boolean
  77. preset_response?: string
  78. }
  79. export type ModerationConfig = MoreLikeThisConfig & {
  80. type?: string
  81. config?: {
  82. keywords?: string
  83. api_based_extension_id?: string
  84. inputs_config?: ModerationContentConfig
  85. outputs_config?: ModerationContentConfig
  86. } & Partial<Record<string, any>>
  87. }
  88. export type RetrieverResourceConfig = MoreLikeThisConfig
  89. export type AgentConfig = {
  90. enabled: boolean
  91. strategy: AgentStrategy
  92. max_iteration: number
  93. tools: ToolItem[]
  94. }
  95. // frontend use. Not the same as backend
  96. export type ModelConfig = {
  97. provider: string // LLM Provider: for example "OPENAI"
  98. model_id: string
  99. mode: ModelModeType
  100. configs: PromptConfig
  101. opening_statement: string | null
  102. more_like_this: MoreLikeThisConfig | null
  103. suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
  104. speech_to_text: SpeechToTextConfig | null
  105. text_to_speech: TextToSpeechConfig | null
  106. retriever_resource: RetrieverResourceConfig | null
  107. sensitive_word_avoidance: ModerationConfig | null
  108. dataSets: any[]
  109. agentConfig: AgentConfig
  110. }
  111. export type DatasetConfigItem = {
  112. enable: boolean
  113. value: number
  114. }
  115. export type DatasetConfigs = {
  116. retrieval_model: RETRIEVE_TYPE
  117. reranking_model: {
  118. reranking_provider_name: string
  119. reranking_model_name: string
  120. }
  121. top_k: number
  122. score_threshold_enabled: boolean
  123. score_threshold: number
  124. datasets: {
  125. datasets: {
  126. enabled: boolean
  127. id: string
  128. }[]
  129. }
  130. }
  131. export type DebugRequestBody = {
  132. inputs: Inputs
  133. query: string
  134. completion_params: CompletionParams
  135. model_config: ModelConfig
  136. }
  137. export type DebugResponse = {
  138. id: string
  139. answer: string
  140. created_at: string
  141. }
  142. export type DebugResponseStream = {
  143. id: string
  144. data: string
  145. created_at: string
  146. }
  147. export type FeedBackRequestBody = {
  148. message_id: string
  149. rating: 'like' | 'dislike'
  150. content?: string
  151. from_source: 'api' | 'log'
  152. }
  153. export type FeedBackResponse = {
  154. message_id: string
  155. rating: 'like' | 'dislike'
  156. }
  157. // Log session list
  158. export type LogSessionListQuery = {
  159. keyword?: string
  160. start?: string // format datetime(YYYY-mm-dd HH:ii)
  161. end?: string // format datetime(YYYY-mm-dd HH:ii)
  162. page: number
  163. limit: number // default 20. 1-100
  164. }
  165. export type LogSessionListResponse = {
  166. data: {
  167. id: string
  168. conversation_id: string
  169. query: string // user's query question
  170. message: string // prompt send to LLM
  171. answer: string
  172. creat_at: string
  173. }[]
  174. total: number
  175. page: number
  176. }
  177. // log session detail and debug
  178. export type LogSessionDetailResponse = {
  179. id: string
  180. cnversation_id: string
  181. model_provider: string
  182. query: string
  183. inputs: Record<string, string | number | object>[]
  184. message: string
  185. message_tokens: number // number of tokens in message
  186. answer: string
  187. answer_tokens: number // number of tokens in answer
  188. provider_response_latency: number // used time in ms
  189. from_source: 'api' | 'log'
  190. }
  191. export type SavedMessage = {
  192. id: string
  193. answer: string
  194. }