llmasaservice-ui 0.3.0 → 0.3.2
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/dist/index.js +34 -3
- package/dist/index.mjs +34 -3
- package/package.json +1 -1
- package/src/ChatPanel.tsx +40 -3
package/dist/index.js
CHANGED
|
@@ -91,7 +91,8 @@ var ChatPanel = ({
|
|
|
91
91
|
initialMessage = "",
|
|
92
92
|
prismStyle = theme === "light" ? import_material_light.default : import_material_dark.default,
|
|
93
93
|
service = null,
|
|
94
|
-
historyChangedCallback = null
|
|
94
|
+
historyChangedCallback = null,
|
|
95
|
+
promptTemplate = ""
|
|
95
96
|
}) => {
|
|
96
97
|
const { send, response, idle, stop, lastCallId } = (0, import_llmasaservice_client.useLLM)({
|
|
97
98
|
project_id,
|
|
@@ -157,6 +158,7 @@ var ChatPanel = ({
|
|
|
157
158
|
}
|
|
158
159
|
}, [history, historyChangedCallback]);
|
|
159
160
|
const continueChat = () => {
|
|
161
|
+
var _a, _b, _c;
|
|
160
162
|
if (!idle) {
|
|
161
163
|
stop(lastController);
|
|
162
164
|
setHistory((prevHistory) => {
|
|
@@ -173,7 +175,18 @@ var ChatPanel = ({
|
|
|
173
175
|
setIsLoading(true);
|
|
174
176
|
const messagesAndHistory = messages;
|
|
175
177
|
Object.entries(history).forEach(([prompt, response2]) => {
|
|
176
|
-
|
|
178
|
+
var _a2, _b2, _c2;
|
|
179
|
+
let promptToSend2 = prompt;
|
|
180
|
+
if (promptTemplate && promptTemplate !== "") {
|
|
181
|
+
promptToSend2 = promptTemplate.replace("{{prompt}}", promptToSend2);
|
|
182
|
+
for (let i = 0; i < data.length; i++) {
|
|
183
|
+
promptToSend2 = promptToSend2.replace(
|
|
184
|
+
"{{" + ((_a2 = data[i]) == null ? void 0 : _a2.key) + "}}",
|
|
185
|
+
(_c2 = (_b2 = data[i]) == null ? void 0 : _b2.data) != null ? _c2 : ""
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
messagesAndHistory.push({ role: "user", content: promptToSend2 });
|
|
177
190
|
messagesAndHistory.push({
|
|
178
191
|
role: "assistant",
|
|
179
192
|
content: response2.content
|
|
@@ -184,8 +197,26 @@ var ChatPanel = ({
|
|
|
184
197
|
[nextPrompt != null ? nextPrompt : ""]: { content: "", callId: "" }
|
|
185
198
|
});
|
|
186
199
|
});
|
|
200
|
+
let promptToSend = nextPrompt;
|
|
201
|
+
if (Object.keys(history).length === 0 && promptTemplate && promptTemplate !== "") {
|
|
202
|
+
promptToSend = promptTemplate.replace("{{prompt}}", nextPrompt);
|
|
203
|
+
for (let i = 0; i < data.length; i++) {
|
|
204
|
+
promptToSend = promptToSend.replace(
|
|
205
|
+
"{{" + ((_a = data[i]) == null ? void 0 : _a.key) + "}}",
|
|
206
|
+
(_c = (_b = data[i]) == null ? void 0 : _b.data) != null ? _c : ""
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
187
210
|
const controller = new AbortController();
|
|
188
|
-
send(
|
|
211
|
+
send(
|
|
212
|
+
promptToSend,
|
|
213
|
+
messagesAndHistory,
|
|
214
|
+
data,
|
|
215
|
+
true,
|
|
216
|
+
true,
|
|
217
|
+
service,
|
|
218
|
+
controller
|
|
219
|
+
);
|
|
189
220
|
setLastPrompt(nextPrompt);
|
|
190
221
|
setLastController(controller);
|
|
191
222
|
setNextPrompt("");
|
package/dist/index.mjs
CHANGED
|
@@ -58,7 +58,8 @@ var ChatPanel = ({
|
|
|
58
58
|
initialMessage = "",
|
|
59
59
|
prismStyle = theme === "light" ? materialLight : materialDark,
|
|
60
60
|
service = null,
|
|
61
|
-
historyChangedCallback = null
|
|
61
|
+
historyChangedCallback = null,
|
|
62
|
+
promptTemplate = ""
|
|
62
63
|
}) => {
|
|
63
64
|
const { send, response, idle, stop, lastCallId } = useLLM({
|
|
64
65
|
project_id,
|
|
@@ -124,6 +125,7 @@ var ChatPanel = ({
|
|
|
124
125
|
}
|
|
125
126
|
}, [history, historyChangedCallback]);
|
|
126
127
|
const continueChat = () => {
|
|
128
|
+
var _a, _b, _c;
|
|
127
129
|
if (!idle) {
|
|
128
130
|
stop(lastController);
|
|
129
131
|
setHistory((prevHistory) => {
|
|
@@ -140,7 +142,18 @@ var ChatPanel = ({
|
|
|
140
142
|
setIsLoading(true);
|
|
141
143
|
const messagesAndHistory = messages;
|
|
142
144
|
Object.entries(history).forEach(([prompt, response2]) => {
|
|
143
|
-
|
|
145
|
+
var _a2, _b2, _c2;
|
|
146
|
+
let promptToSend2 = prompt;
|
|
147
|
+
if (promptTemplate && promptTemplate !== "") {
|
|
148
|
+
promptToSend2 = promptTemplate.replace("{{prompt}}", promptToSend2);
|
|
149
|
+
for (let i = 0; i < data.length; i++) {
|
|
150
|
+
promptToSend2 = promptToSend2.replace(
|
|
151
|
+
"{{" + ((_a2 = data[i]) == null ? void 0 : _a2.key) + "}}",
|
|
152
|
+
(_c2 = (_b2 = data[i]) == null ? void 0 : _b2.data) != null ? _c2 : ""
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
messagesAndHistory.push({ role: "user", content: promptToSend2 });
|
|
144
157
|
messagesAndHistory.push({
|
|
145
158
|
role: "assistant",
|
|
146
159
|
content: response2.content
|
|
@@ -151,8 +164,26 @@ var ChatPanel = ({
|
|
|
151
164
|
[nextPrompt != null ? nextPrompt : ""]: { content: "", callId: "" }
|
|
152
165
|
});
|
|
153
166
|
});
|
|
167
|
+
let promptToSend = nextPrompt;
|
|
168
|
+
if (Object.keys(history).length === 0 && promptTemplate && promptTemplate !== "") {
|
|
169
|
+
promptToSend = promptTemplate.replace("{{prompt}}", nextPrompt);
|
|
170
|
+
for (let i = 0; i < data.length; i++) {
|
|
171
|
+
promptToSend = promptToSend.replace(
|
|
172
|
+
"{{" + ((_a = data[i]) == null ? void 0 : _a.key) + "}}",
|
|
173
|
+
(_c = (_b = data[i]) == null ? void 0 : _b.data) != null ? _c : ""
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
154
177
|
const controller = new AbortController();
|
|
155
|
-
send(
|
|
178
|
+
send(
|
|
179
|
+
promptToSend,
|
|
180
|
+
messagesAndHistory,
|
|
181
|
+
data,
|
|
182
|
+
true,
|
|
183
|
+
true,
|
|
184
|
+
service,
|
|
185
|
+
controller
|
|
186
|
+
);
|
|
156
187
|
setLastPrompt(nextPrompt);
|
|
157
188
|
setLastController(controller);
|
|
158
189
|
setNextPrompt("");
|
package/package.json
CHANGED
package/src/ChatPanel.tsx
CHANGED
|
@@ -17,7 +17,7 @@ export interface ChatPanelProps {
|
|
|
17
17
|
hideInitialPrompt?: boolean;
|
|
18
18
|
customer?: LLMAsAServiceCustomer;
|
|
19
19
|
messages?: { role: "user" | "assistant"; content: string }[];
|
|
20
|
-
data
|
|
20
|
+
data?: { key: string; data: string }[];
|
|
21
21
|
thumbsUpClick?: () => void;
|
|
22
22
|
thumbsDownClick?: () => void;
|
|
23
23
|
theme?: "light" | "dark";
|
|
@@ -59,6 +59,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
59
59
|
prismStyle = theme === "light" ? materialLight : materialDark,
|
|
60
60
|
service = null,
|
|
61
61
|
historyChangedCallback = null,
|
|
62
|
+
promptTemplate = "",
|
|
62
63
|
}) => {
|
|
63
64
|
const { send, response, idle, stop, lastCallId } = useLLM({
|
|
64
65
|
project_id: project_id,
|
|
@@ -163,7 +164,18 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
163
164
|
// build the chat input from history
|
|
164
165
|
const messagesAndHistory = messages;
|
|
165
166
|
Object.entries(history).forEach(([prompt, response]) => {
|
|
166
|
-
|
|
167
|
+
let promptToSend = prompt;
|
|
168
|
+
if (promptTemplate && promptTemplate !== "") {
|
|
169
|
+
promptToSend = promptTemplate.replace("{{prompt}}", promptToSend);
|
|
170
|
+
for (let i = 0; i < data.length; i++) {
|
|
171
|
+
promptToSend = promptToSend.replace(
|
|
172
|
+
"{{" + data[i]?.key + "}}",
|
|
173
|
+
data[i]?.data ?? ""
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
messagesAndHistory.push({ role: "user", content: promptToSend });
|
|
167
179
|
messagesAndHistory.push({
|
|
168
180
|
role: "assistant",
|
|
169
181
|
content: response.content,
|
|
@@ -178,8 +190,33 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
178
190
|
};
|
|
179
191
|
});
|
|
180
192
|
|
|
193
|
+
let promptToSend = nextPrompt;
|
|
194
|
+
|
|
195
|
+
// if this is the first user message, use the template. otherwise it is a follow-on question(s)
|
|
196
|
+
if (
|
|
197
|
+
Object.keys(history).length === 0 &&
|
|
198
|
+
promptTemplate &&
|
|
199
|
+
promptTemplate !== ""
|
|
200
|
+
) {
|
|
201
|
+
promptToSend = promptTemplate.replace("{{prompt}}", nextPrompt);
|
|
202
|
+
for (let i = 0; i < data.length; i++) {
|
|
203
|
+
promptToSend = promptToSend.replace(
|
|
204
|
+
"{{" + data[i]?.key + "}}",
|
|
205
|
+
data[i]?.data ?? ""
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
181
210
|
const controller = new AbortController();
|
|
182
|
-
send(
|
|
211
|
+
send(
|
|
212
|
+
promptToSend,
|
|
213
|
+
messagesAndHistory,
|
|
214
|
+
data,
|
|
215
|
+
true,
|
|
216
|
+
true,
|
|
217
|
+
service,
|
|
218
|
+
controller
|
|
219
|
+
);
|
|
183
220
|
|
|
184
221
|
setLastPrompt(nextPrompt);
|
|
185
222
|
setLastController(controller);
|