@visactor/vmind
Version:
<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu
71 lines (65 loc) • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.registerChartCommandAtom = exports.ChartCommandAtom = void 0;
const vutils_1 = require("@visactor/vutils"), types_1 = require("../../types"), base_1 = require("../base"), text_1 = require("../../utils/text"), prompt_1 = require("./prompt"), field_1 = require("../../utils/field"), common_1 = require("../../utils/common"), factory_1 = require("../../core/factory");
class ChartCommandAtom extends base_1.BaseAtom {
constructor(context, option) {
super(context, option), this.name = types_1.AtomName.CHART_COMMAND, this.isLLMAtom = !0;
}
buildDefaultOptions() {
return Object.assign(Object.assign({}, super.buildDefaultOptions()), {
useDataTable: !1
});
}
buildDefaultContext(context) {
return (0, vutils_1.merge)({}, {
command: ""
}, context);
}
shouldRunByContextUpdate(context) {
return context.text !== this.context.text || context.fieldInfo !== this.context.fieldInfo;
}
getLLMMessages(query) {
var _a, _b, _c;
const {fieldInfo: fieldInfo, text: text, dataTable: dataTable, summary: summary} = this.context, language = null !== (_b = null === (_a = this.options) || void 0 === _a ? void 0 : _a.language) && void 0 !== _b ? _b : (0,
text_1.getLanguageOfText)(text || summary), addtionContent = this.getHistoryLLMMessages(query);
return [ {
role: "system",
content: (0, prompt_1.getChartCommandPrompt)(language)
}, {
role: "user",
content: JSON.stringify({
userInput: [ {
text: text,
summary: summary,
fieldInfo: fieldInfo.map((info => {
var _a;
return {
fieldName: info.fieldName,
type: info.role || (0, field_1.getRoleByFieldType)(info.type),
dataLength: (null === (_a = null == dataTable ? void 0 : dataTable.filter((v => (0,
common_1.isValidData)(v[info.fieldName])))) || void 0 === _a ? void 0 : _a.length) || void 0
};
})),
dataTable: (null === (_c = this.options) || void 0 === _c ? void 0 : _c.useDataTable) ? JSON.stringify(dataTable) : void 0
} ]
})
}, ...addtionContent ];
}
parseLLMContent(resJson) {
const {commands: commands = []} = resJson, command = (null == commands ? void 0 : commands[0]) || "";
return !1 !== command && "false" !== command && command ? Object.assign(Object.assign({}, this.context), {
command: command
}) : (console.error("Can't generate chart command in this case"), Object.assign(Object.assign({}, this.context), {
command: "",
error: "Can't generate chart command in this case"
}));
}
}
exports.ChartCommandAtom = ChartCommandAtom;
const registerChartCommandAtom = () => {
factory_1.Factory.registerAtom(types_1.AtomName.CHART_COMMAND, ChartCommandAtom);
};
exports.registerChartCommandAtom = registerChartCommandAtom;
//# sourceMappingURL=index.js.map