debug.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem, TtsAutoPlay } from '@/types/app'
  2. import type {
  3. RerankingModeEnum,
  4. WeightedScoreEnum,
  5. } from '@/models/datasets'
  6. export type Inputs = Record<string, string | number | object>
  7. export enum PromptMode {
  8. simple = 'simple',
  9. advanced = 'advanced',
  10. }
  11. export type PromptItem = {
  12. role?: PromptRole
  13. text: string
  14. }
  15. export type ChatPromptConfig = {
  16. prompt: PromptItem[]
  17. }
  18. export type ConversationHistoriesRole = {
  19. user_prefix: string
  20. assistant_prefix: string
  21. }
  22. export type CompletionPromptConfig = {
  23. prompt: PromptItem
  24. conversation_histories_role: ConversationHistoriesRole
  25. }
  26. export type BlockStatus = {
  27. context: boolean
  28. history: boolean
  29. query: boolean
  30. }
  31. export enum PromptRole {
  32. system = 'system',
  33. user = 'user',
  34. assistant = 'assistant',
  35. }
  36. export type PromptVariable = {
  37. key: string
  38. name: string
  39. type: string // "string" | "number" | "select",
  40. default?: string | number
  41. required?: boolean
  42. options?: string[]
  43. max_length?: number
  44. is_context_var?: boolean
  45. enabled?: boolean
  46. config?: Record<string, any>
  47. icon?: string
  48. icon_background?: string
  49. }
  50. export type CompletionParams = {
  51. max_tokens: number
  52. temperature: number
  53. top_p: number
  54. presence_penalty: number
  55. frequency_penalty: number
  56. stop?: string[]
  57. }
  58. export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
  59. export type PromptConfig = {
  60. prompt_template: string
  61. prompt_variables: PromptVariable[]
  62. }
  63. export type MoreLikeThisConfig = {
  64. enabled: boolean
  65. }
  66. export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
  67. export type SpeechToTextConfig = MoreLikeThisConfig
  68. export type TextToSpeechConfig = {
  69. enabled: boolean
  70. voice?: string
  71. language?: string
  72. autoPlay?: TtsAutoPlay
  73. }
  74. export type CitationConfig = MoreLikeThisConfig
  75. export type AnnotationReplyConfig = {
  76. id: string
  77. enabled: boolean
  78. score_threshold: number
  79. embedding_model: {
  80. embedding_provider_name: string
  81. embedding_model_name: string
  82. }
  83. }
  84. export type ModerationContentConfig = {
  85. enabled: boolean
  86. preset_response?: string
  87. }
  88. export type ModerationConfig = MoreLikeThisConfig & {
  89. type?: string
  90. config?: {
  91. keywords?: string
  92. api_based_extension_id?: string
  93. inputs_config?: ModerationContentConfig
  94. outputs_config?: ModerationContentConfig
  95. } & Partial<Record<string, any>>
  96. }
  97. export type RetrieverResourceConfig = MoreLikeThisConfig
  98. export type AgentConfig = {
  99. enabled: boolean
  100. strategy: AgentStrategy
  101. max_iteration: number
  102. tools: ToolItem[]
  103. }
  104. // frontend use. Not the same as backend
  105. export type ModelConfig = {
  106. provider: string // LLM Provider: for example "OPENAI"
  107. model_id: string
  108. mode: ModelModeType
  109. configs: PromptConfig
  110. opening_statement: string | null
  111. more_like_this: MoreLikeThisConfig | null
  112. suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
  113. speech_to_text: SpeechToTextConfig | null
  114. text_to_speech: TextToSpeechConfig | null
  115. retriever_resource: RetrieverResourceConfig | null
  116. sensitive_word_avoidance: ModerationConfig | null
  117. dataSets: any[]
  118. agentConfig: AgentConfig
  119. }
  120. export type DatasetConfigItem = {
  121. enable: boolean
  122. value: number
  123. }
  124. export type DatasetConfigs = {
  125. retrieval_model: RETRIEVE_TYPE
  126. reranking_model: {
  127. reranking_provider_name: string
  128. reranking_model_name: string
  129. }
  130. top_k: number
  131. score_threshold_enabled: boolean
  132. score_threshold: number | null | undefined
  133. datasets: {
  134. datasets: {
  135. enabled: boolean
  136. id: string
  137. }[]
  138. }
  139. reranking_mode?: RerankingModeEnum
  140. weights?: {
  141. weight_type: WeightedScoreEnum
  142. vector_setting: {
  143. vector_weight: number
  144. embedding_provider_name: string
  145. embedding_model_name: string
  146. }
  147. keyword_setting: {
  148. keyword_weight: number
  149. }
  150. }
  151. reranking_enable?: boolean
  152. }
  153. export type DebugRequestBody = {
  154. inputs: Inputs
  155. query: string
  156. completion_params: CompletionParams
  157. model_config: ModelConfig
  158. }
  159. export type DebugResponse = {
  160. id: string
  161. answer: string
  162. created_at: string
  163. }
  164. export type DebugResponseStream = {
  165. id: string
  166. data: string
  167. created_at: string
  168. }
  169. export type FeedBackRequestBody = {
  170. message_id: string
  171. rating: 'like' | 'dislike'
  172. content?: string
  173. from_source: 'api' | 'log'
  174. }
  175. export type FeedBackResponse = {
  176. message_id: string
  177. rating: 'like' | 'dislike'
  178. }
  179. // Log session list
  180. export type LogSessionListQuery = {
  181. keyword?: string
  182. start?: string // format datetime(YYYY-mm-dd HH:ii)
  183. end?: string // format datetime(YYYY-mm-dd HH:ii)
  184. page: number
  185. limit: number // default 20. 1-100
  186. }
  187. export type LogSessionListResponse = {
  188. data: {
  189. id: string
  190. conversation_id: string
  191. query: string // user's query question
  192. message: string // prompt send to LLM
  193. answer: string
  194. creat_at: string
  195. }[]
  196. total: number
  197. page: number
  198. }
  199. // log session detail and debug
  200. export type LogSessionDetailResponse = {
  201. id: string
  202. cnversation_id: string
  203. model_provider: string
  204. query: string
  205. inputs: Record<string, string | number | object>[]
  206. message: string
  207. message_tokens: number // number of tokens in message
  208. answer: string
  209. answer_tokens: number // number of tokens in answer
  210. provider_response_latency: number // used time in ms
  211. from_source: 'api' | 'log'
  212. }
  213. export type SavedMessage = {
  214. id: string
  215. answer: string
  216. }