debug.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import type { ModelModeType, RETRIEVE_TYPE } 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. }
  42. export type CompletionParams = {
  43. max_tokens: number
  44. temperature: number
  45. top_p: number
  46. presence_penalty: number
  47. frequency_penalty: number
  48. stop?: string[]
  49. }
  50. export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
  51. export type PromptConfig = {
  52. prompt_template: string
  53. prompt_variables: PromptVariable[]
  54. }
  55. export type MoreLikeThisConfig = {
  56. enabled: boolean
  57. }
  58. export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
  59. export type SpeechToTextConfig = MoreLikeThisConfig
  60. export type CitationConfig = MoreLikeThisConfig
  61. export type ModerationContentConfig = {
  62. enabled: boolean
  63. preset_response?: string
  64. }
  65. export type ModerationConfig = MoreLikeThisConfig & {
  66. type?: string
  67. config?: {
  68. keywords?: string
  69. api_based_extension_id?: string
  70. inputs_config?: ModerationContentConfig
  71. outputs_config?: ModerationContentConfig
  72. } & Partial<Record<string, any>>
  73. }
  74. export type RetrieverResourceConfig = MoreLikeThisConfig
  75. // frontend use. Not the same as backend
  76. export type ModelConfig = {
  77. provider: string // LLM Provider: for example "OPENAI"
  78. model_id: string
  79. mode: ModelModeType
  80. configs: PromptConfig
  81. opening_statement: string | null
  82. more_like_this: MoreLikeThisConfig | null
  83. suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
  84. speech_to_text: SpeechToTextConfig | null
  85. retriever_resource: RetrieverResourceConfig | null
  86. sensitive_word_avoidance: ModerationConfig | null
  87. dataSets: any[]
  88. }
  89. export type DatasetConfigItem = {
  90. enable: boolean
  91. value: number
  92. }
  93. export type DatasetConfigs = {
  94. retrieval_model: RETRIEVE_TYPE
  95. reranking_model: {
  96. reranking_provider_name: string
  97. reranking_model_name: string
  98. }
  99. top_k: number
  100. score_threshold_enabled: boolean
  101. score_threshold: number
  102. }
  103. export type DebugRequestBody = {
  104. inputs: Inputs
  105. query: string
  106. completion_params: CompletionParams
  107. model_config: ModelConfig
  108. }
  109. export type DebugResponse = {
  110. id: string
  111. answer: string
  112. created_at: string
  113. }
  114. export type DebugResponseStream = {
  115. id: string
  116. data: string
  117. created_at: string
  118. }
  119. export type FeedBackRequestBody = {
  120. message_id: string
  121. rating: 'like' | 'dislike'
  122. content?: string
  123. from_source: 'api' | 'log'
  124. }
  125. export type FeedBackResponse = {
  126. message_id: string
  127. rating: 'like' | 'dislike'
  128. }
  129. // Log session list
  130. export type LogSessionListQuery = {
  131. keyword?: string
  132. start?: string // format datetime(YYYY-mm-dd HH:ii)
  133. end?: string // format datetime(YYYY-mm-dd HH:ii)
  134. page: number
  135. limit: number // default 20. 1-100
  136. }
  137. export type LogSessionListResponse = {
  138. data: {
  139. id: string
  140. conversation_id: string
  141. query: string // user's query question
  142. message: string // prompt send to LLM
  143. answer: string
  144. creat_at: string
  145. }[]
  146. total: number
  147. page: number
  148. }
  149. // log session detail and debug
  150. export type LogSessionDetailResponse = {
  151. id: string
  152. cnversation_id: string
  153. model_provider: string
  154. query: string
  155. inputs: Record<string, string | number | object>[]
  156. message: string
  157. message_tokens: number // number of tokens in message
  158. answer: string
  159. answer_tokens: number // number of tokens in answer
  160. provider_response_latency: number // used time in ms
  161. from_source: 'api' | 'log'
  162. }
  163. export type SavedMessage = {
  164. id: string
  165. answer: string
  166. }