aptai
Version:
Node.js client for aptAI APIs
45 lines (39 loc) • 1.13 kB
JavaScript
const { getConfig, apiDomain, defaultTimeout } = require('../../../config.js');
const axios = require('axios');
// Function to make the API request
async function llmV3API(options) {
const apiUrl = `${apiDomain}/api/service/llm/v3`;
const { apiKey } = getConfig();
if (!apiKey) {
throw new Error('API key must be initialized');
}
// Default values for the parameters
const defaults = {
q: '',
group_id: '',
followUp: 0,
limit: 0,
regenerate_id: '',
model: '',
timeout: defaultTimeout
};
// Merge the passed options with the defaults
const data = { ...defaults, ...options };
const headers = {
'Content-Type': 'application/json',
'Authorization': `${apiKey}`,
};
try {
const response = await axios.post(apiUrl, data, { headers, timeout: data.timeout });
return response;
} catch (error) {
if(error && error.hasOwnProperty('response') && error.response != null && error.response.hasOwnProperty('data')){
throw new Error(error.response.data.message);
}else{
throw new Error(error.message);
}
}
}
module.exports = {
llmV3API,
};