UNPKG

@difizen/ai-flow

Version:

Scalable, out-of-the-box, agent-oriented flow

173 lines 10.6 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import { CollapseWrapper, SelectInNode } from "../../AIBasic"; import { OutputVariable } from "../../AIBasic/OutputVariableTree/OutputVariable"; import { PromptEditor } from "../../AIBasic/PromptEditor"; import { ReferenceForm } from "../../ReferenceForm"; import { useFlowStore } from "../../../stores/flowStore"; import { useModelStore } from "../../../stores/useModelStore"; import { BarsOutlined } from '@ant-design/icons'; import { Button, InputNumber, Popover } from 'antd'; import React, { memo, useMemo } from 'react'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; var Prompt = function Prompt(props) { var value = props.value, onChange = props.onChange, className = props.className, variables = props.variables; return /*#__PURE__*/_jsx(CollapseWrapper, { className: className, label: 'Prompt', children: /*#__PURE__*/_jsx("div", { className: "h-[200px] bg-white rounded-md cursor-pointer nodrag p-3 overflow-y-auto", children: /*#__PURE__*/_jsx(PromptEditor, { value: value, placeholder: "\u8BF7\u8F93\u5165 Prompt", onChange: onChange, variableBlock: { show: true, variables: variables } }) }) }); }; var PromptMemo = /*#__PURE__*/memo(Prompt, function (prevProps, nextProps) { return prevProps.value === nextProps.value && prevProps.variables === nextProps.variables; }); export var LLMPanel = function LLMPanel(props) { var _data$config, _data$config3, _data$config4, _llmParam$find, _data$config5; var data = props.data; var setNode = useFlowStore(function (state) { return state.setNode; }); var nodeLinkMap = useFlowStore(function (state) { return state.nodeLinkMap; }); var _useModelStore = useModelStore(), ModelSelector = _useModelStore.ModelSelector, modelOptions = _useModelStore.modelOptions, modelConfig = _useModelStore.modelConfig; var upstreamNodes = nodeLinkMap[data.id]; var llmParam = (_data$config = data.config) === null || _data$config === void 0 || (_data$config = _data$config.inputs) === null || _data$config === void 0 ? void 0 : _data$config['llm_param']; var variable = useMemo(function () { var _data$config2; return (_data$config2 = data.config) === null || _data$config2 === void 0 || (_data$config2 = _data$config2.inputs) === null || _data$config2 === void 0 ? void 0 : _data$config2.input_param.map(function (input) { return { name: input.name, value: input.name }; }); }, [(_data$config3 = data.config) === null || _data$config3 === void 0 || (_data$config3 = _data$config3.inputs) === null || _data$config3 === void 0 ? void 0 : _data$config3.input_param]); return /*#__PURE__*/_jsxs("div", { children: [/*#__PURE__*/_jsx(CollapseWrapper, { className: "mb-4", label: '模型配置', children: /*#__PURE__*/_jsx(_Fragment, { children: ModelSelector !== null ? /*#__PURE__*/_jsx(ModelSelector, { nodeId: data.id, llmParam: llmParam }) : /*#__PURE__*/_jsxs("div", { className: "flex", children: [/*#__PURE__*/_jsx(SelectInNode, { options: modelOptions.map(function (model) { return { label: model.name, value: model.id }; }), className: "w-full mr-2" }), /*#__PURE__*/_jsx(Popover, { title: "\u6A21\u578B\u914D\u7F6E", content: /*#__PURE__*/_jsx("div", { children: Object.entries(modelConfig).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; return /*#__PURE__*/_jsx("div", { children: /*#__PURE__*/_jsx(InputNumber, {}, value) }, key); }) }), children: Object.entries(modelConfig).length > 0 && /*#__PURE__*/_jsx(Button, { type: "text", icon: /*#__PURE__*/_jsx(BarsOutlined, {}) }) })] }) }) }), /*#__PURE__*/_jsx(ReferenceForm, { label: "\u8F93\u5165\u53D8\u91CF", dynamic: true, nodes: upstreamNodes, value: (_data$config4 = data.config) === null || _data$config4 === void 0 || (_data$config4 = _data$config4.inputs) === null || _data$config4 === void 0 ? void 0 : _data$config4.input_param, onChange: function onChange(values) { setNode(data.id, function (old) { return _objectSpread(_objectSpread({}, old), {}, { data: _objectSpread(_objectSpread({}, old.data), {}, { config: _objectSpread(_objectSpread({}, old.data['config']), {}, { inputs: _objectSpread(_objectSpread({}, old.data['config']['inputs']), {}, { input_param: _toConsumableArray(values) }) }) }) }); }); } }), /*#__PURE__*/_jsx(PromptMemo, { value: ((_llmParam$find = llmParam.find(function (item) { return item.name === 'prompt'; })) === null || _llmParam$find === void 0 || (_llmParam$find = _llmParam$find.value) === null || _llmParam$find === void 0 ? void 0 : _llmParam$find.content) || '', onChange: function onChange(values) { setNode(data.id, function (old) { return _objectSpread(_objectSpread({}, old), {}, { data: _objectSpread(_objectSpread({}, old.data), {}, { config: _objectSpread(_objectSpread({}, old.data['config']), {}, { inputs: _objectSpread(_objectSpread({}, old.data['config']['inputs']), {}, { llm_param: [].concat(_toConsumableArray(llmParam.filter(function (p) { return p.name !== 'prompt'; })), [{ name: 'prompt', type: 'string', value: { type: 'value', content: values } }]) }) }) }) }); }); }, variables: variable }), /*#__PURE__*/_jsx(CollapseWrapper, { className: "mt-3", label: 'Output', children: /*#__PURE__*/_jsx(_Fragment, { children: (((_data$config5 = data.config) === null || _data$config5 === void 0 ? void 0 : _data$config5.outputs) || []).map(function (output) { return /*#__PURE__*/_jsx(OutputVariable, { name: output.name, type: output.type }, output.name); }) }) })] }); };