@sprucelabs/sprucebot-llm 11.1.1 → 11.1.3
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/build/bots/SprucebotLlmBotImpl.d.ts +1 -0
- package/build/bots/SprucebotLlmBotImpl.js +10 -3
- package/build/bots/adapters/OpenAiMessageBuilder.js +9 -9
- package/build/esm/bots/SprucebotLlmBotImpl.d.ts +1 -0
- package/build/esm/bots/SprucebotLlmBotImpl.js +13 -4
- package/build/esm/bots/adapters/OpenAiMessageBuilder.js +9 -9
- package/build/esm/llm.types.d.ts +2 -1
- package/build/llm.types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, St
|
|
|
16
16
|
getIsDone(): boolean;
|
|
17
17
|
serialize(): SerializedBot<StateSchema, State>;
|
|
18
18
|
sendMessage(message: SendMessage, cb?: MessageResponseCallback): Promise<string>;
|
|
19
|
+
private _sendMessageInternal;
|
|
19
20
|
private optionallyUpdateState;
|
|
20
21
|
private parseResponse;
|
|
21
22
|
private sendMessageToAdapter;
|
|
@@ -56,6 +56,9 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
56
56
|
llmMessage.message = message.imageDescription;
|
|
57
57
|
llmMessage.imageBase64 = message.imageBase64;
|
|
58
58
|
}
|
|
59
|
+
return this._sendMessageInternal(llmMessage, cb);
|
|
60
|
+
}
|
|
61
|
+
async _sendMessageInternal(llmMessage, cb) {
|
|
59
62
|
this.trackMessage(llmMessage);
|
|
60
63
|
const { model, callbacks } = this.skill?.serialize() ?? {};
|
|
61
64
|
const response = await this.sendMessageToAdapter(model);
|
|
@@ -87,15 +90,19 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
87
90
|
if (callbackResults) {
|
|
88
91
|
let message;
|
|
89
92
|
if (typeof callbackResults === 'string') {
|
|
90
|
-
message =
|
|
93
|
+
message = {
|
|
94
|
+
from: 'Api',
|
|
95
|
+
message: `API Results: ${callbackResults}`,
|
|
96
|
+
};
|
|
91
97
|
}
|
|
92
98
|
else {
|
|
93
99
|
message = {
|
|
100
|
+
from: 'Api',
|
|
94
101
|
imageBase64: callbackResults.imageBase64,
|
|
95
|
-
|
|
102
|
+
message: `API Results: ${callbackResults.imageDescription}`,
|
|
96
103
|
};
|
|
97
104
|
}
|
|
98
|
-
await this.
|
|
105
|
+
await this._sendMessageInternal(message, cb);
|
|
99
106
|
}
|
|
100
107
|
return parsedMessage;
|
|
101
108
|
}
|
|
@@ -42,13 +42,13 @@ class OpenAiMessageBuilder {
|
|
|
42
42
|
];
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
role: message.from === 'Me' ? 'user' : '
|
|
45
|
+
role: message.from === 'Me' ? 'user' : 'developer',
|
|
46
46
|
content,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
buildFirstMessage(youAre) {
|
|
50
50
|
return {
|
|
51
|
-
role: '
|
|
51
|
+
role: 'developer',
|
|
52
52
|
content: `You are ${youAre}.`,
|
|
53
53
|
};
|
|
54
54
|
}
|
|
@@ -112,37 +112,37 @@ class OpenAiMessageBuilder {
|
|
|
112
112
|
}
|
|
113
113
|
const api = `<APIReference>\n\n${descriptions.join('\n\n')}</APIReference>`;
|
|
114
114
|
return {
|
|
115
|
-
role: '
|
|
116
|
-
content: `You have an API available to you to lookup answers. When you need the response of the function call to proceed, you can call a function using a custom markup we created that looks like this: <<FunctionName/>>. The API will respond with the results and then you can continue the conversation with your new knowledge. If the api call has parameters, call it like this: <<FunctionName>>{{parametersJsonEncoded}}<</FunctionName>>. Make sure to json encode the data and drop it between the function tags. The API is as follows (in xml format):\n\n${api}`,
|
|
115
|
+
role: 'developer',
|
|
116
|
+
content: `You have an API available to you to lookup answers. When you need the response of the function call to proceed, you can call a function using a custom markup we created that looks like this: <<FunctionName/>>. The API will respond with the results and then you can continue the conversation with your new knowledge. If the api call has parameters, call it like this: <<FunctionName>>{{parametersJsonEncoded}}<</FunctionName>>. Make sure to json encode the data and drop it between the function tags. Note: You can only make one API call at a time. The API is as follows (in xml format):\n\n${api}`,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
buildPleaseKeepInMindMessage(pleaseKeepInMindThat) {
|
|
120
120
|
return {
|
|
121
|
-
role: '
|
|
121
|
+
role: 'developer',
|
|
122
122
|
content: `During this conversation, please keep the following in mind:\n\n${pleaseKeepInMindThat.map((m, idx) => `${idx + 1}. ${m}`).join('\n')}.`,
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
buildStateMessage(state) {
|
|
126
126
|
return {
|
|
127
|
-
role: '
|
|
127
|
+
role: 'developer',
|
|
128
128
|
content: `The current state of this conversation is:\n\n${JSON.stringify(state)}. As the state is being updated, send it back to me in json format (something in can JSON.parse()) at the end of each response (it's not meant for reading, but for parsing, so don't call it out, but send it as we progress), surrounded by a boundary, like this: ${templates_1.STATE_BOUNDARY} { "fieldName": "fieldValue" } ${templates_1.STATE_BOUNDARY}`,
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
buildYourJobMessage(yourJob) {
|
|
132
132
|
return {
|
|
133
|
-
role: '
|
|
133
|
+
role: 'developer',
|
|
134
134
|
content: `For this interaction, your job is ${yourJob}.`,
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
buildWeAreDoneWhenMessage(weAreDoneWhen) {
|
|
138
138
|
return {
|
|
139
|
-
role: '
|
|
139
|
+
role: 'developer',
|
|
140
140
|
content: `Our conversation is done when ${weAreDoneWhen}. Once you determine we are done, send me the following message so I know we're done: ${templates_1.DONE_TOKEN}`,
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
buildStateSchemaMessage(schema) {
|
|
144
144
|
return {
|
|
145
|
-
role: '
|
|
145
|
+
role: 'developer',
|
|
146
146
|
content: `We will be tracking state for this conversation. The following schema is what we'll use to define the shape of the state:\n\n${JSON.stringify(schema)}`,
|
|
147
147
|
};
|
|
148
148
|
}
|
|
@@ -16,6 +16,7 @@ export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, St
|
|
|
16
16
|
getIsDone(): boolean;
|
|
17
17
|
serialize(): SerializedBot<StateSchema, State>;
|
|
18
18
|
sendMessage(message: SendMessage, cb?: MessageResponseCallback): Promise<string>;
|
|
19
|
+
private _sendMessageInternal;
|
|
19
20
|
private optionallyUpdateState;
|
|
20
21
|
private parseResponse;
|
|
21
22
|
private sendMessageToAdapter;
|
|
@@ -47,7 +47,6 @@ class SprucebotLlmBotImpl extends AbstractEventEmitter {
|
|
|
47
47
|
}
|
|
48
48
|
sendMessage(message, cb) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
var _a, _b, _c, _d;
|
|
51
50
|
assertOptions({ message }, ['message']);
|
|
52
51
|
const llmMessage = {
|
|
53
52
|
from: 'Me',
|
|
@@ -60,6 +59,12 @@ class SprucebotLlmBotImpl extends AbstractEventEmitter {
|
|
|
60
59
|
llmMessage.message = message.imageDescription;
|
|
61
60
|
llmMessage.imageBase64 = message.imageBase64;
|
|
62
61
|
}
|
|
62
|
+
return this._sendMessageInternal(llmMessage, cb);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
_sendMessageInternal(llmMessage, cb) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b, _c, _d;
|
|
63
68
|
this.trackMessage(llmMessage);
|
|
64
69
|
const { model, callbacks } = (_b = (_a = this.skill) === null || _a === void 0 ? void 0 : _a.serialize()) !== null && _b !== void 0 ? _b : {};
|
|
65
70
|
const response = yield this.sendMessageToAdapter(model);
|
|
@@ -91,15 +96,19 @@ class SprucebotLlmBotImpl extends AbstractEventEmitter {
|
|
|
91
96
|
if (callbackResults) {
|
|
92
97
|
let message;
|
|
93
98
|
if (typeof callbackResults === 'string') {
|
|
94
|
-
message =
|
|
99
|
+
message = {
|
|
100
|
+
from: 'Api',
|
|
101
|
+
message: `API Results: ${callbackResults}`,
|
|
102
|
+
};
|
|
95
103
|
}
|
|
96
104
|
else {
|
|
97
105
|
message = {
|
|
106
|
+
from: 'Api',
|
|
98
107
|
imageBase64: callbackResults.imageBase64,
|
|
99
|
-
|
|
108
|
+
message: `API Results: ${callbackResults.imageDescription}`,
|
|
100
109
|
};
|
|
101
110
|
}
|
|
102
|
-
yield this.
|
|
111
|
+
yield this._sendMessageInternal(message, cb);
|
|
103
112
|
}
|
|
104
113
|
return parsedMessage;
|
|
105
114
|
});
|
|
@@ -41,13 +41,13 @@ export default class OpenAiMessageBuilder {
|
|
|
41
41
|
];
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
44
|
-
role: message.from === 'Me' ? 'user' : '
|
|
44
|
+
role: message.from === 'Me' ? 'user' : 'developer',
|
|
45
45
|
content,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
buildFirstMessage(youAre) {
|
|
49
49
|
return {
|
|
50
|
-
role: '
|
|
50
|
+
role: 'developer',
|
|
51
51
|
content: `You are ${youAre}.`,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -111,37 +111,37 @@ export default class OpenAiMessageBuilder {
|
|
|
111
111
|
}
|
|
112
112
|
const api = `<APIReference>\n\n${descriptions.join('\n\n')}</APIReference>`;
|
|
113
113
|
return {
|
|
114
|
-
role: '
|
|
115
|
-
content: `You have an API available to you to lookup answers. When you need the response of the function call to proceed, you can call a function using a custom markup we created that looks like this: <<FunctionName/>>. The API will respond with the results and then you can continue the conversation with your new knowledge. If the api call has parameters, call it like this: <<FunctionName>>{{parametersJsonEncoded}}<</FunctionName>>. Make sure to json encode the data and drop it between the function tags. The API is as follows (in xml format):\n\n${api}`,
|
|
114
|
+
role: 'developer',
|
|
115
|
+
content: `You have an API available to you to lookup answers. When you need the response of the function call to proceed, you can call a function using a custom markup we created that looks like this: <<FunctionName/>>. The API will respond with the results and then you can continue the conversation with your new knowledge. If the api call has parameters, call it like this: <<FunctionName>>{{parametersJsonEncoded}}<</FunctionName>>. Make sure to json encode the data and drop it between the function tags. Note: You can only make one API call at a time. The API is as follows (in xml format):\n\n${api}`,
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
buildPleaseKeepInMindMessage(pleaseKeepInMindThat) {
|
|
119
119
|
return {
|
|
120
|
-
role: '
|
|
120
|
+
role: 'developer',
|
|
121
121
|
content: `During this conversation, please keep the following in mind:\n\n${pleaseKeepInMindThat.map((m, idx) => `${idx + 1}. ${m}`).join('\n')}.`,
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
buildStateMessage(state) {
|
|
125
125
|
return {
|
|
126
|
-
role: '
|
|
126
|
+
role: 'developer',
|
|
127
127
|
content: `The current state of this conversation is:\n\n${JSON.stringify(state)}. As the state is being updated, send it back to me in json format (something in can JSON.parse()) at the end of each response (it's not meant for reading, but for parsing, so don't call it out, but send it as we progress), surrounded by a boundary, like this: ${STATE_BOUNDARY} { "fieldName": "fieldValue" } ${STATE_BOUNDARY}`,
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
buildYourJobMessage(yourJob) {
|
|
131
131
|
return {
|
|
132
|
-
role: '
|
|
132
|
+
role: 'developer',
|
|
133
133
|
content: `For this interaction, your job is ${yourJob}.`,
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
buildWeAreDoneWhenMessage(weAreDoneWhen) {
|
|
137
137
|
return {
|
|
138
|
-
role: '
|
|
138
|
+
role: 'developer',
|
|
139
139
|
content: `Our conversation is done when ${weAreDoneWhen}. Once you determine we are done, send me the following message so I know we're done: ${DONE_TOKEN}`,
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
buildStateSchemaMessage(schema) {
|
|
143
143
|
return {
|
|
144
|
-
role: '
|
|
144
|
+
role: 'developer',
|
|
145
145
|
content: `We will be tracking state for this conversation. The following schema is what we'll use to define the shape of the state:\n\n${JSON.stringify(schema)}`,
|
|
146
146
|
};
|
|
147
147
|
}
|
package/build/esm/llm.types.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export declare const llmEventContract: {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
export type LlmEventContract = typeof llmEventContract;
|
|
41
|
+
export type LlmMessageFrom = 'Me' | 'You' | 'Api';
|
|
41
42
|
export interface LlmMessage {
|
|
42
|
-
from:
|
|
43
|
+
from: LlmMessageFrom;
|
|
43
44
|
message: string;
|
|
44
45
|
imageBase64?: string;
|
|
45
46
|
}
|
package/build/llm.types.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export declare const llmEventContract: {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
export type LlmEventContract = typeof llmEventContract;
|
|
41
|
+
export type LlmMessageFrom = 'Me' | 'You' | 'Api';
|
|
41
42
|
export interface LlmMessage {
|
|
42
|
-
from:
|
|
43
|
+
from: LlmMessageFrom;
|
|
43
44
|
message: string;
|
|
44
45
|
imageBase64?: string;
|
|
45
46
|
}
|