debug.ts 4.8 KB

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