-
Notifications
You must be signed in to change notification settings - Fork 63
/
genericAgent.js
25 lines (21 loc) · 987 Bytes
/
genericAgent.js
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
const { PromptTemplate } = require("langchain/prompts");
const { callGPT } = require('../modules/gpt');
/**
Asynchronous function that calls a GPT model with a prompt generated from a template and variables.
@param {string} template - A string representing a template with variables to be replaced.
@param {object} values - A dictionary of arguments to be passed to the prompt template.
@param {object} model - A GPT model to generate a response with the given prompt.
@returns {Promise<string>} - A promise that resolves to a string representing the response generated by the model.
*/
async function callAgent(template, values, model) {
const promptTemplate = PromptTemplate.fromTemplate(template);
const prompt = await promptTemplate.format(values);
const reply = await callGPT(prompt, model);
// console.log(`Prompt: ${prompt}`);
// console.log(`Reply:\n`);
// console.dir(reply, { depth: null });
return reply;
}
module.exports = {
callAgent
}