@cmnd-ai/chatbot-react 1.5.0 → 1.7.0
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import StreamError from "./StreamError.js";
|
|
1
2
|
const processStream = async (reader, onData) => {
|
|
2
3
|
if (!onData)
|
|
3
4
|
return;
|
|
@@ -25,28 +26,32 @@ const processStream = async (reader, onData) => {
|
|
|
25
26
|
if (dataString === "[DONE]") {
|
|
26
27
|
onData({
|
|
27
28
|
completionFinished: true,
|
|
28
|
-
finalResponseWithUsageData: false
|
|
29
|
+
finalResponseWithUsageData: false,
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
33
|
try {
|
|
33
34
|
const dataObject = JSON.parse(fullMessageContext + dataString);
|
|
34
35
|
if (dataObject.error) {
|
|
35
|
-
throw new
|
|
36
|
+
throw new StreamError({
|
|
37
|
+
error: dataObject.error,
|
|
38
|
+
path: dataObject.path,
|
|
39
|
+
message: dataObject.error,
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
if (dataObject.content) {
|
|
38
43
|
fullAssistantMessage += dataObject.content;
|
|
39
44
|
onData({
|
|
40
45
|
completionFinished: false,
|
|
41
46
|
finalResponseWithUsageData: false,
|
|
42
|
-
message: fullAssistantMessage
|
|
47
|
+
message: fullAssistantMessage,
|
|
43
48
|
});
|
|
44
49
|
}
|
|
45
50
|
else {
|
|
46
51
|
//at this point, the dataObject does not have a content propery
|
|
47
52
|
//and it is completed
|
|
48
53
|
//get the last message from the dataObject to check if it is a function call
|
|
49
|
-
const { messages, completionFinished, finalResponseWithUsageData, chatbotConversationId, conversationId, totalTokens, totalCost } = dataObject;
|
|
54
|
+
const { messages, completionFinished, finalResponseWithUsageData, chatbotConversationId, conversationId, totalTokens, totalCost, } = dataObject;
|
|
50
55
|
onData({
|
|
51
56
|
messages,
|
|
52
57
|
completionFinished,
|
|
@@ -54,25 +59,31 @@ const processStream = async (reader, onData) => {
|
|
|
54
59
|
conversationId,
|
|
55
60
|
chatbotConversationId,
|
|
56
61
|
totalTokens,
|
|
57
|
-
totalCost
|
|
62
|
+
totalCost,
|
|
58
63
|
});
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
catch (error) {
|
|
62
|
-
|
|
67
|
+
console.error("Error processing stream", error);
|
|
68
|
+
onData({
|
|
69
|
+
completionFinished: true,
|
|
70
|
+
message: error instanceof StreamError
|
|
71
|
+
? error.message
|
|
72
|
+
: "Oops! I ran into a problem.",
|
|
73
|
+
finalResponseWithUsageData: true,
|
|
74
|
+
});
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
catch (error) {
|
|
81
|
+
console.error("Error processing stream", error);
|
|
69
82
|
onData({
|
|
70
83
|
completionFinished: true,
|
|
71
|
-
message:
|
|
72
|
-
finalResponseWithUsageData: true
|
|
84
|
+
message: "Oops! I ran into a problem.",
|
|
85
|
+
finalResponseWithUsageData: true,
|
|
73
86
|
});
|
|
74
|
-
console.error(error);
|
|
75
|
-
throw new Error(error);
|
|
76
87
|
}
|
|
77
88
|
};
|
|
78
89
|
export default processStream;
|
package/package.json
CHANGED
package/readme.dev.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Development README for @cmnd-ai/chatbot-react
|
|
2
|
+
|
|
3
|
+
## Getting Started (Development)
|
|
4
|
+
|
|
5
|
+
1. **Install dependencies:**
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
2. **Start the development server:**
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm run dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
3. **Link the package locally:**
|
|
18
|
+
In a separate terminal, run:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm link
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
4. **Test in another project:**
|
|
25
|
+
In the project where you want to use `@cmnd-ai/chatbot-react`, run:
|
|
26
|
+
```sh
|
|
27
|
+
npm link @cmnd-ai/chatbot-react
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This will allow you to test your local changes in another project without publishing to npm.
|