| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  | import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem, TtsAutoPlay } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   RerankingModeEnum, | 
					
						
							| 
									
										
										
										
											2025-03-22 20:21:57 +08:00
										 |  |  |   WeightedScoreEnum, | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  | } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import type { FileUpload } from '@/app/components/base/features/types' | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   MetadataFilteringConditions, | 
					
						
							|  |  |  |   MetadataFilteringModeEnum, | 
					
						
							|  |  |  | } from '@/app/components/workflow/nodes/knowledge-retrieval/types' | 
					
						
							|  |  |  | import type { ModelConfig as NodeModelConfig } from '@/app/components/workflow/types' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export type Inputs = Record<string, string | number | object> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  | export enum PromptMode { | 
					
						
							|  |  |  |   simple = 'simple', | 
					
						
							|  |  |  |   advanced = 'advanced', | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type PromptItem = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   role?: PromptRole | 
					
						
							|  |  |  |   text: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type ChatPromptConfig = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   prompt: PromptItem[] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type ConversationHistoriesRole = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   user_prefix: string | 
					
						
							|  |  |  |   assistant_prefix: string | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type CompletionPromptConfig = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   prompt: PromptItem | 
					
						
							|  |  |  |   conversation_histories_role: ConversationHistoriesRole | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type BlockStatus = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   context: boolean | 
					
						
							|  |  |  |   history: boolean | 
					
						
							|  |  |  |   query: boolean | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export enum PromptRole { | 
					
						
							|  |  |  |   system = 'system', | 
					
						
							|  |  |  |   user = 'user', | 
					
						
							|  |  |  |   assistant = 'assistant', | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type PromptVariable = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   key: string | 
					
						
							|  |  |  |   name: string | 
					
						
							|  |  |  |   type: string // "string" | "number" | "select",
 | 
					
						
							|  |  |  |   default?: string | number | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   required?: boolean | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   options?: string[] | 
					
						
							|  |  |  |   max_length?: number | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |   is_context_var?: boolean | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   enabled?: boolean | 
					
						
							|  |  |  |   config?: Record<string, any> | 
					
						
							|  |  |  |   icon?: string | 
					
						
							|  |  |  |   icon_background?: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type CompletionParams = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   max_tokens: number | 
					
						
							|  |  |  |   temperature: number | 
					
						
							|  |  |  |   top_p: number | 
					
						
							|  |  |  |   presence_penalty: number | 
					
						
							|  |  |  |   frequency_penalty: number | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   stop?: string[] | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  | export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type PromptConfig = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   prompt_template: string | 
					
						
							|  |  |  |   prompt_variables: PromptVariable[] | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type MoreLikeThisConfig = { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   enabled: boolean | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 17:50:42 +08:00
										 |  |  | export type SpeechToTextConfig = MoreLikeThisConfig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type TextToSpeechConfig = { | 
					
						
							| 
									
										
										
										
											2024-02-15 22:41:18 +08:00
										 |  |  |   enabled: boolean | 
					
						
							|  |  |  |   voice?: string | 
					
						
							|  |  |  |   language?: string | 
					
						
							| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  |   autoPlay?: TtsAutoPlay | 
					
						
							| 
									
										
										
										
											2024-02-15 22:41:18 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-09 19:17:12 +08:00
										 |  |  | export type CitationConfig = MoreLikeThisConfig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type AnnotationReplyConfig = { | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   id: string | 
					
						
							|  |  |  |   enabled: boolean | 
					
						
							|  |  |  |   score_threshold: number | 
					
						
							|  |  |  |   embedding_model: { | 
					
						
							|  |  |  |     embedding_provider_name: string | 
					
						
							|  |  |  |     embedding_model_name: string | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type ModerationContentConfig = { | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   enabled: boolean | 
					
						
							|  |  |  |   preset_response?: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export type ModerationConfig = MoreLikeThisConfig & { | 
					
						
							|  |  |  |   type?: string | 
					
						
							|  |  |  |   config?: { | 
					
						
							|  |  |  |     keywords?: string | 
					
						
							|  |  |  |     api_based_extension_id?: string | 
					
						
							|  |  |  |     inputs_config?: ModerationContentConfig | 
					
						
							|  |  |  |     outputs_config?: ModerationContentConfig | 
					
						
							|  |  |  |   } & Partial<Record<string, any>> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  | export type RetrieverResourceConfig = MoreLikeThisConfig | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type AgentConfig = { | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   enabled: boolean | 
					
						
							|  |  |  |   strategy: AgentStrategy | 
					
						
							|  |  |  |   max_iteration: number | 
					
						
							|  |  |  |   tools: ToolItem[] | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | // frontend use. Not the same as backend
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type ModelConfig = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   provider: string // LLM Provider: for example "OPENAI"
 | 
					
						
							|  |  |  |   model_id: string | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   mode: ModelModeType | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   configs: PromptConfig | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   opening_statement: string | null | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |   more_like_this: MoreLikeThisConfig | null | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   suggested_questions: string[] | null | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |   suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null | 
					
						
							|  |  |  |   speech_to_text: SpeechToTextConfig | null | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  |   text_to_speech: TextToSpeechConfig | null | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   file_upload: FileUpload | null | 
					
						
							| 
									
										
										
										
											2023-09-11 09:30:17 +08:00
										 |  |  |   retriever_resource: RetrieverResourceConfig | null | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   sensitive_word_avoidance: ModerationConfig | null | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   annotation_reply: AnnotationReplyConfig | null | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   dataSets: any[] | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   agentConfig: AgentConfig | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type DatasetConfigItem = { | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   enable: boolean | 
					
						
							|  |  |  |   value: number | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type DatasetConfigs = { | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  |   retrieval_model: RETRIEVE_TYPE | 
					
						
							|  |  |  |   reranking_model: { | 
					
						
							|  |  |  |     reranking_provider_name: string | 
					
						
							|  |  |  |     reranking_model_name: string | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  |   top_k: number | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  |   score_threshold_enabled: boolean | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |   score_threshold: number | null | undefined | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   datasets: { | 
					
						
							|  |  |  |     datasets: { | 
					
						
							|  |  |  |       enabled: boolean | 
					
						
							|  |  |  |       id: string | 
					
						
							|  |  |  |     }[] | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |   reranking_mode?: RerankingModeEnum | 
					
						
							|  |  |  |   weights?: { | 
					
						
							| 
									
										
										
										
											2025-03-22 20:21:57 +08:00
										 |  |  |     weight_type: WeightedScoreEnum | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |     vector_setting: { | 
					
						
							|  |  |  |       vector_weight: number | 
					
						
							|  |  |  |       embedding_provider_name: string | 
					
						
							|  |  |  |       embedding_model_name: string | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     keyword_setting: { | 
					
						
							|  |  |  |       keyword_weight: number | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   reranking_enable?: boolean | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  |   metadata_filtering_mode?: MetadataFilteringModeEnum | 
					
						
							|  |  |  |   metadata_filtering_conditions?: MetadataFilteringConditions | 
					
						
							|  |  |  |   metadata_model_config?: NodeModelConfig | 
					
						
							| 
									
										
										
										
											2023-10-12 23:14:28 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type DebugRequestBody = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   inputs: Inputs | 
					
						
							|  |  |  |   query: string | 
					
						
							|  |  |  |   completion_params: CompletionParams | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   model_config: ModelConfig | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type DebugResponse = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   id: string | 
					
						
							|  |  |  |   answer: string | 
					
						
							|  |  |  |   created_at: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type DebugResponseStream = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   id: string | 
					
						
							|  |  |  |   data: string | 
					
						
							|  |  |  |   created_at: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type FeedBackRequestBody = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   message_id: string | 
					
						
							|  |  |  |   rating: 'like' | 'dislike' | 
					
						
							|  |  |  |   content?: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   from_source: 'api' | 'log' | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type FeedBackResponse = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   message_id: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   rating: 'like' | 'dislike' | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Log session list
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type LogSessionListQuery = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   keyword?: string | 
					
						
							|  |  |  |   start?: string // format datetime(YYYY-mm-dd HH:ii)
 | 
					
						
							|  |  |  |   end?: string // format datetime(YYYY-mm-dd HH:ii)
 | 
					
						
							|  |  |  |   page: number | 
					
						
							|  |  |  |   limit: number // default 20. 1-100
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type LogSessionListResponse = { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   data: { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |     id: string | 
					
						
							|  |  |  |     conversation_id: string | 
					
						
							|  |  |  |     query: string // user's query question
 | 
					
						
							|  |  |  |     message: string // prompt send to LLM
 | 
					
						
							|  |  |  |     answer: string | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |     created_at: string | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   }[] | 
					
						
							|  |  |  |   total: number | 
					
						
							|  |  |  |   page: number | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // log session detail and debug
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type LogSessionDetailResponse = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   id: string | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |   conversation_id: string | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   model_provider: string | 
					
						
							|  |  |  |   query: string | 
					
						
							|  |  |  |   inputs: Record<string, string | number | object>[] | 
					
						
							|  |  |  |   message: string | 
					
						
							|  |  |  |   message_tokens: number // number of tokens in message
 | 
					
						
							|  |  |  |   answer: string | 
					
						
							|  |  |  |   answer_tokens: number // number of tokens in answer
 | 
					
						
							|  |  |  |   provider_response_latency: number // used time in ms
 | 
					
						
							|  |  |  |   from_source: 'api' | 'log' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 11:01:06 +08:00
										 |  |  | export type SavedMessage = { | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  |   id: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   answer: string | 
					
						
							| 
									
										
										
										
											2023-06-06 14:58:56 +08:00
										 |  |  | } |