@@ -32,13 +32,13 @@ How to use `llm-interface` in your project.
3232First, require the LLMInterface from the ` llm-interface ` package:
3333
3434``` javascript
35- const LLMInterface = require (" llm-interface" );
35+ const LLMInterface = require (' llm-interface' );
3636```
3737
3838or import it:
3939
4040``` javascript
41- import LLMInterface from " llm-interface" ;
41+ import LLMInterface from ' llm-interface' ;
4242```
4343
4444## Basic Usage Examples
@@ -55,10 +55,10 @@ The OpenAI interface allows you to send messages to the OpenAI API.
5555const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
5656
5757const message = {
58- model: " gpt-3.5-turbo" ,
58+ model: ' gpt-3.5-turbo' ,
5959 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.' },
6262 ],
6363};
6464
@@ -169,10 +169,10 @@ The Gemini interface allows you to send messages to the Google Gemini API.
169169const gemini = new LLMInterface.gemini (process .env .GEMINI_API_KEY );
170170
171171const message = {
172- model: " gemini-1.5-flash" ,
172+ model: ' gemini-1.5-flash' ,
173173 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.' },
176176 ],
177177};
178178
@@ -196,10 +196,10 @@ The Goose AI interface allows you to send messages to the Goose AI API.
196196const goose = new LLMInterface.goose (process .env .GROQ_API_KEY );
197197
198198const message = {
199- model: " gpt-neo-20b" ,
199+ model: ' gpt-neo-20b' ,
200200 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.' },
203203 ],
204204};
205205
@@ -223,10 +223,10 @@ The Groq interface allows you to send messages to the Groq API.
223223const groq = new LLMInterface.groq (process .env .GROQ_API_KEY );
224224
225225const message = {
226- model: " llama3-8b-8192" ,
226+ model: ' llama3-8b-8192' ,
227227 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.' },
230230 ],
231231};
232232
@@ -250,15 +250,15 @@ The HuggingFace interface allows you to send messages to the HuggingFace API.
250250const huggingface = new LLMInterface.huggingface (process .env .ANTHROPIC_API_KEY );
251251
252252const message = {
253- model: " claude-3-opus-20240229" ,
253+ model: ' claude-3-opus-20240229' ,
254254 messages: [
255255 {
256- role: " user" ,
256+ role: ' user' ,
257257 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.' ,
259259 },
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.' },
262262 ],
263263};
264264
@@ -282,10 +282,10 @@ The Mistral AI interface allows you to send messages to the Mistral AI API.
282282const mistral = new LLMInterface.mistral (process .env .GROQ_API_KEY );
283283
284284const message = {
285- model: " llama3-8b-8192" ,
285+ model: ' llama3-8b-8192' ,
286286 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.' },
289289 ],
290290};
291291
@@ -309,15 +309,15 @@ The Perplexity interface allows you to send messages to the Perplexity API.
309309const perplexity = new LLMInterface.perplexity (process .env .ANTHROPIC_API_KEY );
310310
311311const message = {
312- model: " claude-3-opus-20240229" ,
312+ model: ' claude-3-opus-20240229' ,
313313 messages: [
314314 {
315- role: " user" ,
315+ role: ' user' ,
316316 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.' ,
318318 },
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.' },
321321 ],
322322};
323323
@@ -341,22 +341,22 @@ The Reka AI interface allows you to send messages to the Reka AI REST API.
341341const reka = new LLMInterface.reka (process .env .REKA_API_KEY );
342342
343343const message = {
344- model: " reka-core" ,
344+ model: ' reka-core' ,
345345 messages: [
346346 {
347- role: " user" ,
347+ role: ' user' ,
348348 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.' ,
350350 },
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.' },
353353 ],
354354};
355355
356356reka
357357 .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));
360360```
361361
362362### LLaMA.cpp Interface
@@ -369,9 +369,9 @@ The LLaMA.cpp interface allows you to send messages to the LLaMA.cpp API; this i
369369const llamacpp = new LLMInterface.llamacpp (process .env .LLAMACPP_URL );
370370
371371const message = {
372- model: " some-llamacpp-model" ,
372+ model: ' some-llamacpp-model' ,
373373 messages: [
374- { role: " user" , content: " Explain the importance of low latency LLMs." },
374+ { role: ' user' , content: ' Explain the importance of low latency LLMs.' },
375375 ],
376376};
377377
@@ -398,7 +398,7 @@ This simplified example uses a string based prompt with the default OpenAI model
398398``` javascript
399399const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
400400
401- const message = " Explain the importance of low latency LLMs." ;
401+ const message = ' Explain the importance of low latency LLMs.' ;
402402
403403openai
404404 .sendMessage (message)
@@ -424,22 +424,22 @@ Some interfaces allows you request the response back in JSON, currently **OpenAI
424424const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
425425
426426const message = {
427- model: " gpt-3.5-turbo" ,
427+ model: ' gpt-3.5-turbo' ,
428428 messages: [
429429 {
430- role: " system" ,
431- content: " You are a helpful assistant." ,
430+ role: ' system' ,
431+ content: ' You are a helpful assistant.' ,
432432 },
433433 {
434- role: " user" ,
434+ role: ' user' ,
435435 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}].' ,
437437 },
438438 ],
439439};
440440
441441openai
442- .sendMessage (message, { max_tokens: 150 , response_format: " json_object" })
442+ .sendMessage (message, { max_tokens: 150 , response_format: ' json_object' })
443443 .then ((response ) => {
444444 console .log (response);
445445 })
@@ -458,10 +458,10 @@ To reduce operational costs and improve performance you can optionally specify a
458458const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
459459
460460const message = {
461- model: " gpt-3.5-turbo" ,
461+ model: ' gpt-3.5-turbo' ,
462462 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.' },
465465 ],
466466};
467467
@@ -485,10 +485,10 @@ You can gracefully retry your requests. In this example we use OpenAI and up to
485485const openai = new LLMInterface.openai (process .env .OPENAI_API_KEY );
486486
487487const message = {
488- model: " gpt-3.5-turbo" ,
488+ model: ' gpt-3.5-turbo' ,
489489 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.' },
492492 ],
493493};
494494
0 commit comments