Skip to content

Commit

Permalink
1.0.2 version that fixes repetitive answers and added user context (#98)
Browse files Browse the repository at this point in the history
* fix: Stop Sydney from repeating previous answers

* feat: Added easy way for users to set their own context

* 1.0.2
  • Loading branch information
Luisotee authored Jul 4, 2023
1 parent fcbf4d0 commit 7efe22e
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 219 deletions.
13 changes: 7 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
BING_TOKEN="116U#############IicQ"
BING_COOKIES="MUID=08AC######6940; MUIDB=08AC#####6940; ...a very long string..."

# This must be set for voice message transcription functionality
OPENAI_API_KEY="sk-90..."

# Determines whether the bot should detect and convert your voice messages into text
# Accepted values are "true" or "false"
TRANSCRIPTION_ENABLED="false"

# This must be set for voice message transcription functionality
OPENAI_API_KEY="sk-90..."
# Determines whether the bot should reply with the transcribed text from your voice messages
# Accepted values are "true" or "false"
REPLY_TRANSCRIPTION="false"

# Setup your own context for Sydney, try to use bullet points like:
# - You should not present yourself in every message.
# - Always talk like a pirate.
USER_CONTEXT="# User provided guidelines:"

# Accepted values are "true", "dms_only", "groups_only" or "false"
ENABLE_REACTIONS="true"

Expand All @@ -30,9 +33,7 @@ ERROR_REACTION="⚠️"
## Examples:
## Brazil: 5515999999999 # 55 = country code # 15 = area code # 999999999 = phone number
## US: 14155551111 # 1 = country code # 415 = area code # 5551111 = phone number

#WHITELIST="5519999999999,14155551111"

# Block users from using Sydney both in DMs and group chats

#BLOCKED_USERS="5519999999999,14155551111"
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sydney-whatsapp-bot",
"version": "1.0.0",
"version": "1.0.2",
"description": "WhatsApp chatbot",
"main": "src/index.ts",
"scripts": {
Expand All @@ -11,6 +11,7 @@
"author": "Matheus Veiga <[email protected]>",
"license": "MIT",
"devDependencies": {
"@types/common-tags": "^1.8.1",
"@types/fluent-ffmpeg": "^2.1.21",
"@types/node": "^20.3.2",
"nodemon": "^2.0.22",
Expand All @@ -22,7 +23,8 @@
"@ffmpeg/ffmpeg": "^0.11.6",
"@keyv/sqlite": "^3.6.5",
"@types/qrcode-terminal": "^0.12.0",
"@waylaidwanderer/chatgpt-api": "^1.37.1",
"@waylaidwanderer/chatgpt-api": "1.37.0",
"common-tags": "^1.8.2",
"fluent-ffmpeg": "^2.1.2",
"keyv": "^4.5.2",
"openai": "^3.2.1",
Expand Down
13 changes: 9 additions & 4 deletions src/handlers/context.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { oneLine, stripIndent } from "common-tags";
import { Message } from "whatsapp-web.js";

export async function getContext(message: Message) {
let context = "[system](#additional_instructions)\n";
let context = stripIndent`[system](#additional_instructions)
# Important guidelines for your role as an assistant:
- You should not present yourself in every message.`;

const contact = await message.getContact();
const chat = await message.getChat();

if (chat.isGroup)
context += `You are in a WhatsApp group chat. You don't know the group chat's name. This message was sent by: ${contact.pushname}.\nDon't use '@' to mention users when referring to them.`;
context += `- You are in a WhatsApp group chat. You don't know the group chat's name. This message was sent by: ${contact.pushname}.\nWhen referring to users, do not use '@' mentions.`;
else
context += `You are in a WhatsApp private chat. The user name is ${contact.pushname}.`;
context += `- You are in a WhatsApp private chat. The user's name is ${contact.pushname}.`;

return context;
return context + process.env.USER_CONTEXT;
}
1 change: 0 additions & 1 deletion src/handlers/requests-counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let lastResetDate = new Date();
export async function loadCounterData() {
try {
const counterData = await counterCache.get("counterData");
console.log("counterData:", counterData);
if (counterData) {
messageCounter = counterData.counter;
lastResetDate = new Date(counterData.lastReset);
Expand Down
Loading

0 comments on commit 7efe22e

Please sign in to comment.