llmasaservice-client 0.1.2 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # llmasaservice-client
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added onCompleteCallback to send
8
+
3
9
  ## 0.1.2
4
10
 
5
11
  ### 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.0",
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);
@@ -98,7 +99,7 @@ export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
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,11 @@ 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
+
145
152
  break;
146
153
  }
147
154