llmasaservice-client 0.1.2 → 0.2.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/useLLM.ts +12 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/useLLM.ts
CHANGED
|
@@ -53,7 +53,8 @@ export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
|
|
|
53
53
|
messages = [],
|
|
54
54
|
stream: boolean = true,
|
|
55
55
|
abortController: AbortController = new AbortController(),
|
|
56
|
-
service: string | null = null // null means use the default service and apply services load balancing
|
|
56
|
+
service: string | null = null, // null means use the default service and apply services load balancing
|
|
57
|
+
onCompleteCallback?: Function
|
|
57
58
|
): Promise<ReadableStreamDefaultReader<any> | string | undefined> {
|
|
58
59
|
setResponse("");
|
|
59
60
|
setIdle(false);
|
|
@@ -94,11 +95,11 @@ export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
|
|
|
94
95
|
if (!stream) {
|
|
95
96
|
return await readStream(reader, decoder, stream, {
|
|
96
97
|
signal: options.signal,
|
|
97
|
-
});
|
|
98
|
+
}, onCompleteCallback);
|
|
98
99
|
} else {
|
|
99
100
|
readStream(reader, decoder, stream, {
|
|
100
101
|
signal: options.signal,
|
|
101
|
-
});
|
|
102
|
+
}, onCompleteCallback);
|
|
102
103
|
|
|
103
104
|
return reader;
|
|
104
105
|
}
|
|
@@ -117,7 +118,8 @@ export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
|
|
|
117
118
|
reader: ReadableStreamDefaultReader,
|
|
118
119
|
decoder: TextDecoder,
|
|
119
120
|
stream: Boolean = true,
|
|
120
|
-
{ signal: signal }: { signal: AbortSignal }
|
|
121
|
+
{ signal: signal }: { signal: AbortSignal },
|
|
122
|
+
onCompleteCallback?: Function
|
|
121
123
|
): Promise<string> {
|
|
122
124
|
let errorInRead = "";
|
|
123
125
|
let result = "";
|
|
@@ -142,6 +144,12 @@ export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
|
|
|
142
144
|
// If the stream has been read to the end, exit the loop
|
|
143
145
|
if (done) {
|
|
144
146
|
setIdle(true);
|
|
147
|
+
|
|
148
|
+
if (onCompleteCallback) {
|
|
149
|
+
onCompleteCallback(result);
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
145
153
|
break;
|
|
146
154
|
}
|
|
147
155
|
|