From 103b0f7a2f459b8b782e3550247e2af6a635fa08 Mon Sep 17 00:00:00 2001 From: Stef Dunlap Date: Sat, 18 Mar 2023 11:35:07 -0400 Subject: [PATCH] Allow custom model --- config.example.json | 4 +++- index.js | 16 ++++++++++------ ircgpt.example.service | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) mode change 100644 => 100755 index.js create mode 100644 ircgpt.example.service diff --git a/config.example.json b/config.example.json index 68be110..5c615e7 100644 --- a/config.example.json +++ b/config.example.json @@ -11,5 +11,7 @@ "initialSystemMessage": "You are a helpful assistant.", "newChatCmd": "!chat", "contChatCmd": "!cont", - "alwaysRemember": false + "alwaysRemember": false, + "debug": false, + "model": "gpt-4" } diff --git a/index.js b/index.js old mode 100644 new mode 100755 index c0447ab..8734ec7 --- a/index.js +++ b/index.js @@ -63,11 +63,13 @@ client.connect({ } }); -client.on('debug', console.log); -client.on('raw', console.log); +if(config.debug) { + client.on('debug', console.log); + client.on('raw', console.log); +} client.on('registered', () => { - client.join(config.channels); + config.channels.forEach(channel => client.join(channel)); }); // listen for messages that start with !chat and call the chatgpt api with a callback that prints the response line by line @@ -110,7 +112,7 @@ function chatgpt(query, messages, callback) { return new Promise((resolve, reject) => { axios.post(apiUrl, { messages: messages, - model: 'gpt-3.5-turbo', + model: config.model, stream: true, }, { headers: { @@ -124,7 +126,9 @@ function chatgpt(query, messages, callback) { let parts = data.split('\n'); // parse if starts with data: for (let part of parts) { - console.log(part); + if(config.debug) { + console.log(part); + } if (part === 'data: [DONE]') { callback(currentLine); @@ -184,4 +188,4 @@ function chatgpt(query, messages, callback) { reject(error); }); }); -} \ No newline at end of file +} diff --git a/ircgpt.example.service b/ircgpt.example.service new file mode 100644 index 0000000..0d70689 --- /dev/null +++ b/ircgpt.example.service @@ -0,0 +1,15 @@ +[Unit] +Description=ircgpt +After=ircgpt.service + +[Service] +Type=simple +WorkingDirectory=/home/kindrobot/wrk/ircgpt +ExecStart=/home/kindrobot/wrk/ircgpt/index.js +Restart=always +RestartSec=5 +StartLimitInterval=60s +StartLimitBurst=3 + +[Install] +WantedBy=default.target