debug.ts 4.7 KB

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