@coko/server
Version:
Reusable server for use by Coko's projects
44 lines • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const config_1 = __importDefault(require("../../configManager/config"));
const logger_1 = __importDefault(require("../../logger"));
const chatGPT = async (input) => {
try {
const CHAT_GPT_URL = 'https://api.openai.com/v1/chat/completions';
// const CHAT_GPT_URL = config.has('chatGPT.url') && config.get('chatGPT.url')
const CHAT_GPT_KEY = config_1.default.has('chatGPT.key') && config_1.default.get('chatGPT.key');
// if (!CHAT_GPT_URL) {
// throw new Error('Missing API URL')
// }
if (!CHAT_GPT_KEY) {
throw new Error('Missing access key');
}
const response = await axios_1.default.post(CHAT_GPT_URL, {
model: 'gpt-3.5-turbo',
// model: 'gpt-4',
messages: [
{
role: 'user',
content: input,
},
],
temperature: 0,
}, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${CHAT_GPT_KEY}`,
},
});
return response.data.choices[0].message.content;
}
catch (e) {
logger_1.default.error('chatGPT:', e);
throw e;
}
};
exports.default = chatGPT;
//# sourceMappingURL=chatGPT.controllers.js.map