@alquimia-ai/tools 1.0.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/README.md +38 -0
- package/dist/index.d.mts +322 -0
- package/dist/index.d.ts +322 -0
- package/dist/index.js +2582 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2336 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @alquimia-ai/tools
|
|
2
|
+
|
|
3
|
+
Tools for Alquimia SDK.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Available Components](#available-components)
|
|
10
|
+
- [Development](#development)
|
|
11
|
+
- [Contributing](#contributing)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install the `@alquimia-ai/tools` package, use the following command:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
yarn add @alquimia-ai/tools
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or with npm:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install @alquimia-ai/tools
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Available Features
|
|
29
|
+
|
|
30
|
+
- **Context**: Session and user context.
|
|
31
|
+
- **Hooks**: Main hook that applies the SDK and most important chat behaviour.
|
|
32
|
+
- **SDK Class and providers**: Main SDK class with its providers.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
This project is licensed under the MIT License. See the LICENSE file for more details.
|
|
38
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import { Message } from 'ai';
|
|
4
|
+
|
|
5
|
+
interface ButtonProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
appName: string;
|
|
9
|
+
}
|
|
10
|
+
declare const Button: ({ children, className, appName }: ButtonProps) => react.JSX.Element;
|
|
11
|
+
|
|
12
|
+
declare function Card({ className, title, children, href, }: {
|
|
13
|
+
className?: string;
|
|
14
|
+
title: string;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
href: string;
|
|
17
|
+
}): JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function Code({ children, className, }: {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
}): JSX.Element;
|
|
23
|
+
|
|
24
|
+
declare abstract class GenerativeProvider {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: Record<string, any>);
|
|
27
|
+
}
|
|
28
|
+
declare abstract class WhisperProvider {
|
|
29
|
+
protected config: Record<string, any>;
|
|
30
|
+
constructor(config: Record<string, any>);
|
|
31
|
+
abstract textToSpeech(text: string): Promise<Blob>;
|
|
32
|
+
abstract speechToText(audio: string): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
declare abstract class StableDiffusionProvider {
|
|
35
|
+
protected config: Record<string, any>;
|
|
36
|
+
constructor(config: Record<string, any>);
|
|
37
|
+
abstract generateImage(query: string): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
declare abstract class CharacterizationProvider {
|
|
40
|
+
protected config: Record<string, any>;
|
|
41
|
+
constructor(config: Record<string, any>);
|
|
42
|
+
abstract analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
43
|
+
}
|
|
44
|
+
declare abstract class RatingsProvider {
|
|
45
|
+
protected config: Record<string, any>;
|
|
46
|
+
constructor(config: Record<string, any>);
|
|
47
|
+
abstract rate(data: Record<string, any>): Promise<Record<string, any>>;
|
|
48
|
+
}
|
|
49
|
+
declare abstract class LoggerProvider {
|
|
50
|
+
protected config: Record<string, any>;
|
|
51
|
+
constructor(config: Record<string, any>);
|
|
52
|
+
abstract logInfo(message: string, data?: Record<string, any>): void;
|
|
53
|
+
abstract logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AlquimiaSDKConfig {
|
|
57
|
+
apiKey: string;
|
|
58
|
+
chatUrl: string;
|
|
59
|
+
streamUrl: string;
|
|
60
|
+
assistantId: string;
|
|
61
|
+
}
|
|
62
|
+
declare class AlquimiaSDK {
|
|
63
|
+
private config;
|
|
64
|
+
private axiosInstance;
|
|
65
|
+
private conversationId;
|
|
66
|
+
private sessionId;
|
|
67
|
+
private streamId;
|
|
68
|
+
private tools;
|
|
69
|
+
private extraData;
|
|
70
|
+
private forceProfile;
|
|
71
|
+
private whisperProvider?;
|
|
72
|
+
private stableDiffusionProvider?;
|
|
73
|
+
private analyzeCharacterizationProvider?;
|
|
74
|
+
private ratingsProvider?;
|
|
75
|
+
private loggerProvider?;
|
|
76
|
+
private enforceCharacterization?;
|
|
77
|
+
constructor(config: AlquimiaSDKConfig, enforceCharacterization?: boolean);
|
|
78
|
+
static configure(apiKey: string, inferUrl: string, streamUrl: string, assistantId: string): AlquimiaSDKConfig;
|
|
79
|
+
widthConversationId(conversationId: string): AlquimiaSDK;
|
|
80
|
+
withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
|
|
81
|
+
withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
|
|
82
|
+
withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
|
|
83
|
+
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
84
|
+
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
85
|
+
getEnforceCharacterization(): boolean;
|
|
86
|
+
withTools(tools: any[]): AlquimiaSDK;
|
|
87
|
+
withExtraData(extraData: any): AlquimiaSDK;
|
|
88
|
+
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
89
|
+
textToSpeech(text: string): Promise<Blob>;
|
|
90
|
+
speechToText(audio: string): Promise<string>;
|
|
91
|
+
sendMessage(query: string, traceParent?: string): Promise<this>;
|
|
92
|
+
generateImage(query: string): Promise<string>;
|
|
93
|
+
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
94
|
+
rate(data: any): Promise<Record<string, any>>;
|
|
95
|
+
logInfo(message: string, data: any): Promise<void>;
|
|
96
|
+
logError(message: string, error: Error, data: any): Promise<void>;
|
|
97
|
+
getUrlStream(): string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface AIMessageChunk {
|
|
101
|
+
type: string;
|
|
102
|
+
data?: AIMessageChunkData;
|
|
103
|
+
error_code?: string;
|
|
104
|
+
error_detail?: string;
|
|
105
|
+
}
|
|
106
|
+
interface AIMessageChunkData {
|
|
107
|
+
content: string;
|
|
108
|
+
additional_kwargs?: Record<string, unknown>;
|
|
109
|
+
response_metadata?: Record<string, unknown>;
|
|
110
|
+
type: string;
|
|
111
|
+
name?: string | null;
|
|
112
|
+
id?: string | null;
|
|
113
|
+
example?: boolean;
|
|
114
|
+
tool_calls?: ToolCall[];
|
|
115
|
+
invalid_tool_calls?: InvalidToolCall[];
|
|
116
|
+
usage_metadata?: any;
|
|
117
|
+
tool_call_chunks?: unknown[];
|
|
118
|
+
error_code?: string;
|
|
119
|
+
error_detail?: string;
|
|
120
|
+
}
|
|
121
|
+
type ToolCall = {
|
|
122
|
+
name: string;
|
|
123
|
+
args: Record<string, any>;
|
|
124
|
+
id?: string | null;
|
|
125
|
+
};
|
|
126
|
+
type InvalidToolCall = {
|
|
127
|
+
name: string | null;
|
|
128
|
+
args: string | null;
|
|
129
|
+
id: string | null;
|
|
130
|
+
error: string | null;
|
|
131
|
+
};
|
|
132
|
+
interface BaseAPIConfig {
|
|
133
|
+
baseUrl: string;
|
|
134
|
+
route: string;
|
|
135
|
+
token?: string;
|
|
136
|
+
headers?: Record<string, string>;
|
|
137
|
+
}
|
|
138
|
+
interface RatingData {
|
|
139
|
+
assistantId: string;
|
|
140
|
+
sessionId: string;
|
|
141
|
+
topicId: number;
|
|
142
|
+
score?: number;
|
|
143
|
+
description?: string;
|
|
144
|
+
}
|
|
145
|
+
interface ConversationsMap {
|
|
146
|
+
[topicId: string]: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare class AlquimiaWhisperProvider extends WhisperProvider {
|
|
150
|
+
constructor(config: {
|
|
151
|
+
baseURL: string;
|
|
152
|
+
ttsRoute: string;
|
|
153
|
+
sttRoute: string;
|
|
154
|
+
});
|
|
155
|
+
textToSpeech(text: string): Promise<any>;
|
|
156
|
+
speechToText(audio: string): Promise<string>;
|
|
157
|
+
}
|
|
158
|
+
declare class AlquimiaRatingsProvider extends RatingsProvider {
|
|
159
|
+
constructor(config: {
|
|
160
|
+
baseUrl: string;
|
|
161
|
+
route: string;
|
|
162
|
+
token: string;
|
|
163
|
+
headers?: Record<string, string>;
|
|
164
|
+
});
|
|
165
|
+
rate(data: RatingData): Promise<Record<string, any>>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
declare class OpenAIWhisperProvider extends WhisperProvider {
|
|
169
|
+
textToSpeech(text: string): Promise<Blob>;
|
|
170
|
+
speechToText(audio: string): Promise<string>;
|
|
171
|
+
}
|
|
172
|
+
declare class OpenAIAnalyzeCharProvider extends CharacterizationProvider {
|
|
173
|
+
private client;
|
|
174
|
+
constructor(config: Record<string, any>);
|
|
175
|
+
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
176
|
+
}
|
|
177
|
+
declare class OpenAIStableDiffusionProvider extends StableDiffusionProvider {
|
|
178
|
+
private client;
|
|
179
|
+
constructor(config: Record<string, any>);
|
|
180
|
+
generateImage(query: string): Promise<string>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class StabilityProvider extends StableDiffusionProvider {
|
|
184
|
+
constructor(config: Record<string, any>);
|
|
185
|
+
generateImage(query: string): Promise<string>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class ElevenLabsWhisperProvider extends WhisperProvider {
|
|
189
|
+
private client;
|
|
190
|
+
constructor(config: {
|
|
191
|
+
apiKey: string;
|
|
192
|
+
voiceId: string;
|
|
193
|
+
baseURL: string;
|
|
194
|
+
});
|
|
195
|
+
speechToText(audio: string): Promise<string>;
|
|
196
|
+
textToSpeech(text: string): Promise<any>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface ElasticLoggerConfig {
|
|
200
|
+
endpoint: string;
|
|
201
|
+
username: string;
|
|
202
|
+
password: string;
|
|
203
|
+
index?: string;
|
|
204
|
+
esVersion?: number;
|
|
205
|
+
flushBytes?: number;
|
|
206
|
+
}
|
|
207
|
+
declare class ElasticLoggerProvider extends LoggerProvider {
|
|
208
|
+
private logger;
|
|
209
|
+
private constructor();
|
|
210
|
+
static create(config: ElasticLoggerConfig): Promise<ElasticLoggerProvider>;
|
|
211
|
+
private initialize;
|
|
212
|
+
logInfo(message: string, data?: Record<string, any>): void;
|
|
213
|
+
logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
declare function generateTranslatePrompt(text: string): string;
|
|
217
|
+
declare function getCookies(name: string): string | undefined;
|
|
218
|
+
declare function generateHeaders(config: BaseAPIConfig): HeadersInit;
|
|
219
|
+
declare function isTextContent(buffer: ArrayBuffer): boolean;
|
|
220
|
+
declare function getQueryParam(param: string): string | null;
|
|
221
|
+
declare function defineAssistantId(defaultId: string): string;
|
|
222
|
+
declare function formatTimeWithUnit(timeMs: number): string;
|
|
223
|
+
declare function serializeAxiosError(error: unknown): {
|
|
224
|
+
message: string;
|
|
225
|
+
name: string;
|
|
226
|
+
stack: string | undefined;
|
|
227
|
+
code: string | number | undefined;
|
|
228
|
+
status: string | number | undefined;
|
|
229
|
+
} | {
|
|
230
|
+
message: string;
|
|
231
|
+
name: string;
|
|
232
|
+
stack?: undefined;
|
|
233
|
+
code?: undefined;
|
|
234
|
+
status?: undefined;
|
|
235
|
+
};
|
|
236
|
+
declare function parseConversationsMapCookie(cookieValue: string): ConversationsMap;
|
|
237
|
+
declare function getTopicSessionId(topicId: string): string;
|
|
238
|
+
declare function createMessageId(): string;
|
|
239
|
+
|
|
240
|
+
declare function useAlquimia(sdk: AlquimiaSDK): {
|
|
241
|
+
activeTool: any;
|
|
242
|
+
cleanMessages: () => void;
|
|
243
|
+
createMessageId: typeof createMessageId;
|
|
244
|
+
handleInputChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
245
|
+
handleReplaceInput: (input: string) => void;
|
|
246
|
+
handleSubmit: (event: React.FormEvent<HTMLFormElement>, traceParentId?: string, sessionId?: string, additionalInfo?: string) => Promise<void>;
|
|
247
|
+
handleSaveCharacterization: (translation: Record<string, any>) => Promise<void>;
|
|
248
|
+
handleLoadingCancel: () => void;
|
|
249
|
+
input: string;
|
|
250
|
+
isLoading: boolean;
|
|
251
|
+
isMessageStreaming: boolean;
|
|
252
|
+
streamingMessageId: string | null;
|
|
253
|
+
isAudioRecording: boolean;
|
|
254
|
+
shouldShowCharacterizationButton: boolean;
|
|
255
|
+
lastRequest: string | null;
|
|
256
|
+
messageMetaData: any;
|
|
257
|
+
messages: (Message & {
|
|
258
|
+
error_code?: string;
|
|
259
|
+
error_detail?: string;
|
|
260
|
+
})[];
|
|
261
|
+
populateMessages: (messages: Message[]) => void;
|
|
262
|
+
processMessageChunk: (messageId: string, chunk: string, error_code?: string, error_detail?: string, additionalInfo?: string) => Promise<void>;
|
|
263
|
+
sendMessage: (message: string, callBack: (chunk: AIMessageChunk) => void, traceParentId?: string, sessionId?: string) => Promise<void>;
|
|
264
|
+
sessionId: string | null;
|
|
265
|
+
setActiveTool: react.Dispatch<any>;
|
|
266
|
+
setSessionId: react.Dispatch<react.SetStateAction<string | null>>;
|
|
267
|
+
setLastRequest: react.Dispatch<react.SetStateAction<string | null>>;
|
|
268
|
+
setIsAudioRecording: react.Dispatch<react.SetStateAction<boolean>>;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
interface UseRatingsParams {
|
|
272
|
+
assistantId: string;
|
|
273
|
+
topicId: string;
|
|
274
|
+
sendRating: (ratingData: RatingData) => Promise<any>;
|
|
275
|
+
onError?: (componentName: string, error: Error) => void;
|
|
276
|
+
}
|
|
277
|
+
declare function useRatings({ assistantId, sendRating, topicId }: UseRatingsParams): {
|
|
278
|
+
handleRate: (key: string, value: any | string, onHandleRateSuccess: (success: boolean, err?: string) => void) => Promise<void>;
|
|
279
|
+
ratingStars: number;
|
|
280
|
+
ratingThumbs: "" | "thumbsUp" | "thumbsDown";
|
|
281
|
+
ratingComment: string;
|
|
282
|
+
isLoading: boolean;
|
|
283
|
+
hasReviewed: boolean;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
declare function initConversation(reset?: boolean, topicId?: string): Promise<string>;
|
|
287
|
+
|
|
288
|
+
interface ActionResponse<T = void> {
|
|
289
|
+
success: boolean;
|
|
290
|
+
data?: T;
|
|
291
|
+
contentType?: string;
|
|
292
|
+
error?: {
|
|
293
|
+
message: string;
|
|
294
|
+
code?: string;
|
|
295
|
+
details?: any;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
declare function createResource<TResponse, TPayload>(config: BaseAPIConfig, payload: TPayload): Promise<ActionResponse<TResponse>>;
|
|
299
|
+
declare function readResource<T>(config: BaseAPIConfig, id?: string): Promise<ActionResponse<T>>;
|
|
300
|
+
declare function updateResource<T>(config: BaseAPIConfig, id: string, data: T): Promise<ActionResponse<T>>;
|
|
301
|
+
declare function deleteResource(config: BaseAPIConfig, id: string): Promise<ActionResponse<void>>;
|
|
302
|
+
|
|
303
|
+
interface CharacterizationState {
|
|
304
|
+
sessionId: string | null;
|
|
305
|
+
characterizationData: any;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface SessionProviderProps {
|
|
309
|
+
children: ReactNode;
|
|
310
|
+
}
|
|
311
|
+
interface AlquimiaContextType {
|
|
312
|
+
getSessionData: () => CharacterizationState;
|
|
313
|
+
userSessionState?: CharacterizationState;
|
|
314
|
+
saveUserSession: (id: string, data: any) => Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
declare const useSessionContext: () => AlquimiaContextType | {
|
|
317
|
+
userSessionState: CharacterizationState;
|
|
318
|
+
saveUserSession: null;
|
|
319
|
+
};
|
|
320
|
+
declare const SessionProvider: react__default.FC<SessionProviderProps>;
|
|
321
|
+
|
|
322
|
+
export { AlquimiaRatingsProvider, AlquimiaSDK, AlquimiaWhisperProvider, Button, Card, CharacterizationProvider, Code, ElasticLoggerProvider, ElevenLabsWhisperProvider, GenerativeProvider, LoggerProvider, OpenAIAnalyzeCharProvider, OpenAIStableDiffusionProvider, OpenAIWhisperProvider, RatingsProvider, SessionProvider, StabilityProvider, StableDiffusionProvider, WhisperProvider, createMessageId, createResource, defineAssistantId, deleteResource, formatTimeWithUnit, generateHeaders, generateTranslatePrompt, getCookies, getQueryParam, getTopicSessionId, initConversation, isTextContent, parseConversationsMapCookie, readResource, serializeAxiosError, updateResource, useAlquimia, useRatings, useSessionContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import { Message } from 'ai';
|
|
4
|
+
|
|
5
|
+
interface ButtonProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
appName: string;
|
|
9
|
+
}
|
|
10
|
+
declare const Button: ({ children, className, appName }: ButtonProps) => react.JSX.Element;
|
|
11
|
+
|
|
12
|
+
declare function Card({ className, title, children, href, }: {
|
|
13
|
+
className?: string;
|
|
14
|
+
title: string;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
href: string;
|
|
17
|
+
}): JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function Code({ children, className, }: {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
}): JSX.Element;
|
|
23
|
+
|
|
24
|
+
declare abstract class GenerativeProvider {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: Record<string, any>);
|
|
27
|
+
}
|
|
28
|
+
declare abstract class WhisperProvider {
|
|
29
|
+
protected config: Record<string, any>;
|
|
30
|
+
constructor(config: Record<string, any>);
|
|
31
|
+
abstract textToSpeech(text: string): Promise<Blob>;
|
|
32
|
+
abstract speechToText(audio: string): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
declare abstract class StableDiffusionProvider {
|
|
35
|
+
protected config: Record<string, any>;
|
|
36
|
+
constructor(config: Record<string, any>);
|
|
37
|
+
abstract generateImage(query: string): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
declare abstract class CharacterizationProvider {
|
|
40
|
+
protected config: Record<string, any>;
|
|
41
|
+
constructor(config: Record<string, any>);
|
|
42
|
+
abstract analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
43
|
+
}
|
|
44
|
+
declare abstract class RatingsProvider {
|
|
45
|
+
protected config: Record<string, any>;
|
|
46
|
+
constructor(config: Record<string, any>);
|
|
47
|
+
abstract rate(data: Record<string, any>): Promise<Record<string, any>>;
|
|
48
|
+
}
|
|
49
|
+
declare abstract class LoggerProvider {
|
|
50
|
+
protected config: Record<string, any>;
|
|
51
|
+
constructor(config: Record<string, any>);
|
|
52
|
+
abstract logInfo(message: string, data?: Record<string, any>): void;
|
|
53
|
+
abstract logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AlquimiaSDKConfig {
|
|
57
|
+
apiKey: string;
|
|
58
|
+
chatUrl: string;
|
|
59
|
+
streamUrl: string;
|
|
60
|
+
assistantId: string;
|
|
61
|
+
}
|
|
62
|
+
declare class AlquimiaSDK {
|
|
63
|
+
private config;
|
|
64
|
+
private axiosInstance;
|
|
65
|
+
private conversationId;
|
|
66
|
+
private sessionId;
|
|
67
|
+
private streamId;
|
|
68
|
+
private tools;
|
|
69
|
+
private extraData;
|
|
70
|
+
private forceProfile;
|
|
71
|
+
private whisperProvider?;
|
|
72
|
+
private stableDiffusionProvider?;
|
|
73
|
+
private analyzeCharacterizationProvider?;
|
|
74
|
+
private ratingsProvider?;
|
|
75
|
+
private loggerProvider?;
|
|
76
|
+
private enforceCharacterization?;
|
|
77
|
+
constructor(config: AlquimiaSDKConfig, enforceCharacterization?: boolean);
|
|
78
|
+
static configure(apiKey: string, inferUrl: string, streamUrl: string, assistantId: string): AlquimiaSDKConfig;
|
|
79
|
+
widthConversationId(conversationId: string): AlquimiaSDK;
|
|
80
|
+
withWhisperProvider(provider: WhisperProvider): AlquimiaSDK;
|
|
81
|
+
withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK;
|
|
82
|
+
withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK;
|
|
83
|
+
withRatingsProvider(provider: RatingsProvider): AlquimiaSDK;
|
|
84
|
+
withLoggerProvider(provider: LoggerProvider): AlquimiaSDK;
|
|
85
|
+
getEnforceCharacterization(): boolean;
|
|
86
|
+
withTools(tools: any[]): AlquimiaSDK;
|
|
87
|
+
withExtraData(extraData: any): AlquimiaSDK;
|
|
88
|
+
withForceProfile(forceProfile: any): AlquimiaSDK;
|
|
89
|
+
textToSpeech(text: string): Promise<Blob>;
|
|
90
|
+
speechToText(audio: string): Promise<string>;
|
|
91
|
+
sendMessage(query: string, traceParent?: string): Promise<this>;
|
|
92
|
+
generateImage(query: string): Promise<string>;
|
|
93
|
+
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
94
|
+
rate(data: any): Promise<Record<string, any>>;
|
|
95
|
+
logInfo(message: string, data: any): Promise<void>;
|
|
96
|
+
logError(message: string, error: Error, data: any): Promise<void>;
|
|
97
|
+
getUrlStream(): string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface AIMessageChunk {
|
|
101
|
+
type: string;
|
|
102
|
+
data?: AIMessageChunkData;
|
|
103
|
+
error_code?: string;
|
|
104
|
+
error_detail?: string;
|
|
105
|
+
}
|
|
106
|
+
interface AIMessageChunkData {
|
|
107
|
+
content: string;
|
|
108
|
+
additional_kwargs?: Record<string, unknown>;
|
|
109
|
+
response_metadata?: Record<string, unknown>;
|
|
110
|
+
type: string;
|
|
111
|
+
name?: string | null;
|
|
112
|
+
id?: string | null;
|
|
113
|
+
example?: boolean;
|
|
114
|
+
tool_calls?: ToolCall[];
|
|
115
|
+
invalid_tool_calls?: InvalidToolCall[];
|
|
116
|
+
usage_metadata?: any;
|
|
117
|
+
tool_call_chunks?: unknown[];
|
|
118
|
+
error_code?: string;
|
|
119
|
+
error_detail?: string;
|
|
120
|
+
}
|
|
121
|
+
type ToolCall = {
|
|
122
|
+
name: string;
|
|
123
|
+
args: Record<string, any>;
|
|
124
|
+
id?: string | null;
|
|
125
|
+
};
|
|
126
|
+
type InvalidToolCall = {
|
|
127
|
+
name: string | null;
|
|
128
|
+
args: string | null;
|
|
129
|
+
id: string | null;
|
|
130
|
+
error: string | null;
|
|
131
|
+
};
|
|
132
|
+
interface BaseAPIConfig {
|
|
133
|
+
baseUrl: string;
|
|
134
|
+
route: string;
|
|
135
|
+
token?: string;
|
|
136
|
+
headers?: Record<string, string>;
|
|
137
|
+
}
|
|
138
|
+
interface RatingData {
|
|
139
|
+
assistantId: string;
|
|
140
|
+
sessionId: string;
|
|
141
|
+
topicId: number;
|
|
142
|
+
score?: number;
|
|
143
|
+
description?: string;
|
|
144
|
+
}
|
|
145
|
+
interface ConversationsMap {
|
|
146
|
+
[topicId: string]: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare class AlquimiaWhisperProvider extends WhisperProvider {
|
|
150
|
+
constructor(config: {
|
|
151
|
+
baseURL: string;
|
|
152
|
+
ttsRoute: string;
|
|
153
|
+
sttRoute: string;
|
|
154
|
+
});
|
|
155
|
+
textToSpeech(text: string): Promise<any>;
|
|
156
|
+
speechToText(audio: string): Promise<string>;
|
|
157
|
+
}
|
|
158
|
+
declare class AlquimiaRatingsProvider extends RatingsProvider {
|
|
159
|
+
constructor(config: {
|
|
160
|
+
baseUrl: string;
|
|
161
|
+
route: string;
|
|
162
|
+
token: string;
|
|
163
|
+
headers?: Record<string, string>;
|
|
164
|
+
});
|
|
165
|
+
rate(data: RatingData): Promise<Record<string, any>>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
declare class OpenAIWhisperProvider extends WhisperProvider {
|
|
169
|
+
textToSpeech(text: string): Promise<Blob>;
|
|
170
|
+
speechToText(audio: string): Promise<string>;
|
|
171
|
+
}
|
|
172
|
+
declare class OpenAIAnalyzeCharProvider extends CharacterizationProvider {
|
|
173
|
+
private client;
|
|
174
|
+
constructor(config: Record<string, any>);
|
|
175
|
+
analyzeCharacterization(text: string): Promise<Record<string, any>>;
|
|
176
|
+
}
|
|
177
|
+
declare class OpenAIStableDiffusionProvider extends StableDiffusionProvider {
|
|
178
|
+
private client;
|
|
179
|
+
constructor(config: Record<string, any>);
|
|
180
|
+
generateImage(query: string): Promise<string>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class StabilityProvider extends StableDiffusionProvider {
|
|
184
|
+
constructor(config: Record<string, any>);
|
|
185
|
+
generateImage(query: string): Promise<string>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class ElevenLabsWhisperProvider extends WhisperProvider {
|
|
189
|
+
private client;
|
|
190
|
+
constructor(config: {
|
|
191
|
+
apiKey: string;
|
|
192
|
+
voiceId: string;
|
|
193
|
+
baseURL: string;
|
|
194
|
+
});
|
|
195
|
+
speechToText(audio: string): Promise<string>;
|
|
196
|
+
textToSpeech(text: string): Promise<any>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface ElasticLoggerConfig {
|
|
200
|
+
endpoint: string;
|
|
201
|
+
username: string;
|
|
202
|
+
password: string;
|
|
203
|
+
index?: string;
|
|
204
|
+
esVersion?: number;
|
|
205
|
+
flushBytes?: number;
|
|
206
|
+
}
|
|
207
|
+
declare class ElasticLoggerProvider extends LoggerProvider {
|
|
208
|
+
private logger;
|
|
209
|
+
private constructor();
|
|
210
|
+
static create(config: ElasticLoggerConfig): Promise<ElasticLoggerProvider>;
|
|
211
|
+
private initialize;
|
|
212
|
+
logInfo(message: string, data?: Record<string, any>): void;
|
|
213
|
+
logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
declare function generateTranslatePrompt(text: string): string;
|
|
217
|
+
declare function getCookies(name: string): string | undefined;
|
|
218
|
+
declare function generateHeaders(config: BaseAPIConfig): HeadersInit;
|
|
219
|
+
declare function isTextContent(buffer: ArrayBuffer): boolean;
|
|
220
|
+
declare function getQueryParam(param: string): string | null;
|
|
221
|
+
declare function defineAssistantId(defaultId: string): string;
|
|
222
|
+
declare function formatTimeWithUnit(timeMs: number): string;
|
|
223
|
+
declare function serializeAxiosError(error: unknown): {
|
|
224
|
+
message: string;
|
|
225
|
+
name: string;
|
|
226
|
+
stack: string | undefined;
|
|
227
|
+
code: string | number | undefined;
|
|
228
|
+
status: string | number | undefined;
|
|
229
|
+
} | {
|
|
230
|
+
message: string;
|
|
231
|
+
name: string;
|
|
232
|
+
stack?: undefined;
|
|
233
|
+
code?: undefined;
|
|
234
|
+
status?: undefined;
|
|
235
|
+
};
|
|
236
|
+
declare function parseConversationsMapCookie(cookieValue: string): ConversationsMap;
|
|
237
|
+
declare function getTopicSessionId(topicId: string): string;
|
|
238
|
+
declare function createMessageId(): string;
|
|
239
|
+
|
|
240
|
+
declare function useAlquimia(sdk: AlquimiaSDK): {
|
|
241
|
+
activeTool: any;
|
|
242
|
+
cleanMessages: () => void;
|
|
243
|
+
createMessageId: typeof createMessageId;
|
|
244
|
+
handleInputChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
245
|
+
handleReplaceInput: (input: string) => void;
|
|
246
|
+
handleSubmit: (event: React.FormEvent<HTMLFormElement>, traceParentId?: string, sessionId?: string, additionalInfo?: string) => Promise<void>;
|
|
247
|
+
handleSaveCharacterization: (translation: Record<string, any>) => Promise<void>;
|
|
248
|
+
handleLoadingCancel: () => void;
|
|
249
|
+
input: string;
|
|
250
|
+
isLoading: boolean;
|
|
251
|
+
isMessageStreaming: boolean;
|
|
252
|
+
streamingMessageId: string | null;
|
|
253
|
+
isAudioRecording: boolean;
|
|
254
|
+
shouldShowCharacterizationButton: boolean;
|
|
255
|
+
lastRequest: string | null;
|
|
256
|
+
messageMetaData: any;
|
|
257
|
+
messages: (Message & {
|
|
258
|
+
error_code?: string;
|
|
259
|
+
error_detail?: string;
|
|
260
|
+
})[];
|
|
261
|
+
populateMessages: (messages: Message[]) => void;
|
|
262
|
+
processMessageChunk: (messageId: string, chunk: string, error_code?: string, error_detail?: string, additionalInfo?: string) => Promise<void>;
|
|
263
|
+
sendMessage: (message: string, callBack: (chunk: AIMessageChunk) => void, traceParentId?: string, sessionId?: string) => Promise<void>;
|
|
264
|
+
sessionId: string | null;
|
|
265
|
+
setActiveTool: react.Dispatch<any>;
|
|
266
|
+
setSessionId: react.Dispatch<react.SetStateAction<string | null>>;
|
|
267
|
+
setLastRequest: react.Dispatch<react.SetStateAction<string | null>>;
|
|
268
|
+
setIsAudioRecording: react.Dispatch<react.SetStateAction<boolean>>;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
interface UseRatingsParams {
|
|
272
|
+
assistantId: string;
|
|
273
|
+
topicId: string;
|
|
274
|
+
sendRating: (ratingData: RatingData) => Promise<any>;
|
|
275
|
+
onError?: (componentName: string, error: Error) => void;
|
|
276
|
+
}
|
|
277
|
+
declare function useRatings({ assistantId, sendRating, topicId }: UseRatingsParams): {
|
|
278
|
+
handleRate: (key: string, value: any | string, onHandleRateSuccess: (success: boolean, err?: string) => void) => Promise<void>;
|
|
279
|
+
ratingStars: number;
|
|
280
|
+
ratingThumbs: "" | "thumbsUp" | "thumbsDown";
|
|
281
|
+
ratingComment: string;
|
|
282
|
+
isLoading: boolean;
|
|
283
|
+
hasReviewed: boolean;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
declare function initConversation(reset?: boolean, topicId?: string): Promise<string>;
|
|
287
|
+
|
|
288
|
+
interface ActionResponse<T = void> {
|
|
289
|
+
success: boolean;
|
|
290
|
+
data?: T;
|
|
291
|
+
contentType?: string;
|
|
292
|
+
error?: {
|
|
293
|
+
message: string;
|
|
294
|
+
code?: string;
|
|
295
|
+
details?: any;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
declare function createResource<TResponse, TPayload>(config: BaseAPIConfig, payload: TPayload): Promise<ActionResponse<TResponse>>;
|
|
299
|
+
declare function readResource<T>(config: BaseAPIConfig, id?: string): Promise<ActionResponse<T>>;
|
|
300
|
+
declare function updateResource<T>(config: BaseAPIConfig, id: string, data: T): Promise<ActionResponse<T>>;
|
|
301
|
+
declare function deleteResource(config: BaseAPIConfig, id: string): Promise<ActionResponse<void>>;
|
|
302
|
+
|
|
303
|
+
interface CharacterizationState {
|
|
304
|
+
sessionId: string | null;
|
|
305
|
+
characterizationData: any;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface SessionProviderProps {
|
|
309
|
+
children: ReactNode;
|
|
310
|
+
}
|
|
311
|
+
interface AlquimiaContextType {
|
|
312
|
+
getSessionData: () => CharacterizationState;
|
|
313
|
+
userSessionState?: CharacterizationState;
|
|
314
|
+
saveUserSession: (id: string, data: any) => Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
declare const useSessionContext: () => AlquimiaContextType | {
|
|
317
|
+
userSessionState: CharacterizationState;
|
|
318
|
+
saveUserSession: null;
|
|
319
|
+
};
|
|
320
|
+
declare const SessionProvider: react__default.FC<SessionProviderProps>;
|
|
321
|
+
|
|
322
|
+
export { AlquimiaRatingsProvider, AlquimiaSDK, AlquimiaWhisperProvider, Button, Card, CharacterizationProvider, Code, ElasticLoggerProvider, ElevenLabsWhisperProvider, GenerativeProvider, LoggerProvider, OpenAIAnalyzeCharProvider, OpenAIStableDiffusionProvider, OpenAIWhisperProvider, RatingsProvider, SessionProvider, StabilityProvider, StableDiffusionProvider, WhisperProvider, createMessageId, createResource, defineAssistantId, deleteResource, formatTimeWithUnit, generateHeaders, generateTranslatePrompt, getCookies, getQueryParam, getTopicSessionId, initConversation, isTextContent, parseConversationsMapCookie, readResource, serializeAxiosError, updateResource, useAlquimia, useRatings, useSessionContext };
|