leumas-axios
Version:
An advanced Axios wrapper with extended features and Express multi-post middleware for conversational API endpoints.
49 lines (43 loc) • 1.58 kB
JavaScript
// tests/generative-post-test.js
const AdvancedAxios = require('../index');
const advancedAxios = new AdvancedAxios({ timeout: 5000 });
const generativePostUrl = 'http://localhost:7643/api/generative-post';
// ChatGPT configuration for generating the complete payload.
// If not passed in explicitly, the generativePost method will use system environment variables.
const chatGptConfig = {
// You can override these values, but by default they will be pulled from process.env if available.
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-3.5-turbo',
temperature: 0.5,
max_tokens: 4096,
// Define the desired output structure.
outputStructure: {
name: "string",
email: "string",
address: "string",
phone: "string",
kycStatus: "string",
additionalInfo: {
idNumber: "string",
expiryDate: "string"
}
},
additionalPrompt: "Ensure that the returned JSON strictly follows the provided structure. Do not include any additional keys or commentary."
};
async function testGenerativePost() {
try {
// Provide some incomplete initial data.
const initialData = { name: 'Alice' };
// Call generativePost with the ChatGPT configuration.
const result = await advancedAxios.generativePost(
generativePostUrl,
{ data: initialData },
{ chatGptConfig }
);
console.log('Generative Post Result:');
console.log(result);
} catch (error) {
console.error('Error in generativePost test:', error.message);
}
}
testGenerativePost();