[mirotalksfu] - add chatGPT-OpenAI

هذا الالتزام موجود في:
Miroslav Pejic
2023-04-14 19:54:56 +02:00
الأصل 618e7b03cb
التزام f8d4f001fb
8 ملفات معدلة مع 117 إضافات و10 حذوفات

عرض الملف

@@ -121,6 +121,20 @@ if (sentryEnabled) {
*/
}
// OpenAI/ChatGPT
let chatGPT;
if (config.chatGPT.enabled) {
if (config.chatGPT.apiKey) {
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: config.chatGPT.apiKey,
});
chatGPT = new OpenAIApi(configuration);
} else {
log.warning('ChatGPT seems enabled, but you missing the apiKey!');
}
}
// directory
const dir = {
public: path.join(__dirname, '../../', 'public'),
@@ -404,6 +418,8 @@ function startServer() {
mediasoup_server_version: mediasoup.version,
mediasoup_client_version: mediasoupClient.version,
sentry_enabled: sentryEnabled,
slack_enabled: slackEnabled,
chatGPT_enabled: config.chatGPT.enabled,
});
} catch (err) {
log.error('Ngrok Start error: ', err.body);
@@ -442,6 +458,8 @@ function startServer() {
mediasoup_server_version: mediasoup.version,
mediasoup_client_version: mediasoupClient.version,
sentry_enabled: sentryEnabled,
slack_enabled: slackEnabled,
chatGPT_enabled: config.chatGPT.enabled,
});
});
@@ -924,6 +942,34 @@ function startServer() {
}
});
socket.on('getChatGPT', async ({ prompt }, cb) => {
if (!roomList.has(socket.room_id)) return;
if (!config.chatGPT.enabled) return cb('ChatGPT seems disabled, try later!');
try {
// https://platform.openai.com/docs/api-reference/completions/create
const completion = await chatGPT.createCompletion({
model: config.chatGPT.model || 'text-davinci-003',
prompt: prompt,
max_tokens: config.chatGPT.max_tokens,
temperature: config.chatGPT.temperature,
});
const response = completion.data.choices[0].text;
log.debug('ChatGPT', {
prompt: prompt,
response: response,
});
cb(response);
} catch (error) {
if (error.response) {
log.error('ChatGPT', error.response);
cb(error.response.data.error.message);
} else {
log.error('ChatGPT', error.message);
cb(error.message);
}
}
});
socket.on('disconnect', () => {
if (!roomList.has(socket.room_id)) return;

عرض الملف

@@ -70,6 +70,7 @@ module.exports = {
},
slack: {
/*
Slack
1. Goto https://api.slack.com/apps/
2. Create your app
3. On Settings - Basic Information - App Credentials, chose your Signing Secret
@@ -78,6 +79,19 @@ module.exports = {
enabled: false,
signingSecret: '',
},
chatGPT: {
/**
ChatGPT
1. Goto https://platform.openai.com/
2. Create your account
3. Generate your APIKey https://platform.openai.com/account/api-keys
*/
enabled: false,
apiKey: '',
model: 'text-davinci-003',
max_tokens: 1000,
temperature: 0,
},
mediasoup: {
// Worker settings
numWorkers: Object.keys(os.cpus()).length,