debug.ts 5.2 KB

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