You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { Edge, Node } from '@xyflow/react';
  2. import { IReference, Message } from './chat';
  3. export type DSLComponents = Record<string, IOperator>;
  4. export interface DSL {
  5. components: DSLComponents;
  6. history: any[];
  7. path?: string[][];
  8. answer?: any[];
  9. graph?: IGraph;
  10. messages: Message[];
  11. reference: IReference[];
  12. globals: Record<string, any>;
  13. retrieval: IReference[];
  14. }
  15. export interface IOperator {
  16. obj: IOperatorNode;
  17. downstream: string[];
  18. upstream: string[];
  19. parent_id?: string;
  20. }
  21. export interface IOperatorNode {
  22. component_name: string;
  23. params: Record<string, unknown>;
  24. }
  25. export declare interface IFlow {
  26. avatar?: string;
  27. canvas_type: null;
  28. create_date: string;
  29. create_time: number;
  30. description: string;
  31. dsl: DSL;
  32. id: string;
  33. title: string;
  34. update_date: string;
  35. update_time: number;
  36. user_id: string;
  37. permission: string;
  38. nickname: string;
  39. }
  40. export interface IFlowTemplate {
  41. avatar: string;
  42. canvas_type: string;
  43. create_date: string;
  44. create_time: number;
  45. description: string;
  46. dsl: DSL;
  47. id: string;
  48. title: string;
  49. update_date: string;
  50. update_time: number;
  51. }
  52. export type ICategorizeItemResult = Record<
  53. string,
  54. Omit<ICategorizeItem, 'name'>
  55. >;
  56. export interface IGenerateForm {
  57. max_tokens?: number;
  58. temperature?: number;
  59. top_p?: number;
  60. presence_penalty?: number;
  61. frequency_penalty?: number;
  62. cite?: boolean;
  63. prompt: number;
  64. llm_id: string;
  65. parameters: { key: string; component_id: string };
  66. }
  67. export interface ICategorizeItem {
  68. name: string;
  69. description?: string;
  70. examples?: string;
  71. to?: string;
  72. index: number;
  73. }
  74. export interface ICategorizeForm extends IGenerateForm {
  75. category_description: ICategorizeItemResult;
  76. }
  77. export interface IRelevantForm extends IGenerateForm {
  78. yes: string;
  79. no: string;
  80. }
  81. export interface ISwitchCondition {
  82. items: ISwitchItem[];
  83. logical_operator: string;
  84. to: string[] | string;
  85. }
  86. export interface ISwitchItem {
  87. cpn_id: string;
  88. operator: string;
  89. value: string;
  90. }
  91. export interface ISwitchForm {
  92. conditions: ISwitchCondition[];
  93. end_cpn_id: string;
  94. no: string;
  95. }
  96. export interface IBeginForm {
  97. prologue?: string;
  98. }
  99. export interface IRetrievalForm {
  100. similarity_threshold?: number;
  101. keywords_similarity_weight?: number;
  102. top_n?: number;
  103. top_k?: number;
  104. rerank_id?: string;
  105. empty_response?: string;
  106. kb_ids: string[];
  107. }
  108. export interface ICodeForm {
  109. inputs?: Array<{ name?: string; component_id?: string }>;
  110. lang: string;
  111. script?: string;
  112. }
  113. export type BaseNodeData<TForm extends any> = {
  114. label: string; // operator type
  115. name: string; // operator name
  116. color?: string;
  117. form?: TForm;
  118. };
  119. export type BaseNode<T = any> = Node<BaseNodeData<T>>;
  120. export type IBeginNode = BaseNode<IBeginForm>;
  121. export type IRetrievalNode = BaseNode<IRetrievalForm>;
  122. export type IGenerateNode = BaseNode<IGenerateForm>;
  123. export type ICategorizeNode = BaseNode<ICategorizeForm>;
  124. export type ISwitchNode = BaseNode<ISwitchForm>;
  125. export type IRagNode = BaseNode;
  126. export type IRelevantNode = BaseNode;
  127. export type ILogicNode = BaseNode;
  128. export type INoteNode = BaseNode;
  129. export type IMessageNode = BaseNode;
  130. export type IRewriteNode = BaseNode;
  131. export type IInvokeNode = BaseNode;
  132. export type ITemplateNode = BaseNode;
  133. export type IEmailNode = BaseNode;
  134. export type IIterationNode = BaseNode;
  135. export type IIterationStartNode = BaseNode;
  136. export type IKeywordNode = BaseNode;
  137. export type ICodeNode = BaseNode<ICodeForm>;
  138. export type IAgentNode = BaseNode;
  139. export type RAGFlowNodeType =
  140. | IBeginNode
  141. | IRetrievalNode
  142. | IGenerateNode
  143. | ICategorizeNode
  144. | ISwitchNode
  145. | IRagNode
  146. | IRelevantNode
  147. | ILogicNode
  148. | INoteNode
  149. | IMessageNode
  150. | IRewriteNode
  151. | IInvokeNode
  152. | ITemplateNode
  153. | IEmailNode
  154. | IIterationNode
  155. | IIterationStartNode
  156. | IKeywordNode;
  157. export interface IGraph {
  158. nodes: RAGFlowNodeType[];
  159. edges: Edge[];
  160. }