-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from samestrin/2.0.9
2.0.9
- Loading branch information
Showing
85 changed files
with
3,833 additions
and
663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,5 @@ dist | |
/src/cache | ||
.prettier* | ||
|
||
.DS_STORE | ||
cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @file examples/json-output.js | ||
* @description Example showing JSON output. To do this, I will specify my JSON output requirements through my prompt. | ||
*/ | ||
const { LLMInterface } = require('llm-interface'); | ||
const { simplePrompt, options } = require('../src/utils/defaults.js'); | ||
|
||
require('dotenv').config({ path: '../.env' }); | ||
|
||
// Setup your key and interface | ||
const interface = 'huggingface'; | ||
const apiKey = process.env.HUGGINGFACE_API_KEY; | ||
|
||
/** | ||
* Main exampleUsage() function. | ||
*/ | ||
async function exampleUsage() { | ||
let prompt = `${simplePrompt} Return 5 results.\n\nProvide the response as a JSON object.\n\nFollow this output format, only responding with the JSON object and nothing else:\n\n{title, reason}`; | ||
|
||
console.log('JSON Output (Prompt Based):'); | ||
console.log(); | ||
console.log('Prompt:'); | ||
console.log(`> ${prompt.replaceAll('\n\n', '\n>\n> ')}`); | ||
console.log(); | ||
|
||
LLMInterface.setApiKey(interface, apiKey); | ||
|
||
try { | ||
const response = await LLMInterface.sendMessage(interface, prompt, { | ||
max_tokens: 1024, | ||
}); | ||
|
||
console.log('Repaired JSON Result:'); | ||
console.log(response.results); | ||
console.log(); | ||
} catch (error) { | ||
console.error('Error processing LLMInterface.sendMessage:', error); | ||
} | ||
} | ||
|
||
exampleUsage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file examples/native-json-output.js | ||
* @description Example showing JSON repair. To do this, I will specify my JSON output requirements through my prompt, and I will request a | ||
* larger result set then can be returned based on token size using a prompt, this will result in a response containing an invalid JSON object. I | ||
* will then repair the response using the attemptJsonRepair interfaceOption. | ||
*/ | ||
const { LLMInterface } = require('llm-interface'); | ||
const { simplePrompt, options } = require('../src/utils/defaults.js'); | ||
|
||
require('dotenv').config({ path: '../.env' }); | ||
|
||
// Setup your key and interface | ||
const interface = 'groq'; | ||
const apiKey = process.env.GROQ_API_KEY; | ||
|
||
/** | ||
* Main exampleUsage() function. | ||
*/ | ||
async function exampleUsage() { | ||
let prompt = `${simplePrompt} Return 5 results.\n\nProvide the response as a JSON object.\n\nFollow this output format, only responding with the JSON object and nothing else:\n\n{title, reason}`; | ||
|
||
console.log('JSON Repair:'); | ||
console.log(); | ||
console.log('Prompt:'); | ||
console.log(`> ${prompt.replaceAll('\n\n', '\n>\n> ')}`); | ||
console.log(); | ||
|
||
LLMInterface.setApiKey(interface, apiKey); | ||
|
||
try { | ||
const response = await LLMInterface.sendMessage( | ||
interface, | ||
prompt, | ||
{ | ||
max_tokens: 100, | ||
}, | ||
{ attemptJsonRepair: true }, | ||
); | ||
|
||
console.log('Repaired JSON Result:'); | ||
console.log(response.results); | ||
console.log(); | ||
} catch (error) { | ||
console.error('Error processing LLMInterface.sendMessage:', error); | ||
} | ||
} | ||
|
||
exampleUsage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @file examples/native-json-output.js | ||
* @description Example showing native JSON output. I will specify my JSON requirements in my prompt, and also specify native JSON mode. This will have | ||
* the added benefit of server side JSON validation, however this can return a null response when the result set is too large for the response token. | ||
*/ | ||
const { LLMInterface } = require('llm-interface'); | ||
const { simplePrompt, options } = require('../src/utils/defaults.js'); | ||
|
||
require('dotenv').config({ path: '../.env' }); | ||
|
||
// Setup your key and interface | ||
const interface = 'gemini'; | ||
const apiKey = process.env.GEMINI_API_KEY; | ||
|
||
/** | ||
* Main exampleUsage() function. | ||
*/ | ||
async function exampleUsage() { | ||
let prompt = `${simplePrompt} Return 5 results.\n\nProvide the response as a valid JSON object; validate the object before responding.\n\nJSON Output Format: [{title, reason}]`; | ||
|
||
console.log('Native JSON Output:'); | ||
console.log(); | ||
console.log('Prompt:'); | ||
console.log(`> ${prompt.replaceAll('\n\n', '\n>\n> ')}`); | ||
console.log(); | ||
|
||
LLMInterface.setApiKey(interface, apiKey); | ||
|
||
try { | ||
const response = await LLMInterface.sendMessage(interface, prompt, { | ||
max_tokens: 1024, | ||
response_format: 'json_object', | ||
}); | ||
|
||
console.log('JSON Result:'); | ||
console.log(response.results); | ||
console.log(); | ||
} catch (error) { | ||
console.error('Error processing LLMInterface.sendMessage:', error); | ||
} | ||
} | ||
|
||
exampleUsage(); |
Oops, something went wrong.