@difizen/libro-prompt-cell 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/libro-formatter-prompt-magic-contribution.js +1 -1
- package/es/module.d.ts.map +1 -1
- package/es/module.js +2 -1
- package/es/prompt-cell-script.d.ts +2 -2
- package/es/prompt-cell-script.d.ts.map +1 -1
- package/es/prompt-cell-script.js +12 -4
- package/es/prompt-cell-view.d.ts +12 -8
- package/es/prompt-cell-view.d.ts.map +1 -1
- package/es/prompt-cell-view.js +115 -82
- package/package.json +7 -7
- package/src/libro-formatter-prompt-magic-contribution.ts +1 -1
- package/src/module.ts +2 -0
- package/src/prompt-cell-script.ts +6 -3
- package/src/prompt-cell-view.tsx +51 -31
|
@@ -24,7 +24,7 @@ export var FormatterPromptMagicContribution = (_dec = singleton({
|
|
|
24
24
|
};
|
|
25
25
|
this.encode = function (source) {
|
|
26
26
|
var promptObj = {
|
|
27
|
-
model_name: source.modelType || '
|
|
27
|
+
model_name: source.modelType || 'chatgpt',
|
|
28
28
|
prompt: source.value
|
|
29
29
|
};
|
|
30
30
|
var encodeValue = "%%prompt \n".concat(JSON.stringify(promptObj));
|
package/es/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAY/C,eAAO,MAAM,qBAAqB,YAyB2B,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -7,9 +7,10 @@ import { PromptCellContribution } from "./prompt-cell-contribution.js";
|
|
|
7
7
|
import { LibroPromptCellModel } from "./prompt-cell-model.js";
|
|
8
8
|
import { LibroPromptOutputArea } from "./prompt-cell-output-area.js";
|
|
9
9
|
import { LibroPromptCellModelFactory } from "./prompt-cell-protocol.js";
|
|
10
|
+
import { PromptScript } from "./prompt-cell-script.js";
|
|
10
11
|
import { LibroPromptCellView } from "./prompt-cell-view.js";
|
|
11
12
|
import { LibroPromptOutputMimeTypeContribution } from "./prompt-output-rendermime-contribution.js";
|
|
12
|
-
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, LibroPromptCellCommandContribution, FormatterPromptMagicContribution, {
|
|
13
|
+
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, PromptScript, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, LibroPromptCellCommandContribution, FormatterPromptMagicContribution, {
|
|
13
14
|
token: LibroPromptCellModelFactory,
|
|
14
15
|
useFactory: function useFactory(ctx) {
|
|
15
16
|
return function (options) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
1
|
+
export declare class PromptScript {
|
|
2
|
+
readonly toList = "from libro_server import chat_provider\nchat_provider.dump_list_json()";
|
|
3
3
|
}
|
|
4
4
|
//# sourceMappingURL=prompt-cell-script.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cell-script.d.ts","sourceRoot":"","sources":["../src/prompt-cell-script.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt-cell-script.d.ts","sourceRoot":"","sources":["../src/prompt-cell-script.ts"],"names":[],"mappings":"AAEA,qBACa,YAAY;IACvB,SAAgB,MAAM,4EACQ;CAC/B"}
|
package/es/prompt-cell-script.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
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); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
import { singleton } from '@difizen/mana-app';
|
|
9
|
+
export var PromptScript = (_dec = singleton(), _dec(_class = /*#__PURE__*/_createClass(function PromptScript() {
|
|
10
|
+
_classCallCheck(this, PromptScript);
|
|
11
|
+
this.toList = "from libro_server import chat_provider\nchat_provider.dump_list_json()";
|
|
12
|
+
})) || _class);
|
package/es/prompt-cell-view.d.ts
CHANGED
|
@@ -8,20 +8,19 @@ import { ViewManager } from '@difizen/mana-app';
|
|
|
8
8
|
import { Deferred } from '@difizen/mana-app';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import type { LibroPromptCellModel } from './prompt-cell-model.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export interface IModelItem {
|
|
16
|
-
value: string;
|
|
11
|
+
import { PromptScript } from './prompt-cell-script.js';
|
|
12
|
+
export interface IChatSelectionItem {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
17
15
|
}
|
|
18
16
|
export declare const CellEditorMemo: React.NamedExoticComponent<{}>;
|
|
19
17
|
export declare class LibroPromptCellView extends LibroExecutableCellView {
|
|
20
18
|
view: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
|
|
21
19
|
model: LibroPromptCellModel;
|
|
22
|
-
|
|
20
|
+
selection: IChatSelectionItem[];
|
|
23
21
|
viewManager: ViewManager;
|
|
24
22
|
codeEditorManager: CodeEditorManager;
|
|
23
|
+
promptScript: PromptScript;
|
|
25
24
|
outputs: IOutput[];
|
|
26
25
|
libroViewTracker: LibroViewTracker;
|
|
27
26
|
editorView?: CodeEditorView;
|
|
@@ -29,7 +28,7 @@ export declare class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
29
28
|
get outputAreaReady(): Promise<LibroOutputArea>;
|
|
30
29
|
protected editorViewReadyDeferred: Deferred<void>;
|
|
31
30
|
get editorReady(): Promise<void>;
|
|
32
|
-
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker
|
|
31
|
+
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker);
|
|
33
32
|
outputWatch(): void;
|
|
34
33
|
toJSON(): LibroCell;
|
|
35
34
|
onViewMount(): void;
|
|
@@ -47,6 +46,11 @@ export declare class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
47
46
|
};
|
|
48
47
|
run(): Promise<boolean>;
|
|
49
48
|
fetch: (content: KernelMessage.IExecuteRequestMsg['content'], ioCallback: (msg: KernelMessage.IIOPubMessage) => any) => Promise<KernelMessage.IExecuteReplyMsg>;
|
|
49
|
+
updateChatList: () => Promise<KernelMessage.IExecuteReplyMsg>;
|
|
50
|
+
toSelectionOption: (item: IChatSelectionItem) => {
|
|
51
|
+
value: string;
|
|
52
|
+
label: import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
};
|
|
50
54
|
handleQueryResponse: (response: KernelMessage.IIOPubMessage) => void;
|
|
51
55
|
}
|
|
52
56
|
//# sourceMappingURL=prompt-cell-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAQL,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAQL,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAmCD,eAAO,MAAM,cAAc,gCAAyB,CAAC;AAgErD,qBAEa,mBAAoB,SAAQ,uBAAuB;IACrD,IAAI,uEAA6B;IAElC,KAAK,EAAE,oBAAoB,CAAC;IAGpC,SAAS,EAAE,kBAAkB,EAAE,CAAM;IAErC,WAAW,EAAE,WAAW,CAAC;IAEE,iBAAiB,EAAE,iBAAiB,CAAC;IAC1C,YAAY,EAAE,YAAY,CAAC;IAEjD,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,gBAAgB,EAAE,gBAAgB,CAAC;IAGnC,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAED,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;gBAGqB,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACnB,gBAAgB,EAAE,gBAAgB;IA+BrD,WAAW;IAQX,MAAM,IAAI,SAAS;IASnB,WAAW;IAQpB,SAAS,CAAC,eAAe,IAAI,qBAAqB;IAY5C,YAAY;cAmBF,gBAAgB;IAUvB,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAQtD,IAAI,aAGX;IAEO,KAAK,WAAY,OAAO,UAqC/B;IAEO,cAAc,aAGrB;IAEF,aAAa,QAAO,EAAE,CAEpB;IAEF,qBAAqB,cAAe,MAAM;;;MAKxC;IAEa,GAAG;IA4ElB,KAAK,YACM,cAAc,kBAAkB,CAAC,SAAS,CAAC,oBAClC,cAAc,aAAa,KAAK,GAAG,6CAUrD;IAEF,cAAc,gDAKZ;IAEF,iBAAiB,SAAU,kBAAkB;;;MAK3C;IAEF,mBAAmB,aAAc,cAAc,aAAa,UA4B1D;CACH"}
|
package/es/prompt-cell-view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
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); }
|
|
2
|
-
var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2;
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
|
|
3
3
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
4
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
5
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -35,12 +35,32 @@ import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker
|
|
|
35
35
|
import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
|
|
36
36
|
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
|
|
37
37
|
import { Deferred } from '@difizen/mana-app';
|
|
38
|
-
import { Select } from 'antd';
|
|
38
|
+
import { Select, Tag } from 'antd';
|
|
39
39
|
import React, { useEffect, useState } from 'react';
|
|
40
40
|
import { PromptScript } from "./prompt-cell-script.js";
|
|
41
41
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
42
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
43
42
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
43
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
44
|
+
var SelectionItemLabel = function SelectionItemLabel(props) {
|
|
45
|
+
var item = props.item;
|
|
46
|
+
var colorMap = {
|
|
47
|
+
VARIABLE: 'red',
|
|
48
|
+
LLM: 'blue',
|
|
49
|
+
API: 'green',
|
|
50
|
+
CUSTOM: undefined
|
|
51
|
+
};
|
|
52
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
53
|
+
className: "libro-prompt-cell-selection-label",
|
|
54
|
+
children: [/*#__PURE__*/_jsx(Tag, {
|
|
55
|
+
color: colorMap[item.type] || undefined,
|
|
56
|
+
className: "libro-prompt-cell-header-selection-type",
|
|
57
|
+
children: item.type
|
|
58
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
59
|
+
className: "libro-prompt-cell-header-selection-name",
|
|
60
|
+
children: item.name
|
|
61
|
+
})]
|
|
62
|
+
});
|
|
63
|
+
};
|
|
44
64
|
var CellEditor = function CellEditor() {
|
|
45
65
|
var _instance$editorView3;
|
|
46
66
|
var instance = useInject(ViewInstance);
|
|
@@ -65,14 +85,11 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
65
85
|
selectedModel = _useState2[0],
|
|
66
86
|
setSelectedModel = _useState2[1];
|
|
67
87
|
useEffect(function () {
|
|
68
|
-
instance.
|
|
69
|
-
|
|
70
|
-
store_history: false
|
|
71
|
-
}, instance.handleQueryResponse).then(function () {
|
|
72
|
-
var len = instance.modelSelection.length;
|
|
88
|
+
instance.updateChatList().then(function () {
|
|
89
|
+
var len = instance.selection.length;
|
|
73
90
|
if (len > 0) {
|
|
74
91
|
instance.model.decodeObject = _objectSpread({
|
|
75
|
-
modelType: instance.
|
|
92
|
+
modelType: instance.selection[len - 1].name
|
|
76
93
|
}, instance.model.decodeObject);
|
|
77
94
|
setSelectedModel(instance.model.decodeObject['modelType']);
|
|
78
95
|
instance.model.modelType = instance.model.decodeObject['modelType'];
|
|
@@ -106,17 +123,14 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
106
123
|
width: 160
|
|
107
124
|
},
|
|
108
125
|
onChange: handleChange,
|
|
109
|
-
options: instance.
|
|
126
|
+
options: instance.selection.map(instance.toSelectionOption),
|
|
110
127
|
bordered: false,
|
|
111
128
|
onFocus: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
112
129
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
113
130
|
while (1) switch (_context.prev = _context.next) {
|
|
114
131
|
case 0:
|
|
115
132
|
_context.next = 2;
|
|
116
|
-
return instance.
|
|
117
|
-
code: PromptScript.get_models,
|
|
118
|
-
store_history: false
|
|
119
|
-
}, instance.handleQueryResponse);
|
|
133
|
+
return instance.updateChatList();
|
|
120
134
|
case 2:
|
|
121
135
|
case "end":
|
|
122
136
|
return _context.stop();
|
|
@@ -128,21 +142,22 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
128
142
|
}), /*#__PURE__*/_jsx(CellEditorMemo, {})]
|
|
129
143
|
});
|
|
130
144
|
});
|
|
131
|
-
export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
|
|
145
|
+
export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = prop(), _dec4 = inject(CodeEditorManager), _dec5 = inject(PromptScript), _dec6 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
|
|
132
146
|
_inherits(LibroPromptCellView, _LibroExecutableCellV);
|
|
133
147
|
var _super = _createSuper(LibroPromptCellView);
|
|
134
|
-
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker
|
|
148
|
+
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker) {
|
|
135
149
|
var _options$cell;
|
|
136
150
|
var _this;
|
|
137
151
|
_classCallCheck(this, LibroPromptCellView);
|
|
138
152
|
_this = _super.call(this, options, cellService);
|
|
139
153
|
_this.view = PropmtEditorViewComponent;
|
|
140
|
-
_initializerDefineProperty(_this, "
|
|
154
|
+
_initializerDefineProperty(_this, "selection", _descriptor, _assertThisInitialized(_this));
|
|
141
155
|
_this.viewManager = void 0;
|
|
142
|
-
_this
|
|
156
|
+
_initializerDefineProperty(_this, "codeEditorManager", _descriptor2, _assertThisInitialized(_this));
|
|
157
|
+
_initializerDefineProperty(_this, "promptScript", _descriptor3, _assertThisInitialized(_this));
|
|
143
158
|
_this.outputs = void 0;
|
|
144
159
|
_this.libroViewTracker = void 0;
|
|
145
|
-
_initializerDefineProperty(_this, "editorView",
|
|
160
|
+
_initializerDefineProperty(_this, "editorView", _descriptor4, _assertThisInitialized(_this));
|
|
146
161
|
_this.outputAreaDeferred = new Deferred();
|
|
147
162
|
_this.editorViewReadyDeferred = new Deferred();
|
|
148
163
|
_this.blur = function () {
|
|
@@ -247,6 +262,28 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
247
262
|
return _ref3.apply(this, arguments);
|
|
248
263
|
};
|
|
249
264
|
}();
|
|
265
|
+
_this.updateChatList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
266
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
267
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
268
|
+
case 0:
|
|
269
|
+
return _context4.abrupt("return", _this.fetch({
|
|
270
|
+
code: _this.promptScript.toList,
|
|
271
|
+
store_history: false
|
|
272
|
+
}, _this.handleQueryResponse));
|
|
273
|
+
case 1:
|
|
274
|
+
case "end":
|
|
275
|
+
return _context4.stop();
|
|
276
|
+
}
|
|
277
|
+
}, _callee4);
|
|
278
|
+
}));
|
|
279
|
+
_this.toSelectionOption = function (item) {
|
|
280
|
+
return {
|
|
281
|
+
value: item.name,
|
|
282
|
+
label: /*#__PURE__*/_jsx(SelectionItemLabel, {
|
|
283
|
+
item: item
|
|
284
|
+
})
|
|
285
|
+
};
|
|
286
|
+
};
|
|
250
287
|
_this.handleQueryResponse = function (response) {
|
|
251
288
|
var msgType = response.header.msg_type;
|
|
252
289
|
switch (msgType) {
|
|
@@ -258,13 +295,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
258
295
|
content = content.slice(1, -1);
|
|
259
296
|
content = content.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
260
297
|
}
|
|
261
|
-
|
|
262
|
-
_this.modelSelection = update.map(function (item) {
|
|
263
|
-
return {
|
|
264
|
-
value: item,
|
|
265
|
-
label: item
|
|
266
|
-
};
|
|
267
|
-
});
|
|
298
|
+
_this.selection = JSON.parse(content);
|
|
268
299
|
break;
|
|
269
300
|
}
|
|
270
301
|
case 'stream':
|
|
@@ -275,13 +306,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
275
306
|
contentStream = contentStream.slice(1, -1);
|
|
276
307
|
contentStream = contentStream.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
277
308
|
}
|
|
278
|
-
|
|
279
|
-
_this.modelSelection = updateStream.map(function (item) {
|
|
280
|
-
return {
|
|
281
|
-
value: item,
|
|
282
|
-
label: item
|
|
283
|
-
};
|
|
284
|
-
});
|
|
309
|
+
_this.selection = JSON.parse(contentStream);
|
|
285
310
|
break;
|
|
286
311
|
}
|
|
287
312
|
default:
|
|
@@ -291,7 +316,6 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
291
316
|
_this.options = options;
|
|
292
317
|
_this.viewManager = viewManager;
|
|
293
318
|
_this.className = _this.className + ' prompt';
|
|
294
|
-
_this.codeEditorManager = codeEditorManager;
|
|
295
319
|
_this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
|
|
296
320
|
_this.libroViewTracker = libroViewTracker;
|
|
297
321
|
|
|
@@ -300,38 +324,37 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
300
324
|
cellId: _this.id,
|
|
301
325
|
cell: _assertThisInitialized(_this)
|
|
302
326
|
}).then( /*#__PURE__*/function () {
|
|
303
|
-
var
|
|
327
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(outputArea) {
|
|
304
328
|
var output;
|
|
305
|
-
return _regeneratorRuntime().wrap(function
|
|
306
|
-
while (1) switch (
|
|
329
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
330
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
307
331
|
case 0:
|
|
308
332
|
_this.outputArea = outputArea;
|
|
309
333
|
output = _this.outputs;
|
|
310
334
|
if (!isOutput(output)) {
|
|
311
|
-
|
|
335
|
+
_context5.next = 5;
|
|
312
336
|
break;
|
|
313
337
|
}
|
|
314
|
-
|
|
338
|
+
_context5.next = 5;
|
|
315
339
|
return _this.outputArea.fromJSON(output);
|
|
316
340
|
case 5:
|
|
317
341
|
_this.outputAreaDeferred.resolve(outputArea);
|
|
318
342
|
_this.outputWatch();
|
|
319
|
-
return
|
|
343
|
+
return _context5.abrupt("return");
|
|
320
344
|
case 8:
|
|
321
345
|
case "end":
|
|
322
|
-
return
|
|
346
|
+
return _context5.stop();
|
|
323
347
|
}
|
|
324
|
-
},
|
|
348
|
+
}, _callee5);
|
|
325
349
|
}));
|
|
326
350
|
return function (_x3) {
|
|
327
|
-
return
|
|
351
|
+
return _ref5.apply(this, arguments);
|
|
328
352
|
};
|
|
329
353
|
}()).catch(function () {
|
|
330
354
|
//
|
|
331
355
|
});
|
|
332
356
|
return _this;
|
|
333
357
|
}
|
|
334
|
-
LibroPromptCellView = inject(CodeEditorManager)(LibroPromptCellView, undefined, 4) || LibroPromptCellView;
|
|
335
358
|
LibroPromptCellView = inject(LibroViewTracker)(LibroPromptCellView, undefined, 3) || LibroPromptCellView;
|
|
336
359
|
LibroPromptCellView = inject(ViewManager)(LibroPromptCellView, undefined, 2) || LibroPromptCellView;
|
|
337
360
|
LibroPromptCellView = inject(CellService)(LibroPromptCellView, undefined, 1) || LibroPromptCellView;
|
|
@@ -391,36 +414,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
391
414
|
}, {
|
|
392
415
|
key: "createEditor",
|
|
393
416
|
value: function () {
|
|
394
|
-
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
417
|
+
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
395
418
|
var option, editorView;
|
|
396
|
-
return _regeneratorRuntime().wrap(function
|
|
397
|
-
while (1) switch (
|
|
419
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
420
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
398
421
|
case 0:
|
|
399
422
|
option = this.getEditorOption();
|
|
400
423
|
this.editorStatus = EditorStatus.LOADING;
|
|
401
424
|
|
|
402
425
|
// 防止虚拟滚动中编辑器被频繁创建
|
|
403
426
|
if (!this.editorView) {
|
|
404
|
-
|
|
427
|
+
_context6.next = 5;
|
|
405
428
|
break;
|
|
406
429
|
}
|
|
407
430
|
this.editorStatus = EditorStatus.LOADED;
|
|
408
|
-
return
|
|
431
|
+
return _context6.abrupt("return");
|
|
409
432
|
case 5:
|
|
410
|
-
|
|
433
|
+
_context6.next = 7;
|
|
411
434
|
return this.codeEditorManager.getOrCreateEditorView(option);
|
|
412
435
|
case 7:
|
|
413
|
-
editorView =
|
|
436
|
+
editorView = _context6.sent;
|
|
414
437
|
this.editorView = editorView;
|
|
415
438
|
this.editorViewReadyDeferred.resolve();
|
|
416
439
|
this.editorStatus = EditorStatus.LOADED;
|
|
417
|
-
|
|
440
|
+
_context6.next = 13;
|
|
418
441
|
return this.afterEditorReady();
|
|
419
442
|
case 13:
|
|
420
443
|
case "end":
|
|
421
|
-
return
|
|
444
|
+
return _context6.stop();
|
|
422
445
|
}
|
|
423
|
-
},
|
|
446
|
+
}, _callee6, this);
|
|
424
447
|
}));
|
|
425
448
|
function createEditor() {
|
|
426
449
|
return _createEditor.apply(this, arguments);
|
|
@@ -430,11 +453,11 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
430
453
|
}, {
|
|
431
454
|
key: "afterEditorReady",
|
|
432
455
|
value: function () {
|
|
433
|
-
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
456
|
+
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
434
457
|
var _this3 = this,
|
|
435
458
|
_this$editorView9;
|
|
436
|
-
return _regeneratorRuntime().wrap(function
|
|
437
|
-
while (1) switch (
|
|
459
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
460
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
438
461
|
case 0:
|
|
439
462
|
watch(this.parent.model, 'readOnly', function () {
|
|
440
463
|
var _this3$editorView;
|
|
@@ -445,9 +468,9 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
445
468
|
});
|
|
446
469
|
case 2:
|
|
447
470
|
case "end":
|
|
448
|
-
return
|
|
471
|
+
return _context7.stop();
|
|
449
472
|
}
|
|
450
|
-
},
|
|
473
|
+
}, _callee7, this);
|
|
451
474
|
}));
|
|
452
475
|
function afterEditorReady() {
|
|
453
476
|
return _afterEditorReady.apply(this, arguments);
|
|
@@ -463,22 +486,22 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
463
486
|
}, {
|
|
464
487
|
key: "run",
|
|
465
488
|
value: function () {
|
|
466
|
-
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
489
|
+
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
467
490
|
var _this4 = this;
|
|
468
491
|
var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
|
|
469
|
-
return _regeneratorRuntime().wrap(function
|
|
470
|
-
while (1) switch (
|
|
492
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
493
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
471
494
|
case 0:
|
|
472
495
|
libroModel = this.parent.model;
|
|
473
496
|
if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
|
|
474
|
-
|
|
497
|
+
_context8.next = 3;
|
|
475
498
|
break;
|
|
476
499
|
}
|
|
477
|
-
return
|
|
500
|
+
return _context8.abrupt("return", false);
|
|
478
501
|
case 3:
|
|
479
502
|
kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
480
503
|
cellContent = this.model.source;
|
|
481
|
-
|
|
504
|
+
_context8.prev = 5;
|
|
482
505
|
// Promise.resolve().then(() => {
|
|
483
506
|
this.clearExecution();
|
|
484
507
|
// });
|
|
@@ -508,10 +531,10 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
508
531
|
_this4.model.hasExecutedError = true;
|
|
509
532
|
}
|
|
510
533
|
};
|
|
511
|
-
|
|
534
|
+
_context8.next = 14;
|
|
512
535
|
return future.done;
|
|
513
536
|
case 14:
|
|
514
|
-
msgPromise =
|
|
537
|
+
msgPromise = _context8.sent;
|
|
515
538
|
this.model.executing = false;
|
|
516
539
|
this.model.kernelExecuting = false;
|
|
517
540
|
this.model.hasExecutedSuccess = !this.model.hasExecutedError;
|
|
@@ -520,36 +543,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
520
543
|
this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
|
|
521
544
|
this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
|
|
522
545
|
if (msgPromise) {
|
|
523
|
-
|
|
546
|
+
_context8.next = 24;
|
|
524
547
|
break;
|
|
525
548
|
}
|
|
526
|
-
return
|
|
549
|
+
return _context8.abrupt("return", true);
|
|
527
550
|
case 24:
|
|
528
551
|
if (!(msgPromise.content.status === 'ok')) {
|
|
529
|
-
|
|
552
|
+
_context8.next = 28;
|
|
530
553
|
break;
|
|
531
554
|
}
|
|
532
|
-
return
|
|
555
|
+
return _context8.abrupt("return", true);
|
|
533
556
|
case 28:
|
|
534
557
|
throw new KernelError(msgPromise.content);
|
|
535
558
|
case 29:
|
|
536
|
-
|
|
559
|
+
_context8.next = 36;
|
|
537
560
|
break;
|
|
538
561
|
case 31:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (!
|
|
542
|
-
|
|
562
|
+
_context8.prev = 31;
|
|
563
|
+
_context8.t0 = _context8["catch"](5);
|
|
564
|
+
if (!_context8.t0.message.startsWith('Canceled')) {
|
|
565
|
+
_context8.next = 35;
|
|
543
566
|
break;
|
|
544
567
|
}
|
|
545
|
-
return
|
|
568
|
+
return _context8.abrupt("return", false);
|
|
546
569
|
case 35:
|
|
547
|
-
throw
|
|
570
|
+
throw _context8.t0;
|
|
548
571
|
case 36:
|
|
549
572
|
case "end":
|
|
550
|
-
return
|
|
573
|
+
return _context8.stop();
|
|
551
574
|
}
|
|
552
|
-
},
|
|
575
|
+
}, _callee8, this, [[5, 31]]);
|
|
553
576
|
}));
|
|
554
577
|
function run() {
|
|
555
578
|
return _run.apply(this, arguments);
|
|
@@ -558,14 +581,24 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
558
581
|
}()
|
|
559
582
|
}]);
|
|
560
583
|
return LibroPromptCellView;
|
|
561
|
-
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "
|
|
584
|
+
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "selection", [_dec3], {
|
|
562
585
|
configurable: true,
|
|
563
586
|
enumerable: true,
|
|
564
587
|
writable: true,
|
|
565
588
|
initializer: function initializer() {
|
|
566
589
|
return [];
|
|
567
590
|
}
|
|
568
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "
|
|
591
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorManager", [_dec4], {
|
|
592
|
+
configurable: true,
|
|
593
|
+
enumerable: true,
|
|
594
|
+
writable: true,
|
|
595
|
+
initializer: null
|
|
596
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "promptScript", [_dec5], {
|
|
597
|
+
configurable: true,
|
|
598
|
+
enumerable: true,
|
|
599
|
+
writable: true,
|
|
600
|
+
initializer: null
|
|
601
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec6], {
|
|
569
602
|
configurable: true,
|
|
570
603
|
enumerable: true,
|
|
571
604
|
writable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-prompt-cell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
36
|
-
"@difizen/libro-jupyter": "^0.1.
|
|
37
|
-
"@difizen/libro-rendermime": "^0.1.
|
|
38
|
-
"@difizen/libro-codemirror": "^0.1.
|
|
39
|
-
"@difizen/libro-common": "^0.1.
|
|
40
|
-
"@difizen/libro-core": "^0.1.
|
|
35
|
+
"@difizen/libro-code-editor": "^0.1.14",
|
|
36
|
+
"@difizen/libro-jupyter": "^0.1.14",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.1.14",
|
|
38
|
+
"@difizen/libro-codemirror": "^0.1.14",
|
|
39
|
+
"@difizen/libro-common": "^0.1.14",
|
|
40
|
+
"@difizen/libro-core": "^0.1.14",
|
|
41
41
|
"@difizen/mana-app": "latest",
|
|
42
42
|
"highlight.js": "^11.8.0",
|
|
43
43
|
"marked": "^5.1.1",
|
|
@@ -27,7 +27,7 @@ export class FormatterPromptMagicContribution
|
|
|
27
27
|
|
|
28
28
|
encode = (source: PromptDecodedFormatter) => {
|
|
29
29
|
const promptObj = {
|
|
30
|
-
model_name: source.modelType || '
|
|
30
|
+
model_name: source.modelType || 'chatgpt',
|
|
31
31
|
prompt: source.value,
|
|
32
32
|
};
|
|
33
33
|
const encodeValue = `%%prompt \n${JSON.stringify(promptObj)}`;
|
package/src/module.ts
CHANGED
|
@@ -8,12 +8,14 @@ import { PromptCellContribution } from './prompt-cell-contribution.js';
|
|
|
8
8
|
import { LibroPromptCellModel } from './prompt-cell-model.js';
|
|
9
9
|
import { LibroPromptOutputArea } from './prompt-cell-output-area.js';
|
|
10
10
|
import { LibroPromptCellModelFactory } from './prompt-cell-protocol.js';
|
|
11
|
+
import { PromptScript } from './prompt-cell-script.js';
|
|
11
12
|
import { LibroPromptCellView } from './prompt-cell-view.js';
|
|
12
13
|
import { LibroPromptOutputMimeTypeContribution } from './prompt-output-rendermime-contribution.js';
|
|
13
14
|
|
|
14
15
|
export const LibroPromptCellModule = ManaModule.create()
|
|
15
16
|
.register(
|
|
16
17
|
PromptCellContribution,
|
|
18
|
+
PromptScript,
|
|
17
19
|
LibroPromptCellView,
|
|
18
20
|
LibroPromptCellModel,
|
|
19
21
|
LibroPromptOutputArea,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
@singleton()
|
|
4
|
+
export class PromptScript {
|
|
5
|
+
public readonly toList = `from libro_server import chat_provider
|
|
6
|
+
chat_provider.dump_list_json()`;
|
|
4
7
|
}
|
package/src/prompt-cell-view.tsx
CHANGED
|
@@ -34,20 +34,40 @@ import {
|
|
|
34
34
|
watch,
|
|
35
35
|
} from '@difizen/mana-app';
|
|
36
36
|
import { Deferred } from '@difizen/mana-app';
|
|
37
|
-
import { Select } from 'antd';
|
|
37
|
+
import { Select, Tag } from 'antd';
|
|
38
38
|
import React, { useEffect, useState } from 'react';
|
|
39
39
|
|
|
40
40
|
import type { LibroPromptCellModel } from './prompt-cell-model.js';
|
|
41
41
|
import { PromptScript } from './prompt-cell-script.js';
|
|
42
42
|
|
|
43
|
-
export interface
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
export interface IModelItem {
|
|
48
|
-
value: string;
|
|
43
|
+
export interface IChatSelectionItem {
|
|
44
|
+
name: string;
|
|
45
|
+
type: string;
|
|
49
46
|
}
|
|
50
47
|
|
|
48
|
+
const SelectionItemLabel: React.FC<{ item: IChatSelectionItem }> = (props: {
|
|
49
|
+
item: IChatSelectionItem;
|
|
50
|
+
}) => {
|
|
51
|
+
const item = props.item;
|
|
52
|
+
const colorMap: Record<string, any> = {
|
|
53
|
+
VARIABLE: 'red',
|
|
54
|
+
LLM: 'blue',
|
|
55
|
+
API: 'green',
|
|
56
|
+
CUSTOM: undefined,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<span className="libro-prompt-cell-selection-label">
|
|
61
|
+
<Tag
|
|
62
|
+
color={colorMap[item.type] || undefined}
|
|
63
|
+
className="libro-prompt-cell-header-selection-type"
|
|
64
|
+
>
|
|
65
|
+
{item.type}
|
|
66
|
+
</Tag>
|
|
67
|
+
<span className="libro-prompt-cell-header-selection-name">{item.name}</span>
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
51
71
|
const CellEditor: React.FC = () => {
|
|
52
72
|
const instance = useInject<LibroPromptCellView>(ViewInstance);
|
|
53
73
|
useEffect(() => {
|
|
@@ -66,15 +86,12 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
66
86
|
const [selectedModel, setSelectedModel] = useState<string>('暂无内置模型');
|
|
67
87
|
useEffect(() => {
|
|
68
88
|
instance
|
|
69
|
-
.
|
|
70
|
-
{ code: PromptScript.get_models, store_history: false },
|
|
71
|
-
instance.handleQueryResponse,
|
|
72
|
-
)
|
|
89
|
+
.updateChatList()
|
|
73
90
|
.then(() => {
|
|
74
|
-
const len = instance.
|
|
91
|
+
const len = instance.selection.length;
|
|
75
92
|
if (len > 0) {
|
|
76
93
|
instance.model.decodeObject = {
|
|
77
|
-
modelType: instance.
|
|
94
|
+
modelType: instance.selection[len - 1].name,
|
|
78
95
|
...instance.model.decodeObject,
|
|
79
96
|
};
|
|
80
97
|
setSelectedModel(instance.model.decodeObject['modelType']);
|
|
@@ -111,13 +128,10 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
111
128
|
value={selectedModel}
|
|
112
129
|
style={{ width: 160 }}
|
|
113
130
|
onChange={handleChange}
|
|
114
|
-
options={instance.
|
|
131
|
+
options={instance.selection.map(instance.toSelectionOption)}
|
|
115
132
|
bordered={false}
|
|
116
133
|
onFocus={async () => {
|
|
117
|
-
await instance.
|
|
118
|
-
{ code: PromptScript.get_models, store_history: false },
|
|
119
|
-
instance.handleQueryResponse,
|
|
120
|
-
);
|
|
134
|
+
await instance.updateChatList();
|
|
121
135
|
}}
|
|
122
136
|
/>
|
|
123
137
|
</div>
|
|
@@ -136,11 +150,12 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
136
150
|
declare model: LibroPromptCellModel;
|
|
137
151
|
|
|
138
152
|
@prop()
|
|
139
|
-
|
|
153
|
+
selection: IChatSelectionItem[] = [];
|
|
140
154
|
|
|
141
155
|
viewManager: ViewManager;
|
|
142
156
|
|
|
143
|
-
codeEditorManager: CodeEditorManager;
|
|
157
|
+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager;
|
|
158
|
+
@inject(PromptScript) promptScript: PromptScript;
|
|
144
159
|
|
|
145
160
|
outputs: IOutput[];
|
|
146
161
|
|
|
@@ -165,13 +180,11 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
165
180
|
@inject(CellService) cellService: CellService,
|
|
166
181
|
@inject(ViewManager) viewManager: ViewManager,
|
|
167
182
|
@inject(LibroViewTracker) libroViewTracker: LibroViewTracker,
|
|
168
|
-
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
|
|
169
183
|
) {
|
|
170
184
|
super(options, cellService);
|
|
171
185
|
this.options = options;
|
|
172
186
|
this.viewManager = viewManager;
|
|
173
187
|
this.className = this.className + ' prompt';
|
|
174
|
-
this.codeEditorManager = codeEditorManager;
|
|
175
188
|
|
|
176
189
|
this.outputs = options.cell?.outputs as IOutput[];
|
|
177
190
|
this.libroViewTracker = libroViewTracker;
|
|
@@ -421,6 +434,20 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
421
434
|
return future.done as Promise<KernelMessage.IExecuteReplyMsg>;
|
|
422
435
|
};
|
|
423
436
|
|
|
437
|
+
updateChatList = async () => {
|
|
438
|
+
return this.fetch(
|
|
439
|
+
{ code: this.promptScript.toList, store_history: false },
|
|
440
|
+
this.handleQueryResponse,
|
|
441
|
+
);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
toSelectionOption = (item: IChatSelectionItem) => {
|
|
445
|
+
return {
|
|
446
|
+
value: item.name,
|
|
447
|
+
label: <SelectionItemLabel item={item} />,
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
|
|
424
451
|
handleQueryResponse = (response: KernelMessage.IIOPubMessage) => {
|
|
425
452
|
const msgType = response.header.msg_type;
|
|
426
453
|
switch (msgType) {
|
|
@@ -432,10 +459,7 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
432
459
|
content = content.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
433
460
|
}
|
|
434
461
|
|
|
435
|
-
|
|
436
|
-
this.modelSelection = update.map((item) => {
|
|
437
|
-
return { value: item, label: item };
|
|
438
|
-
});
|
|
462
|
+
this.selection = JSON.parse(content) as IChatSelectionItem[];
|
|
439
463
|
break;
|
|
440
464
|
}
|
|
441
465
|
case 'stream': {
|
|
@@ -446,11 +470,7 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
446
470
|
contentStream = contentStream.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
447
471
|
}
|
|
448
472
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.modelSelection = updateStream.map((item) => {
|
|
452
|
-
return { value: item, label: item };
|
|
453
|
-
});
|
|
473
|
+
this.selection = JSON.parse(contentStream) as IChatSelectionItem[];
|
|
454
474
|
break;
|
|
455
475
|
}
|
|
456
476
|
default:
|