@@ -32,13 +32,13 @@ How to use `llm-interface` in your project.
32
32
First, require the LLMInterface from the ` llm-interface ` package:
33
33
34
34
``` javascript
35
- const LLMInterface = require (" llm-interface" );
35
+ const LLMInterface = require (' llm-interface' );
36
36
```
37
37
38
38
or import it:
39
39
40
40
``` javascript
41
- import LLMInterface from " llm-interface" ;
41
+ import LLMInterface from ' llm-interface' ;
42
42
```
43
43
44
44
## Basic Usage Examples
@@ -55,10 +55,10 @@ The OpenAI interface allows you to send messages to the OpenAI API.
55
55
const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
56
56
57
57
const message = {
58
- model: " gpt-3.5-turbo" ,
58
+ model: ' gpt-3.5-turbo' ,
59
59
messages: [
60
- { role: " system" , content: " You are a helpful assistant." },
61
- { role: " user" , content: " Explain the importance of low latency LLMs." },
60
+ { role: ' system' , content: ' You are a helpful assistant.' },
61
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
62
62
],
63
63
};
64
64
@@ -169,10 +169,10 @@ The Gemini interface allows you to send messages to the Google Gemini API.
169
169
const gemini = new LLMInterface.gemini (process .env .GEMINI_API_KEY );
170
170
171
171
const message = {
172
- model: " gemini-1.5-flash" ,
172
+ model: ' gemini-1.5-flash' ,
173
173
messages: [
174
- { role: " system" , content: " You are a helpful assistant." },
175
- { role: " user" , content: " Explain the importance of low latency LLMs." },
174
+ { role: ' system' , content: ' You are a helpful assistant.' },
175
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
176
176
],
177
177
};
178
178
@@ -196,10 +196,10 @@ The Goose AI interface allows you to send messages to the Goose AI API.
196
196
const goose = new LLMInterface.goose (process .env .GROQ_API_KEY );
197
197
198
198
const message = {
199
- model: " gpt-neo-20b" ,
199
+ model: ' gpt-neo-20b' ,
200
200
messages: [
201
- { role: " system" , content: " You are a helpful assistant." },
202
- { role: " user" , content: " Explain the importance of low latency LLMs." },
201
+ { role: ' system' , content: ' You are a helpful assistant.' },
202
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
203
203
],
204
204
};
205
205
@@ -223,10 +223,10 @@ The Groq interface allows you to send messages to the Groq API.
223
223
const groq = new LLMInterface.groq (process .env .GROQ_API_KEY );
224
224
225
225
const message = {
226
- model: " llama3-8b-8192" ,
226
+ model: ' llama3-8b-8192' ,
227
227
messages: [
228
- { role: " system" , content: " You are a helpful assistant." },
229
- { role: " user" , content: " Explain the importance of low latency LLMs." },
228
+ { role: ' system' , content: ' You are a helpful assistant.' },
229
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
230
230
],
231
231
};
232
232
@@ -250,15 +250,15 @@ The HuggingFace interface allows you to send messages to the HuggingFace API.
250
250
const huggingface = new LLMInterface.huggingface (process .env .ANTHROPIC_API_KEY );
251
251
252
252
const message = {
253
- model: " claude-3-opus-20240229" ,
253
+ model: ' claude-3-opus-20240229' ,
254
254
messages: [
255
255
{
256
- role: " user" ,
256
+ role: ' user' ,
257
257
content:
258
- " You are a helpful assistant. Say OK if you understand and stop." ,
258
+ ' You are a helpful assistant. Say OK if you understand and stop.' ,
259
259
},
260
- { role: " system" , content: " OK " },
261
- { role: " user" , content: " Explain the importance of low latency LLMs." },
260
+ { role: ' system' , content: ' OK ' },
261
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
262
262
],
263
263
};
264
264
@@ -282,10 +282,10 @@ The Mistral AI interface allows you to send messages to the Mistral AI API.
282
282
const mistral = new LLMInterface.mistral (process .env .GROQ_API_KEY );
283
283
284
284
const message = {
285
- model: " llama3-8b-8192" ,
285
+ model: ' llama3-8b-8192' ,
286
286
messages: [
287
- { role: " system" , content: " You are a helpful assistant." },
288
- { role: " user" , content: " Explain the importance of low latency LLMs." },
287
+ { role: ' system' , content: ' You are a helpful assistant.' },
288
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
289
289
],
290
290
};
291
291
@@ -309,15 +309,15 @@ The Perplexity interface allows you to send messages to the Perplexity API.
309
309
const perplexity = new LLMInterface.perplexity (process .env .ANTHROPIC_API_KEY );
310
310
311
311
const message = {
312
- model: " claude-3-opus-20240229" ,
312
+ model: ' claude-3-opus-20240229' ,
313
313
messages: [
314
314
{
315
- role: " user" ,
315
+ role: ' user' ,
316
316
content:
317
- " You are a helpful assistant. Say OK if you understand and stop." ,
317
+ ' You are a helpful assistant. Say OK if you understand and stop.' ,
318
318
},
319
- { role: " system" , content: " OK " },
320
- { role: " user" , content: " Explain the importance of low latency LLMs." },
319
+ { role: ' system' , content: ' OK ' },
320
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
321
321
],
322
322
};
323
323
@@ -341,22 +341,22 @@ The Reka AI interface allows you to send messages to the Reka AI REST API.
341
341
const reka = new LLMInterface.reka (process .env .REKA_API_KEY );
342
342
343
343
const message = {
344
- model: " reka-core" ,
344
+ model: ' reka-core' ,
345
345
messages: [
346
346
{
347
- role: " user" ,
347
+ role: ' user' ,
348
348
content:
349
- " You are a helpful assistant. Say OK if you understand and stop." ,
349
+ ' You are a helpful assistant. Say OK if you understand and stop.' ,
350
350
},
351
- { role: " system" , content: " OK " },
352
- { role: " user" , content: " Explain the importance of low latency LLMs." },
351
+ { role: ' system' , content: ' OK ' },
352
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
353
353
],
354
354
};
355
355
356
356
reka
357
357
.sendMessage (message, {})
358
- .then ((response ) => console .log (" Response:" , response))
359
- .catch ((error ) => console .error (" Error:" , error));
358
+ .then ((response ) => console .log (' Response:' , response))
359
+ .catch ((error ) => console .error (' Error:' , error));
360
360
```
361
361
362
362
### LLaMA.cpp Interface
@@ -369,9 +369,9 @@ The LLaMA.cpp interface allows you to send messages to the LLaMA.cpp API; this i
369
369
const llamacpp = new LLMInterface.llamacpp (process .env .LLAMACPP_URL );
370
370
371
371
const message = {
372
- model: " some-llamacpp-model" ,
372
+ model: ' some-llamacpp-model' ,
373
373
messages: [
374
- { role: " user" , content: " Explain the importance of low latency LLMs." },
374
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
375
375
],
376
376
};
377
377
@@ -398,7 +398,7 @@ This simplified example uses a string based prompt with the default OpenAI model
398
398
``` javascript
399
399
const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
400
400
401
- const message = " Explain the importance of low latency LLMs." ;
401
+ const message = ' Explain the importance of low latency LLMs.' ;
402
402
403
403
openai
404
404
.sendMessage (message)
@@ -424,22 +424,22 @@ Some interfaces allows you request the response back in JSON, currently **OpenAI
424
424
const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
425
425
426
426
const message = {
427
- model: " gpt-3.5-turbo" ,
427
+ model: ' gpt-3.5-turbo' ,
428
428
messages: [
429
429
{
430
- role: " system" ,
431
- content: " You are a helpful assistant." ,
430
+ role: ' system' ,
431
+ content: ' You are a helpful assistant.' ,
432
432
},
433
433
{
434
- role: " user" ,
434
+ role: ' user' ,
435
435
content:
436
- " Explain the importance of low latency LLMs. Return the results as a JSON object. Follow this format: [{reason, reasonDescription}]." ,
436
+ ' Explain the importance of low latency LLMs. Return the results as a JSON object. Follow this format: [{reason, reasonDescription}].' ,
437
437
},
438
438
],
439
439
};
440
440
441
441
openai
442
- .sendMessage (message, { max_tokens: 150 , response_format: " json_object" })
442
+ .sendMessage (message, { max_tokens: 150 , response_format: ' json_object' })
443
443
.then ((response ) => {
444
444
console .log (response);
445
445
})
@@ -458,10 +458,10 @@ To reduce operational costs and improve performance you can optionally specify a
458
458
const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
459
459
460
460
const message = {
461
- model: " gpt-3.5-turbo" ,
461
+ model: ' gpt-3.5-turbo' ,
462
462
messages: [
463
- { role: " system" , content: " You are a helpful assistant." },
464
- { role: " user" , content: " Explain the importance of low latency LLMs." },
463
+ { role: ' system' , content: ' You are a helpful assistant.' },
464
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
465
465
],
466
466
};
467
467
@@ -485,10 +485,10 @@ You can gracefully retry your requests. In this example we use OpenAI and up to
485
485
const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
486
486
487
487
const message = {
488
- model: " gpt-3.5-turbo" ,
488
+ model: ' gpt-3.5-turbo' ,
489
489
messages: [
490
- { role: " system" , content: " You are a helpful assistant." },
491
- { role: " user" , content: " Explain the importance of low latency LLMs." },
490
+ { role: ' system' , content: ' You are a helpful assistant.' },
491
+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
492
492
],
493
493
};
494
494
0 commit comments