-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinclude-original-response.js
More file actions
62 lines (51 loc) · 2.06 KB
/
Copy pathinclude-original-response.js
File metadata and controls
62 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @file examples/interfaceOptions/include-original-response.js
* @description This example demonstrates the usage of interfaceOptions to control the final output response. By default, LLMInterface does not include the entire response, instead it normalizes the responses back to response.results. If you enable includeOriginalResponse, response.originalResponse will contain the entire LLM provider response in its original format.
*
* To run this example, you first need to install the required module by executing:
*
* npm install dotenv
*/
const { LLMInterface } = require('../../src/index.js');
const { simplePrompt } = require('../../src/utils/defaults.js');
const { prettyHeader, prettyResult } = require('../../src/utils/utils.js');
require('dotenv').config({ path: '../../.env' });
// Setup your key and interface
const interfaceName = 'groq';
const apiKey = process.env.GROQ_API_KEY;
// Example description
const description = `This example demonstrates the usage of interfaceOptions to control the final output response. By default, LLMInterface does not include the entire response, instead it normalizes the responses back to response.results. If you enable includeOriginalResponse, response.originalResponse will contain the entire LLM provider response in its original format.
To run this example, you first need to install the required modules by executing:
npm install dotenv`;
/**
* Main exampleUsage() function.
*/
async function exampleUsage() {
prettyHeader(
'Auto Retry Failed Requests Example',
description,
simplePrompt,
interfaceName,
);
LLMInterface.setApiKey(interfaceName, apiKey);
try {
console.time('Timer');
const response = await LLMInterface.sendMessage(
interfaceName,
simplePrompt,
{
max_tokens: 100,
},
{
includeOriginalResponse: true,
},
);
prettyResult(response.results);
console.log();
console.timeEnd('Timer');
console.log();
} catch (error) {
console.error('Error processing LLMInterface.sendMessage:', error);
}
}
exampleUsage();