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.

flow.ts 3.6KB

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