@fonoster/autopilot 0.8.64 → 0.8.65
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.
|
@@ -121,7 +121,6 @@ async function handleVoiceRequest(req, res) {
|
|
|
121
121
|
autopilot.stop();
|
|
122
122
|
const rawChatHistory = await languageModel.getChatHistoryMessages();
|
|
123
123
|
const chatHistory = rawChatHistory
|
|
124
|
-
.filter((msg) => !msg.content?.toString().startsWith("tool result:")) // FIXME: Hardcoded filter
|
|
125
124
|
.map((msg) => {
|
|
126
125
|
if (msg.constructor.name === "HumanMessage") {
|
|
127
126
|
return { human: msg.content };
|
|
@@ -5,6 +5,9 @@ declare abstract class AbstractLanguageModel implements LanguageModel {
|
|
|
5
5
|
private readonly chatHistory;
|
|
6
6
|
private readonly toolsCatalog;
|
|
7
7
|
private readonly voice;
|
|
8
|
+
private readonly goodbyeMessage;
|
|
9
|
+
private readonly firstMessage;
|
|
10
|
+
private readonly transferOptions;
|
|
8
11
|
constructor(params: LanguageModelParams, voice: Voice, telephonyContext: TelephonyContext);
|
|
9
12
|
invoke(text: string): Promise<InvocationResult>;
|
|
10
13
|
getChatHistoryMessages(): Promise<import("@langchain/core/messages").BaseMessage[]>;
|
|
@@ -28,12 +28,14 @@ const tools_1 = require("../tools");
|
|
|
28
28
|
const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
|
|
29
29
|
class AbstractLanguageModel {
|
|
30
30
|
constructor(params, voice, telephonyContext) {
|
|
31
|
-
const { model, firstMessage, systemPrompt, knowledgeBase, tools } = params;
|
|
31
|
+
const { model, firstMessage, transferOptions, systemPrompt, goodbyeMessage, knowledgeBase, tools } = params;
|
|
32
32
|
this.chatHistory = (0, chatHistory_1.createChatHistory)();
|
|
33
33
|
this.toolsCatalog = new tools_1.ToolsCatalog(tools);
|
|
34
34
|
this.voice = voice;
|
|
35
|
+
this.firstMessage = firstMessage;
|
|
36
|
+
this.goodbyeMessage = goodbyeMessage;
|
|
37
|
+
this.transferOptions = transferOptions;
|
|
35
38
|
const promptTemplate = (0, createPromptTemplate_1.createPromptTemplate)({
|
|
36
|
-
firstMessage,
|
|
37
39
|
systemPrompt,
|
|
38
40
|
telephonyContext
|
|
39
41
|
});
|
|
@@ -43,12 +45,16 @@ class AbstractLanguageModel {
|
|
|
43
45
|
const { chain, chatHistory, toolsCatalog } = this;
|
|
44
46
|
const response = (await chain.invoke({ text }));
|
|
45
47
|
let isFirstTool = true;
|
|
46
|
-
logger.verbose("invoke", {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
logger.verbose("invoke", {
|
|
49
|
+
text,
|
|
50
|
+
response: response.content,
|
|
49
51
|
hasTools: response.tool_calls?.length > 0,
|
|
50
52
|
tools: response.tool_calls?.map((tool) => tool.name)
|
|
51
53
|
});
|
|
54
|
+
// Begin the conversation with the first message
|
|
55
|
+
if ((await chatHistory.getMessages()).length === 0 && this.firstMessage) {
|
|
56
|
+
await chatHistory.addAIMessage(this.firstMessage);
|
|
57
|
+
}
|
|
52
58
|
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
53
59
|
// eslint-disable-next-line no-loops/no-loops
|
|
54
60
|
for (const toolCall of response.tool_calls) {
|
|
@@ -58,17 +64,19 @@ class AbstractLanguageModel {
|
|
|
58
64
|
});
|
|
59
65
|
switch (toolName) {
|
|
60
66
|
case "hangup":
|
|
61
|
-
await chatHistory.
|
|
67
|
+
await chatHistory.addUserMessage(text);
|
|
68
|
+
await chatHistory.addAIMessage(this.goodbyeMessage);
|
|
62
69
|
return {
|
|
63
70
|
type: "hangup",
|
|
64
|
-
content: "
|
|
71
|
+
content: "tool_result: call hangup initiated",
|
|
65
72
|
toolCalls: response.tool_calls
|
|
66
73
|
};
|
|
67
74
|
case "transfer":
|
|
68
|
-
await chatHistory.
|
|
75
|
+
await chatHistory.addUserMessage(text);
|
|
76
|
+
await chatHistory.addAIMessage(this.transferOptions.message);
|
|
69
77
|
return {
|
|
70
78
|
type: "transfer",
|
|
71
|
-
content: "
|
|
79
|
+
content: "tool_result: call transfer initiated",
|
|
72
80
|
toolCalls: response.tool_calls
|
|
73
81
|
};
|
|
74
82
|
default:
|
package/dist/models/types.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { CallDirection } from "@fonoster/types";
|
|
2
2
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
import { KnowledgeBase } from "../knowledge";
|
|
4
3
|
import { Tool } from "../tools/type";
|
|
5
4
|
import { ToolCall } from "@langchain/core/messages/tool";
|
|
5
|
+
import { KnowledgeBase } from "../knowledge";
|
|
6
6
|
type LanguageModel = {
|
|
7
7
|
invoke: (text: string) => Promise<InvocationResult>;
|
|
8
8
|
};
|
|
9
9
|
type BaseModelParams = {
|
|
10
10
|
firstMessage?: string;
|
|
11
|
+
goodbyeMessage?: string;
|
|
12
|
+
transferOptions: {
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
11
15
|
systemPrompt: string;
|
|
12
16
|
knowledgeBase: KnowledgeBase;
|
|
13
17
|
tools: Tool[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.65",
|
|
4
4
|
"description": "Voice AI for the Fonoster platform",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@aws-sdk/client-s3": "^3.712.0",
|
|
36
36
|
"@fonoster/common": "^0.8.64",
|
|
37
37
|
"@fonoster/logger": "^0.8.59",
|
|
38
|
-
"@fonoster/sdk": "^0.8.
|
|
38
|
+
"@fonoster/sdk": "^0.8.65",
|
|
39
39
|
"@fonoster/types": "^0.8.59",
|
|
40
|
-
"@fonoster/voice": "^0.8.
|
|
40
|
+
"@fonoster/voice": "^0.8.65",
|
|
41
41
|
"@langchain/community": "^0.3.29",
|
|
42
42
|
"@langchain/core": "^0.3.39",
|
|
43
43
|
"@langchain/groq": "^0.1.3",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"typescript": "^5.5.4"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "eebe765c78a8a39a1254fceca416e919d0415c3d"
|
|
61
61
|
}
|