[mirotalksfu] - keep chatGPT context
هذا الالتزام موجود في:
@@ -41,7 +41,7 @@ dependencies: {
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.3.91
|
* @version 1.3.92
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -1593,26 +1593,33 @@ function startServer() {
|
|||||||
: room.sendTo(data.to_peer_id, 'message', data);
|
: room.sendTo(data.to_peer_id, 'message', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('getChatGPT', async ({ time, room, name, prompt }, cb) => {
|
socket.on('getChatGPT', async ({ time, room, name, prompt, context }, cb) => {
|
||||||
if (!roomList.has(socket.room_id)) return;
|
if (!roomList.has(socket.room_id)) return;
|
||||||
if (!config.chatGPT.enabled) return cb('ChatGPT seems disabled, try later!');
|
if (!config.chatGPT.enabled) return cb({ message: 'ChatGPT seems disabled, try later!' });
|
||||||
|
// https://platform.openai.com/docs/api-reference/completions/create
|
||||||
try {
|
try {
|
||||||
// https://platform.openai.com/docs/api-reference/completions/create
|
// Add the prompt to the context
|
||||||
const completion = await chatGPT.completions.create({
|
context.push({ role: 'user', content: prompt });
|
||||||
model: config.chatGPT.model || 'gpt-3.5-turbo-instruct',
|
// Call OpenAI's API to generate response
|
||||||
prompt: prompt,
|
const completion = await chatGPT.chat.completions.create({
|
||||||
|
model: config.chatGPT.model || 'gpt-3.5-turbo',
|
||||||
|
messages: context,
|
||||||
max_tokens: config.chatGPT.max_tokens,
|
max_tokens: config.chatGPT.max_tokens,
|
||||||
temperature: config.chatGPT.temperature,
|
temperature: config.chatGPT.temperature,
|
||||||
});
|
});
|
||||||
const response = completion.choices[0].text;
|
// Extract message from completion
|
||||||
|
const message = completion.choices[0].message.content.trim();
|
||||||
|
// Add response to context
|
||||||
|
context.push({ role: 'assistant', content: message });
|
||||||
|
// Log conversation details
|
||||||
log.info('ChatGPT', {
|
log.info('ChatGPT', {
|
||||||
time: time,
|
time: time,
|
||||||
room: room,
|
room: room,
|
||||||
name: name,
|
name: name,
|
||||||
prompt: prompt,
|
context: context,
|
||||||
response: response,
|
|
||||||
});
|
});
|
||||||
cb(response);
|
// Callback response to client
|
||||||
|
cb({ message: message, context: context });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === 'APIError') {
|
if (error.name === 'APIError') {
|
||||||
log.error('ChatGPT', {
|
log.error('ChatGPT', {
|
||||||
@@ -1622,11 +1629,11 @@ function startServer() {
|
|||||||
code: error.code,
|
code: error.code,
|
||||||
type: error.type,
|
type: error.type,
|
||||||
});
|
});
|
||||||
cb(error.message);
|
cb({ message: error.message });
|
||||||
} else {
|
} else {
|
||||||
// Non-API error
|
// Non-API error
|
||||||
log.error('ChatGPT', error);
|
log.error('ChatGPT', error);
|
||||||
cb(error.message);
|
cb({ message: error.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mirotalksfu",
|
"name": "mirotalksfu",
|
||||||
"version": "1.3.91",
|
"version": "1.3.92",
|
||||||
"description": "WebRTC SFU browser-based video calls",
|
"description": "WebRTC SFU browser-based video calls",
|
||||||
"main": "Server.js",
|
"main": "Server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (location.href.substr(0, 5) !== 'https') location.href = 'https' + location.h
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.3.91
|
* @version 1.3.92
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.3.91
|
* @version 1.3.92
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -238,6 +238,7 @@ class RoomClient {
|
|||||||
this.camera = 'user';
|
this.camera = 'user';
|
||||||
this.videoQualitySelectedIndex = 0;
|
this.videoQualitySelectedIndex = 0;
|
||||||
|
|
||||||
|
this.chatGPTContext = [];
|
||||||
this.chatMessages = [];
|
this.chatMessages = [];
|
||||||
this.leftMsgAvatar = null;
|
this.leftMsgAvatar = null;
|
||||||
this.rightMsgAvatar = null;
|
this.rightMsgAvatar = null;
|
||||||
@@ -3511,22 +3512,17 @@ class RoomClient {
|
|||||||
room: this.room_id,
|
room: this.room_id,
|
||||||
name: this.peer_name,
|
name: this.peer_name,
|
||||||
prompt: peer_msg,
|
prompt: peer_msg,
|
||||||
|
context: this.chatGPTContext,
|
||||||
})
|
})
|
||||||
.then((completion) => {
|
.then((completion) => {
|
||||||
if (!completion) return;
|
if (!completion) return;
|
||||||
console.log('Receive message:', completion);
|
const { message, context } = completion;
|
||||||
|
this.chatGPTContext = context ? context : [];
|
||||||
|
console.log('Receive message:', message);
|
||||||
this.setMsgAvatar('right', 'ChatGPT');
|
this.setMsgAvatar('right', 'ChatGPT');
|
||||||
this.appendMessage(
|
this.appendMessage('right', image.chatgpt, 'ChatGPT', this.peer_id, message, 'ChatGPT', 'ChatGPT');
|
||||||
'right',
|
|
||||||
image.chatgpt,
|
|
||||||
'ChatGPT',
|
|
||||||
this.peer_id,
|
|
||||||
completion,
|
|
||||||
'ChatGPT',
|
|
||||||
'ChatGPT',
|
|
||||||
);
|
|
||||||
this.cleanMessage();
|
this.cleanMessage();
|
||||||
this.speechInMessages ? this.speechMessage(true, 'ChatGPT', completion) : this.sound('message');
|
this.speechInMessages ? this.speechMessage(true, 'ChatGPT', message) : this.sound('message');
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('ChatGPT error:', err);
|
console.log('ChatGPT error:', err);
|
||||||
@@ -3942,6 +3938,7 @@ class RoomClient {
|
|||||||
removeAllChildNodes(chatPublicMessages);
|
removeAllChildNodes(chatPublicMessages);
|
||||||
removeAllChildNodes(chatPrivateMessages);
|
removeAllChildNodes(chatPrivateMessages);
|
||||||
this.chatMessages = [];
|
this.chatMessages = [];
|
||||||
|
this.chatGPTContext = [];
|
||||||
this.sound('delete');
|
this.sound('delete');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم