@mate-academy/llm-gateway 1.3.1 → 1.3.2
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 +40 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,9 @@ import {
|
|
|
35
35
|
LLMAssistanceService,
|
|
36
36
|
LLMSpeechToTextService,
|
|
37
37
|
LLMTextToSpeechService,
|
|
38
|
+
LLMRoles,
|
|
39
|
+
LLMMessageContentType,
|
|
40
|
+
LLMUploadFileMimeTypes,
|
|
38
41
|
} from '@mate-academy/llm-gateway';
|
|
39
42
|
|
|
40
43
|
// Define provider options
|
|
@@ -145,8 +148,8 @@ class MyUseCase {
|
|
|
145
148
|
// Use completion service
|
|
146
149
|
const completion = await this.llmCompletionService.sendMessage({
|
|
147
150
|
message: {
|
|
148
|
-
role:
|
|
149
|
-
content: { type:
|
|
151
|
+
role: LLMRoles.User,
|
|
152
|
+
content: { type: LLMMessageContentType.TEXT, text: prompt }
|
|
150
153
|
},
|
|
151
154
|
model: this.getPreferredModel(),
|
|
152
155
|
});
|
|
@@ -167,9 +170,12 @@ class MyUseCase {
|
|
|
167
170
|
async generateSpeech(text) {
|
|
168
171
|
// Use text-to-speech service
|
|
169
172
|
const speech = await this.llmTextToSpeechService.createSpeech({
|
|
170
|
-
|
|
173
|
+
text: text,
|
|
171
174
|
model: this.getPreferredModel(),
|
|
172
|
-
|
|
175
|
+
speechOptions: {
|
|
176
|
+
voice: 'alloy', // OpenAI voice option
|
|
177
|
+
response_format: 'mp3',
|
|
178
|
+
},
|
|
173
179
|
});
|
|
174
180
|
|
|
175
181
|
return speech;
|
|
@@ -183,13 +189,6 @@ class MyUseCase {
|
|
|
183
189
|
}
|
|
184
190
|
```
|
|
185
191
|
|
|
186
|
-
this.llmAssistanceService = LLMServiceFactory.getAssistanceService(
|
|
187
|
-
config.llmProvider,
|
|
188
|
-
logger,
|
|
189
|
-
llmProviderOptions,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
192
|
### Usage Examples
|
|
194
193
|
|
|
195
194
|
#### Basic Text Completion
|
|
@@ -197,8 +196,8 @@ class MyUseCase {
|
|
|
197
196
|
```typescript
|
|
198
197
|
const result = await completionService.sendMessage({
|
|
199
198
|
message: {
|
|
200
|
-
role:
|
|
201
|
-
content: { type:
|
|
199
|
+
role: LLMRoles.User,
|
|
200
|
+
content: { type: LLMMessageContentType.TEXT, text: 'Hello, how are you?' }
|
|
202
201
|
},
|
|
203
202
|
model: preferredModel,
|
|
204
203
|
});
|
|
@@ -211,9 +210,9 @@ console.log(result.text); // AI response
|
|
|
211
210
|
```typescript
|
|
212
211
|
// Upload files for context
|
|
213
212
|
const uploadedFile = await assistanceService.uploadFile({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
mimeType:
|
|
213
|
+
name: 'document.txt',
|
|
214
|
+
path: '/path/to/document.txt',
|
|
215
|
+
mimeType: LLMUploadFileMimeTypes.PLAIN_TEXT,
|
|
217
216
|
});
|
|
218
217
|
|
|
219
218
|
// Create file storage
|
|
@@ -239,7 +238,6 @@ const chat = await assistanceService.createChat({
|
|
|
239
238
|
const transcription = await speechToTextService.transcribe({
|
|
240
239
|
pathToAudio: '/path/to/audio.mp3',
|
|
241
240
|
model: preferredModel,
|
|
242
|
-
language: 'en', // optional
|
|
243
241
|
});
|
|
244
242
|
|
|
245
243
|
console.log(transcription.text); // Transcribed text
|
|
@@ -249,14 +247,16 @@ console.log(transcription.text); // Transcribed text
|
|
|
249
247
|
|
|
250
248
|
```typescript
|
|
251
249
|
const speech = await textToSpeechService.createSpeech({
|
|
252
|
-
|
|
250
|
+
text: 'Hello, this will be converted to speech',
|
|
253
251
|
model: preferredModel,
|
|
254
|
-
|
|
255
|
-
|
|
252
|
+
speechOptions: {
|
|
253
|
+
voice: 'alloy', // OpenAI voice option
|
|
254
|
+
response_format: 'mp3',
|
|
255
|
+
},
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
// Save audio buffer to file
|
|
259
|
-
fs.writeFileSync('output.mp3', speech.
|
|
259
|
+
fs.writeFileSync('output.mp3', speech.audio);
|
|
260
260
|
```
|
|
261
261
|
|
|
262
262
|
## API Reference
|
|
@@ -313,9 +313,24 @@ Interface for chat/assistance services with file handling capabilities.
|
|
|
313
313
|
#### Methods
|
|
314
314
|
|
|
315
315
|
- `uploadFile(file)`: Upload a file to the LLM service
|
|
316
|
+
- Parameters: `LLMUploadFile` with `name`, `path`, and `mimeType`
|
|
317
|
+
- Returns: `Promise<LLMUploadFileResult>`
|
|
318
|
+
- `deleteFile(fileId)`: Delete a file from the LLM service
|
|
316
319
|
- `createFileStorage(options)`: Create a file storage for organizing files
|
|
320
|
+
- Parameters: `LLMCreateFileStorageOptions` with `uploadedFiles`, `model`, and optional `instructions`
|
|
321
|
+
- Returns: `Promise<LLMCreateFileStorageResult>`
|
|
322
|
+
- `deleteFileStorage(fileStorageId)`: Delete a file storage
|
|
323
|
+
- `createAssistant(options)`: Create an AI assistant with specific instructions
|
|
324
|
+
- Parameters: `LLMCreateAssistantOptions` with `model`, optional `instructions` and `storageIds`
|
|
325
|
+
- Returns: `Promise<LLMCreateAssistantResult>`
|
|
326
|
+
- `deleteAssistant(assistantId)`: Delete an assistant
|
|
317
327
|
- `createChat(options)`: Create a new chat/conversation
|
|
328
|
+
- Parameters: `LLMCreateChatOptions` with `model`, optional `instructions`, `history`, `files`, and `storageId`
|
|
329
|
+
- Returns: `Promise<LLMCreateChatResult>`
|
|
330
|
+
- `deleteChat(chatId)`: Delete a chat
|
|
318
331
|
- `assistInChat(options)`: Send a message in an existing chat and get an assistant response
|
|
332
|
+
- Parameters: `LLMAssistanceOptions` with `model`, `message`, `chatId`, and `assistantId`
|
|
333
|
+
- Returns: `Promise<LLMAssistanceResult>`
|
|
319
334
|
|
|
320
335
|
### LLMSpeechToTextService
|
|
321
336
|
|
|
@@ -341,7 +356,8 @@ Supports all service types: completion, assistance, speech-to-text, and text-to-
|
|
|
341
356
|
|
|
342
357
|
**Available Models:**
|
|
343
358
|
- GPT-4 models for completion and assistance
|
|
344
|
-
-
|
|
359
|
+
- Whisper models for speech-to-text transcription
|
|
360
|
+
- TTS models for text-to-speech generation
|
|
345
361
|
|
|
346
362
|
### Google Generative AI
|
|
347
363
|
|
|
@@ -823,8 +839,8 @@ export class YourProviderTextToSpeechService extends LLMTextToSpeechService<LLMP
|
|
|
823
839
|
try {
|
|
824
840
|
// Implement provider-specific speech creation logic
|
|
825
841
|
return {
|
|
826
|
-
|
|
827
|
-
|
|
842
|
+
audio: Buffer.from('audio data'),
|
|
843
|
+
mimeType: 'audio/mp3',
|
|
828
844
|
};
|
|
829
845
|
} catch (error) {
|
|
830
846
|
this.logger.error('Error in YourProvider speech creation', { error });
|