llmasaservice-client 0.8.0 → 0.9.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/dist/index.d.mts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +3 -7
- package/dist/index.mjs +3 -7
- package/package.json +4 -1
- package/CHANGELOG.md +0 -165
- package/index.ts +0 -3
- package/src/LLMAsAService.tsx +0 -47
- package/src/useLLM.ts +0 -217
- package/tsconfig.json +0 -108
package/dist/index.d.mts
CHANGED
|
@@ -11,8 +11,6 @@ interface LLMServiceType {
|
|
|
11
11
|
customer?: LLMAsAServiceCustomer;
|
|
12
12
|
url?: string | null;
|
|
13
13
|
agent?: string | null;
|
|
14
|
-
ragQueryLimit?: number | null;
|
|
15
|
-
ragRankLimit?: number | null;
|
|
16
14
|
}
|
|
17
15
|
declare const LLMService: React.Context<LLMServiceType | undefined>;
|
|
18
16
|
interface UserProviderProps {
|
|
@@ -21,8 +19,6 @@ interface UserProviderProps {
|
|
|
21
19
|
customer?: LLMAsAServiceCustomer;
|
|
22
20
|
url?: string | null;
|
|
23
21
|
agent?: string | null;
|
|
24
|
-
ragQueryLimit?: number | null;
|
|
25
|
-
ragRankLimit?: number | null;
|
|
26
22
|
}
|
|
27
23
|
declare const LLMServiceProvider: React.FC<UserProviderProps>;
|
|
28
24
|
|
|
@@ -37,4 +33,4 @@ interface UseLLMReturnType {
|
|
|
37
33
|
}
|
|
38
34
|
declare const useLLM: (options?: LLMServiceType) => UseLLMReturnType;
|
|
39
35
|
|
|
40
|
-
export { type LLMAsAServiceCustomer, LLMService, LLMServiceProvider, type LLMServiceType, useLLM };
|
|
36
|
+
export { type LLMAsAServiceCustomer, LLMService, LLMServiceProvider, type LLMServiceType, type UseLLMReturnType, useLLM };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ interface LLMServiceType {
|
|
|
11
11
|
customer?: LLMAsAServiceCustomer;
|
|
12
12
|
url?: string | null;
|
|
13
13
|
agent?: string | null;
|
|
14
|
-
ragQueryLimit?: number | null;
|
|
15
|
-
ragRankLimit?: number | null;
|
|
16
14
|
}
|
|
17
15
|
declare const LLMService: React.Context<LLMServiceType | undefined>;
|
|
18
16
|
interface UserProviderProps {
|
|
@@ -21,8 +19,6 @@ interface UserProviderProps {
|
|
|
21
19
|
customer?: LLMAsAServiceCustomer;
|
|
22
20
|
url?: string | null;
|
|
23
21
|
agent?: string | null;
|
|
24
|
-
ragQueryLimit?: number | null;
|
|
25
|
-
ragRankLimit?: number | null;
|
|
26
22
|
}
|
|
27
23
|
declare const LLMServiceProvider: React.FC<UserProviderProps>;
|
|
28
24
|
|
|
@@ -37,4 +33,4 @@ interface UseLLMReturnType {
|
|
|
37
33
|
}
|
|
38
34
|
declare const useLLM: (options?: LLMServiceType) => UseLLMReturnType;
|
|
39
35
|
|
|
40
|
-
export { type LLMAsAServiceCustomer, LLMService, LLMServiceProvider, type LLMServiceType, useLLM };
|
|
36
|
+
export { type LLMAsAServiceCustomer, LLMService, LLMServiceProvider, type LLMServiceType, type UseLLMReturnType, useLLM };
|
package/dist/index.js
CHANGED
|
@@ -67,11 +67,9 @@ var LLMServiceProvider = ({
|
|
|
67
67
|
project_id,
|
|
68
68
|
customer,
|
|
69
69
|
url = "https://chat.llmasaservice.io/",
|
|
70
|
-
agent = null
|
|
71
|
-
ragQueryLimit = null,
|
|
72
|
-
ragRankLimit = null
|
|
70
|
+
agent = null
|
|
73
71
|
}) => {
|
|
74
|
-
return /* @__PURE__ */ import_react.default.createElement(LLMService.Provider, { value: { project_id, customer, url, agent
|
|
72
|
+
return /* @__PURE__ */ import_react.default.createElement(LLMService.Provider, { value: { project_id, customer, url, agent } }, children);
|
|
75
73
|
};
|
|
76
74
|
|
|
77
75
|
// src/useLLM.ts
|
|
@@ -109,9 +107,7 @@ var useLLM = (options) => {
|
|
|
109
107
|
customer: (_b = context == null ? void 0 : context.customer) != null ? _b : {},
|
|
110
108
|
// if no customer, use the projectId as the customer_id
|
|
111
109
|
allowCaching,
|
|
112
|
-
conversationId: conversation
|
|
113
|
-
ragQueryLimit: context == null ? void 0 : context.ragQueryLimit,
|
|
114
|
-
ragRankLimit: context == null ? void 0 : context.ragRankLimit
|
|
110
|
+
conversationId: conversation
|
|
115
111
|
});
|
|
116
112
|
const options2 = {
|
|
117
113
|
method: "POST",
|
package/dist/index.mjs
CHANGED
|
@@ -30,11 +30,9 @@ var LLMServiceProvider = ({
|
|
|
30
30
|
project_id,
|
|
31
31
|
customer,
|
|
32
32
|
url = "https://chat.llmasaservice.io/",
|
|
33
|
-
agent = null
|
|
34
|
-
ragQueryLimit = null,
|
|
35
|
-
ragRankLimit = null
|
|
33
|
+
agent = null
|
|
36
34
|
}) => {
|
|
37
|
-
return /* @__PURE__ */ React.createElement(LLMService.Provider, { value: { project_id, customer, url, agent
|
|
35
|
+
return /* @__PURE__ */ React.createElement(LLMService.Provider, { value: { project_id, customer, url, agent } }, children);
|
|
38
36
|
};
|
|
39
37
|
|
|
40
38
|
// src/useLLM.ts
|
|
@@ -72,9 +70,7 @@ var useLLM = (options) => {
|
|
|
72
70
|
customer: (_b = context == null ? void 0 : context.customer) != null ? _b : {},
|
|
73
71
|
// if no customer, use the projectId as the customer_id
|
|
74
72
|
allowCaching,
|
|
75
|
-
conversationId: conversation
|
|
76
|
-
ragQueryLimit: context == null ? void 0 : context.ragQueryLimit,
|
|
77
|
-
ragRankLimit: context == null ? void 0 : context.ragRankLimit
|
|
73
|
+
conversationId: conversation
|
|
78
74
|
});
|
|
79
75
|
const options2 = {
|
|
80
76
|
method: "POST",
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llmasaservice-client",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsup index.ts --format cjs,esm --dts",
|
|
10
13
|
"lint": "tsc"
|
package/CHANGELOG.md
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# llmasaservice-client
|
|
2
|
-
|
|
3
|
-
## 0.8.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- Adding agent query limit values
|
|
8
|
-
|
|
9
|
-
## 0.7.0
|
|
10
|
-
|
|
11
|
-
### Minor Changes
|
|
12
|
-
|
|
13
|
-
- moved agent to the context and added conversation id
|
|
14
|
-
|
|
15
|
-
## 0.6.0
|
|
16
|
-
|
|
17
|
-
### Minor Changes
|
|
18
|
-
|
|
19
|
-
- pushing agent into the chat
|
|
20
|
-
|
|
21
|
-
## 0.6.0
|
|
22
|
-
|
|
23
|
-
### Minor Changes
|
|
24
|
-
|
|
25
|
-
- Adding agent id
|
|
26
|
-
|
|
27
|
-
## 0.5.0
|
|
28
|
-
|
|
29
|
-
### Minor Changes
|
|
30
|
-
|
|
31
|
-
- Adding the ability to pass data to the chat service
|
|
32
|
-
|
|
33
|
-
## 0.4.0
|
|
34
|
-
|
|
35
|
-
### Minor Changes
|
|
36
|
-
|
|
37
|
-
- Added the ability to disable cache for some calls on send
|
|
38
|
-
|
|
39
|
-
## 0.3.0
|
|
40
|
-
|
|
41
|
-
### Minor Changes
|
|
42
|
-
|
|
43
|
-
- Final onComplete and onError callbacks added to the send method
|
|
44
|
-
|
|
45
|
-
## 0.2.5
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Debugging callback
|
|
50
|
-
|
|
51
|
-
## 0.2.4
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- new callback signature
|
|
56
|
-
|
|
57
|
-
## 0.2.3
|
|
58
|
-
|
|
59
|
-
### Patch Changes
|
|
60
|
-
|
|
61
|
-
- Fixed callback
|
|
62
|
-
|
|
63
|
-
## 0.2.2
|
|
64
|
-
|
|
65
|
-
### Patch Changes
|
|
66
|
-
|
|
67
|
-
- Build fix
|
|
68
|
-
|
|
69
|
-
## 0.2.1
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- callback on complete bug fix
|
|
74
|
-
|
|
75
|
-
## 0.2.0
|
|
76
|
-
|
|
77
|
-
### Minor Changes
|
|
78
|
-
|
|
79
|
-
- Added onCompleteCallback to send
|
|
80
|
-
|
|
81
|
-
## 0.1.2
|
|
82
|
-
|
|
83
|
-
### Patch Changes
|
|
84
|
-
|
|
85
|
-
- New non stream send functionality added to return string directly
|
|
86
|
-
|
|
87
|
-
## 0.1.1
|
|
88
|
-
|
|
89
|
-
### Patch Changes
|
|
90
|
-
|
|
91
|
-
- non stream send returns string directly
|
|
92
|
-
- non stream send returns a string rather than setting response
|
|
93
|
-
|
|
94
|
-
## 0.1.0
|
|
95
|
-
|
|
96
|
-
### Minor Changes
|
|
97
|
-
|
|
98
|
-
- URL can be passed as null
|
|
99
|
-
- more small fixes
|
|
100
|
-
|
|
101
|
-
## 0.0.12
|
|
102
|
-
|
|
103
|
-
### Patch Changes
|
|
104
|
-
|
|
105
|
-
- Minor fixes
|
|
106
|
-
|
|
107
|
-
## 0.0.11
|
|
108
|
-
|
|
109
|
-
### Patch Changes
|
|
110
|
-
|
|
111
|
-
- More NPM ignores to reduce package size
|
|
112
|
-
|
|
113
|
-
## 0.0.10
|
|
114
|
-
|
|
115
|
-
### Patch Changes
|
|
116
|
-
|
|
117
|
-
- Removing images from NPM package
|
|
118
|
-
|
|
119
|
-
## 0.0.9
|
|
120
|
-
|
|
121
|
-
### Patch Changes
|
|
122
|
-
|
|
123
|
-
- Added next.js / react example
|
|
124
|
-
|
|
125
|
-
## 0.0.8
|
|
126
|
-
|
|
127
|
-
### Patch Changes
|
|
128
|
-
|
|
129
|
-
- Exposed return type for useLLM
|
|
130
|
-
|
|
131
|
-
## 0.0.7
|
|
132
|
-
|
|
133
|
-
### Patch Changes
|
|
134
|
-
|
|
135
|
-
- More export changes.
|
|
136
|
-
|
|
137
|
-
## 0.0.6
|
|
138
|
-
|
|
139
|
-
### Patch Changes
|
|
140
|
-
|
|
141
|
-
- Changing the call signatures and exports
|
|
142
|
-
|
|
143
|
-
## 0.0.5
|
|
144
|
-
|
|
145
|
-
### Patch Changes
|
|
146
|
-
|
|
147
|
-
- Changing the call signatures of useLLM
|
|
148
|
-
|
|
149
|
-
## 0.0.4
|
|
150
|
-
|
|
151
|
-
### Patch Changes
|
|
152
|
-
|
|
153
|
-
- bc13d7a: Immages pointing to GitHub
|
|
154
|
-
|
|
155
|
-
## 0.0.3
|
|
156
|
-
|
|
157
|
-
### Patch Changes
|
|
158
|
-
|
|
159
|
-
- Fixing images in readme
|
|
160
|
-
|
|
161
|
-
## 0.0.2
|
|
162
|
-
|
|
163
|
-
### Patch Changes
|
|
164
|
-
|
|
165
|
-
- Added documentation and making the customer optional for calls
|
package/index.ts
DELETED
package/src/LLMAsAService.tsx
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React, { createContext, ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
export type LLMAsAServiceCustomer = {
|
|
4
|
-
customer_id: string;
|
|
5
|
-
customer_name?: string;
|
|
6
|
-
customer_user_id?: string;
|
|
7
|
-
customer_user_email?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export interface LLMServiceType {
|
|
11
|
-
project_id: string | undefined;
|
|
12
|
-
customer?: LLMAsAServiceCustomer;
|
|
13
|
-
url?: string | null;
|
|
14
|
-
agent?: string | null;
|
|
15
|
-
ragQueryLimit?: number | null;
|
|
16
|
-
ragRankLimit?: number | null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const LLMService = createContext<LLMServiceType | undefined>(undefined);
|
|
20
|
-
|
|
21
|
-
interface UserProviderProps {
|
|
22
|
-
children: ReactNode;
|
|
23
|
-
project_id: string | undefined;
|
|
24
|
-
customer?: LLMAsAServiceCustomer;
|
|
25
|
-
url?: string | null;
|
|
26
|
-
agent?: string | null;
|
|
27
|
-
ragQueryLimit?: number | null;
|
|
28
|
-
ragRankLimit?: number | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const LLMServiceProvider: React.FC<UserProviderProps> = ({
|
|
32
|
-
children,
|
|
33
|
-
project_id,
|
|
34
|
-
customer,
|
|
35
|
-
url = "https://chat.llmasaservice.io/",
|
|
36
|
-
agent = null,
|
|
37
|
-
ragQueryLimit = null,
|
|
38
|
-
ragRankLimit = null,
|
|
39
|
-
}) => {
|
|
40
|
-
return (
|
|
41
|
-
<LLMService.Provider value={{ project_id, customer, url, agent, ragQueryLimit, ragRankLimit }}>
|
|
42
|
-
{children}
|
|
43
|
-
</LLMService.Provider>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export default LLMServiceProvider;
|
package/src/useLLM.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { useContext, useState } from "react";
|
|
2
|
-
import { LLMService, LLMServiceType } from "./LLMAsAService";
|
|
3
|
-
|
|
4
|
-
export interface UseLLMReturnType {
|
|
5
|
-
send: Function;
|
|
6
|
-
stop: Function;
|
|
7
|
-
response: string;
|
|
8
|
-
idle: boolean;
|
|
9
|
-
error: string;
|
|
10
|
-
setResponse: Function;
|
|
11
|
-
lastCallId: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useLLM = (options?: LLMServiceType): UseLLMReturnType => {
|
|
15
|
-
const [response, setResponse] = useState<string>("");
|
|
16
|
-
const [idle, setIdle] = useState<boolean>(true);
|
|
17
|
-
const [error, setError] = useState<string>("");
|
|
18
|
-
const [lastCallId, setLastCallId] = useState<string>("");
|
|
19
|
-
|
|
20
|
-
let context = useContext(LLMService);
|
|
21
|
-
if (!context) {
|
|
22
|
-
context = options;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!context) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"useLLM must be used within a LLMServiceProvider or constructed with options in your useLLM() call."
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Stops the fetch request and returns the hook to an idle state. Use this to add abort functionality to your UI.
|
|
33
|
-
*
|
|
34
|
-
* @param controller An AbortController object to stop the fetch request and return this hook to an idle state, the controller should be the same one passed to the send function.
|
|
35
|
-
*/
|
|
36
|
-
const stop = (controller: AbortController | null) => {
|
|
37
|
-
if (controller) controller.abort();
|
|
38
|
-
setIdle(true);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Calls the LLM as a service with the given prompt and messages. The response is returned in the response property of the hook.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} prompt - The prompt to send to the LLM service.
|
|
45
|
-
* @param {Array<{role: string, content: string}>} messages - The history and context messages to send to the LLM service, as an array of {role: string, content: string} objects. For example, [{ role: "system", content: "You are a useful assistant." }]
|
|
46
|
-
* @param {Array<{key: string, data: string}>} data - The data to send to the LLM service, as an array of {key: string, data: string} objects. For example, [{ key: "name", value: "John" }]
|
|
47
|
-
* @param {boolean} stream - Determines whether to stream results back in the response property as they return from the service or batch them up and return them all at once in the response property as a string.
|
|
48
|
-
* @param {boolean} allowCaching - Determines whether the service can use cached results or not.
|
|
49
|
-
* @param {string | null} service - The service to use for the request. If null, load balancing will be applied. This is typically only used for testing.
|
|
50
|
-
* @param {string | null} conversation - The conversation of this request. If null, this is a one off call with no conversation history
|
|
51
|
-
* @param {AbortController} abortController - The AbortController used to abort this request once it's started. This allows you to add a stop button to your UI.
|
|
52
|
-
* @param {(result: string) => void} onComplete - The callback function to be called once the stream completes, with the final result string.
|
|
53
|
-
* @param {(error: string) => void} onError - The callback function to be called if an error occurs, with the error string.
|
|
54
|
-
* @returns {Promise<ReadableStreamDefaultReader<any> | string | undefined>} - A StreamReader object if stream is true, otherwise a string of the response. Typically this isn't used when streaming, the stream is exposed in the response property.
|
|
55
|
-
*/
|
|
56
|
-
async function send(
|
|
57
|
-
prompt: string,
|
|
58
|
-
messages = [],
|
|
59
|
-
data = [],
|
|
60
|
-
stream: boolean = true,
|
|
61
|
-
allowCaching: boolean = true,
|
|
62
|
-
service: string | null = null, // null means use the default service and apply services load balancing
|
|
63
|
-
conversation: string | null = null,
|
|
64
|
-
abortController: AbortController = new AbortController(),
|
|
65
|
-
onComplete?: (result: string) => void,
|
|
66
|
-
onError?: (error: string) => void
|
|
67
|
-
): Promise<ReadableStreamDefaultReader<any> | string | undefined> {
|
|
68
|
-
setResponse("");
|
|
69
|
-
setIdle(false);
|
|
70
|
-
|
|
71
|
-
let errorInFetch = "";
|
|
72
|
-
|
|
73
|
-
const responseBody = JSON.stringify({
|
|
74
|
-
projectId: context?.project_id ?? "",
|
|
75
|
-
serviceId: service,
|
|
76
|
-
agentId: context?.agent,
|
|
77
|
-
prompt: prompt,
|
|
78
|
-
messages: messages,
|
|
79
|
-
data: data,
|
|
80
|
-
customer: context?.customer ?? {}, // if no customer, use the projectId as the customer_id
|
|
81
|
-
allowCaching: allowCaching,
|
|
82
|
-
conversationId: conversation,
|
|
83
|
-
ragQueryLimit: context?.ragQueryLimit,
|
|
84
|
-
ragRankLimit: context?.ragRankLimit,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// trying to get cloudfront oac going. posts need to be signed, but when i add this the call fails...
|
|
88
|
-
const options = {
|
|
89
|
-
method: "POST",
|
|
90
|
-
signal: abortController.signal,
|
|
91
|
-
mode: "cors" as RequestMode,
|
|
92
|
-
headers: {
|
|
93
|
-
"Content-Type": "text/plain",
|
|
94
|
-
},
|
|
95
|
-
body: responseBody,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const url = context?.url ?? "https://chat.llmasaservice.io/";
|
|
100
|
-
const response = await fetch(url, options);
|
|
101
|
-
if (!response.ok) {
|
|
102
|
-
errorInFetch = `Error: Network error for service. (${response.status} ${response.statusText})`;
|
|
103
|
-
} else {
|
|
104
|
-
setLastCallId(response.headers.get("x-callId") ?? "");
|
|
105
|
-
const reader =
|
|
106
|
-
response?.body?.getReader() as ReadableStreamDefaultReader;
|
|
107
|
-
const decoder = new TextDecoder("utf-8");
|
|
108
|
-
setIdle(false);
|
|
109
|
-
|
|
110
|
-
if (!stream) {
|
|
111
|
-
return await readStream(
|
|
112
|
-
reader,
|
|
113
|
-
decoder,
|
|
114
|
-
stream,
|
|
115
|
-
{
|
|
116
|
-
signal: options.signal,
|
|
117
|
-
},
|
|
118
|
-
onComplete,
|
|
119
|
-
onError
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
readStream(
|
|
123
|
-
reader,
|
|
124
|
-
decoder,
|
|
125
|
-
stream,
|
|
126
|
-
{
|
|
127
|
-
signal: options.signal,
|
|
128
|
-
},
|
|
129
|
-
onComplete,
|
|
130
|
-
onError
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
return reader;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} catch (errorObject: any) {
|
|
137
|
-
errorInFetch = `Error: Having trouble connecting to chat service. (${errorObject.message})`;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (errorInFetch !== "") {
|
|
141
|
-
setError(errorInFetch);
|
|
142
|
-
if (onError) {
|
|
143
|
-
onError(errorInFetch);
|
|
144
|
-
}
|
|
145
|
-
console.error(`Error: Error in fetch. (${errorInFetch})`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function readStream(
|
|
150
|
-
reader: ReadableStreamDefaultReader,
|
|
151
|
-
decoder: TextDecoder,
|
|
152
|
-
stream: Boolean = true,
|
|
153
|
-
{ signal: signal }: { signal: AbortSignal },
|
|
154
|
-
onComplete?: (result: string) => void,
|
|
155
|
-
onError?: (error: string) => void
|
|
156
|
-
): Promise<string> {
|
|
157
|
-
let errorInRead = "";
|
|
158
|
-
let result = "";
|
|
159
|
-
|
|
160
|
-
while (true) {
|
|
161
|
-
try {
|
|
162
|
-
// Check if the stream has been aborted
|
|
163
|
-
if (signal.aborted) {
|
|
164
|
-
reader.cancel();
|
|
165
|
-
setIdle(true);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Read a chunk of data from the stream
|
|
170
|
-
const { value, done } = await reader.read();
|
|
171
|
-
|
|
172
|
-
if (decoder.decode(value).startsWith("Error:")) {
|
|
173
|
-
errorInRead = decoder.decode(value).substring(6);
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// If the stream has been read to the end, exit the loop
|
|
178
|
-
if (done) {
|
|
179
|
-
setIdle(true);
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Process the chunk of data
|
|
184
|
-
result += decoder.decode(value);
|
|
185
|
-
if (stream) setResponse((prevState: any) => result);
|
|
186
|
-
} catch (error: any) {
|
|
187
|
-
if (error.name === "AbortError") {
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
errorInRead = `Reading error ${error.message}`;
|
|
192
|
-
break;
|
|
193
|
-
} finally {
|
|
194
|
-
if (signal.aborted) {
|
|
195
|
-
reader.releaseLock();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (errorInRead !== "") {
|
|
201
|
-
setError(errorInRead);
|
|
202
|
-
reader.cancel();
|
|
203
|
-
if (onError) onError(errorInRead);
|
|
204
|
-
setIdle(true);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (onComplete) {
|
|
208
|
-
onComplete(result);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return { response, send, stop, idle, error, setResponse, lastCallId };
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export default useLLM;
|
package/tsconfig.json
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
-
"jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
-
|
|
27
|
-
/* Modules */
|
|
28
|
-
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
-
|
|
46
|
-
/* JavaScript Support */
|
|
47
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
-
|
|
51
|
-
/* Emit */
|
|
52
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
-
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
59
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
-
"noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
63
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
64
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
65
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
66
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
67
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
68
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
69
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
70
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
71
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
72
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
73
|
-
|
|
74
|
-
/* Interop Constraints */
|
|
75
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
76
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
77
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
78
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
79
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
80
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
81
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
82
|
-
|
|
83
|
-
/* Type Checking */
|
|
84
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
85
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
86
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
87
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
88
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
89
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
90
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
91
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
92
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
93
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
94
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
95
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
96
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
97
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
98
|
-
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
99
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
100
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
101
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
102
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
103
|
-
|
|
104
|
-
/* Completeness */
|
|
105
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
106
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
107
|
-
}
|
|
108
|
-
}
|