@wabot-dev/framework 0.1.0-beta.4 → 0.1.0-beta.6
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.
|
@@ -8,10 +8,12 @@ import { ChatBotAdapter } from '../../chatbot/ChatBotAdapter.js';
|
|
|
8
8
|
import 'reflect-metadata';
|
|
9
9
|
import '../../mindset/metadata/MindsetMetadataStore.js';
|
|
10
10
|
import { MindsetOperator } from '../../mindset/MindsetOperator.js';
|
|
11
|
+
import { Logger } from '../../logger/Logger.js';
|
|
11
12
|
|
|
12
13
|
let OpenaiChatBotAdapter = class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
13
14
|
openai = new OpenAI();
|
|
14
15
|
model;
|
|
16
|
+
logger = new Logger('wabot:openai-chat-bot-adapter');
|
|
15
17
|
constructor(mindset) {
|
|
16
18
|
super(mindset);
|
|
17
19
|
const model = process.env.OPENAI_CHAT_MODEL;
|
|
@@ -26,11 +28,13 @@ let OpenaiChatBotAdapter = class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
|
26
28
|
const parameters = { ...fn.parameters, additionalProperties: false, type: 'object' };
|
|
27
29
|
return { ...fn, type: 'function', parameters, strict: true };
|
|
28
30
|
});
|
|
29
|
-
const
|
|
31
|
+
const request = {
|
|
30
32
|
model: this.model,
|
|
31
33
|
input: [{ role: 'system', content: systemPrompt }, ...this.mapChatItems(chatItems)],
|
|
32
34
|
tools,
|
|
33
|
-
}
|
|
35
|
+
};
|
|
36
|
+
this.logger.debug(`Call Api with Request: ${JSON.stringify(request)}`);
|
|
37
|
+
const response = await this.openai.responses.create(request);
|
|
34
38
|
let newChatItem;
|
|
35
39
|
if (response.output_text) {
|
|
36
40
|
newChatItem = await this.buildBotMessageItem(response.output_text);
|
|
@@ -55,11 +55,9 @@ class WhatsAppSender {
|
|
|
55
55
|
if (!template) {
|
|
56
56
|
throw new Error(`WhatsAppTemplate with name ${request.templateMessage.templateName} and language ${request.templateMessage.languageCode} not found`);
|
|
57
57
|
}
|
|
58
|
+
const components = template.components.filter((x) => x.text != null).map((x) => x.text).join('\n');
|
|
58
59
|
return {
|
|
59
|
-
text:
|
|
60
|
-
.filter((x) => x.text != null)
|
|
61
|
-
.map((x) => x.text)
|
|
62
|
-
.join('\n'),
|
|
60
|
+
text: this.replaceTemplateParameters(components, request.templateMessage.parameters),
|
|
63
61
|
senderName: request.senderName,
|
|
64
62
|
};
|
|
65
63
|
}
|
|
@@ -77,6 +75,22 @@ class WhatsAppSender {
|
|
|
77
75
|
});
|
|
78
76
|
await chatMemory.create(chatItem);
|
|
79
77
|
}
|
|
78
|
+
replaceTemplateParameters(template, data) {
|
|
79
|
+
let result = template;
|
|
80
|
+
data.forEach(param => {
|
|
81
|
+
if (param.type === 'text' && param.parameter_name) {
|
|
82
|
+
const tag = `{{${param.parameter_name}}}`;
|
|
83
|
+
result = result.split(tag).join(param.text);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
data.forEach((param, index) => {
|
|
87
|
+
if (param.type === 'text') {
|
|
88
|
+
const tag = `{{${index + 1}}}`;
|
|
89
|
+
result = result.split(tag).join(param.text);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
export { WhatsAppSender };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -379,6 +379,7 @@ declare class DeepSeekChatBotAdapter extends ChatBotAdapter {
|
|
|
379
379
|
declare class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
380
380
|
private openai;
|
|
381
381
|
private model;
|
|
382
|
+
private logger;
|
|
382
383
|
constructor(mindset: MindsetOperator);
|
|
383
384
|
generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
|
|
384
385
|
private mapChatItems;
|
|
@@ -536,6 +537,7 @@ declare function whatsapp(config: IWhatsappChannelConfig): (target: object, prop
|
|
|
536
537
|
type IWhatsAppTemplateParameter = {
|
|
537
538
|
type: 'text';
|
|
538
539
|
text: string;
|
|
540
|
+
parameter_name?: string;
|
|
539
541
|
} | {
|
|
540
542
|
type: 'currency';
|
|
541
543
|
currency: {
|
|
@@ -718,6 +720,7 @@ declare abstract class WhatsAppSender {
|
|
|
718
720
|
getWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
|
|
719
721
|
protected resolveTemplateToChatMessage(request: ISendWhatsAppTemplateRequest): Promise<IChatMessage>;
|
|
720
722
|
protected writePrivateChatMemory(message: IChatMessage, to: string): Promise<void>;
|
|
723
|
+
private replaceTemplateParameters;
|
|
721
724
|
}
|
|
722
725
|
|
|
723
726
|
declare class WhatsAppChannel implements IChatChannel {
|