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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # llmasaservice-client
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - callback on complete bug fix
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added onCompleteCallback to send
14
+
3
15
  ## 0.1.2
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "llmasaservice-client",
3
3
  "license": "MIT",
4
- "version": "0.1.2",
4
+ "version": "0.2.1",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
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