debug.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import type { ModelModeType } 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. top_k: number
  95. score_threshold: DatasetConfigItem
  96. }
  97. export type DebugRequestBody = {
  98. inputs: Inputs
  99. query: string
  100. completion_params: CompletionParams
  101. model_config: ModelConfig
  102. }
  103. export type DebugResponse = {
  104. id: string
  105. answer: string
  106. created_at: string
  107. }
  108. export type DebugResponseStream = {
  109. id: string
  110. data: string
  111. created_at: string
  112. }
  113. export type FeedBackRequestBody = {
  114. message_id: string
  115. rating: 'like' | 'dislike'
  116. content?: string
  117. from_source: 'api' | 'log'
  118. }
  119. export type FeedBackResponse = {
  120. message_id: string
  121. rating: 'like' | 'dislike'
  122. }
  123. // Log session list
  124. export type LogSessionListQuery = {
  125. keyword?: string
  126. start?: string // format datetime(YYYY-mm-dd HH:ii)
  127. end?: string // format datetime(YYYY-mm-dd HH:ii)
  128. page: number
  129. limit: number // default 20. 1-100
  130. }
  131. export type LogSessionListResponse = {
  132. data: {
  133. id: string
  134. conversation_id: string
  135. query: string // user's query question
  136. message: string // prompt send to LLM
  137. answer: string
  138. creat_at: string
  139. }[]
  140. total: number
  141. page: number
  142. }
  143. // log session detail and debug
  144. export type LogSessionDetailResponse = {
  145. id: string
  146. cnversation_id: string
  147. model_provider: string
  148. query: string
  149. inputs: Record<string, string | number | object>[]
  150. message: string
  151. message_tokens: number // number of tokens in message
  152. answer: string
  153. answer_tokens: number // number of tokens in answer
  154. provider_response_latency: number // used time in ms
  155. from_source: 'api' | 'log'
  156. }
  157. export type SavedMessage = {
  158. id: string
  159. answer: string
  160. }