Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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