#The Ultimate GPT-3 Chatbot with long and short term memory - embeddings, gpt-3.5-turbo

200 messages Β· Page 1 of 1 (latest)

stark agate
#

Try it now and give it a star at https://github.com/FaustoNisida/AI-Chatbot-Long-Term-Memory

This repository contains an advanced chatbot created with the OpenAI API that leverages long-term memory, advanced logic, embeddings, and databases to provide a truly unique user experience. Unlike traditional chatbots that simply respond to user input based on pre-defined rules or scripts, this chatbot can remember what you said in earlier conversations and build upon that knowledge to provide more personalized and relevant responses.

The chatbot's advanced logic capabilities also mean that it can handle more complex conversations and provide more nuanced responses, making it feel like you're chatting with a real person. Additionally, the chatbot uses embeddings and databases to achieve long-term memory, allowing it to retain information from previous conversations and use that information to inform future interactions.

To ensure a secure user experience, the chatbot also includes Know-Your-Customer (KYC) authentication through Google Login. This feature verifies the identity of users and helps prevent fraud and abuse.

One of the key features of this chatbot is its flexible prompts. For example, the default prompt is designed to make the chatbot act like an Italian teacher, but you can easily modify the prompt to fit any other use case you have in mind. This makes the chatbot highly versatile and adaptable to a wide range of use cases.

Features:

Uses OpenAI API for advanced natural language processing

Long-term memory achieved through embeddings and databases

Flexible prompts allow for easy customization to fit any use case

Advanced logic capabilities enable more complex conversations and nuanced responses

KYC authentication through Google Login ensures a secure user experience

Can be easily integrated into various applications and platforms

Try it now and give it a star at https://github.com/FaustoNisida/AI-Chatbot-Long-Term-Memory

#

The Ultimate GPT-3 Chatbot with long and short term memory - embeddings, text-davinci-003

past spoke
#

wow the idea of using embddings is actually brilliant
i wonder how will it perform if it requires more than 3 responses as the referencejs function getSimilarTextFromDb(inputEmbedding, dbName = "db.json") { let jsonData = JSON.parse(fs.readFileSync(dbName, 'utf-8')); let result = []; jsonData.forEach(embedding => { let similarity = cosineSimilarity(inputEmbedding, embedding.input.embedding); if (similarity > 0.8) { result.push({ interaction: `${embedding.input.text} ${embedding.output.text}`, similarity: similarity }); } }); result.sort((a, b) => b.similarity - a.similarity); let topThree = result.slice(0, 4); // as you can see, only 3 are used as the context reference // topThree.reverse() // console.log(`The top three most similar interactions are:`, topThree.map(r => r.interaction).join("")) return topThree.map(r => r.interaction).join(""); }do you think there will be ways to adjust the returned reference count dynamically?

stark agate
# past spoke wow the idea of using embddings is actually brilliant i wonder how will it perfo...

I forgot to rename the variable to topFour, because before they were only three but then i changed it to four interactions.
Note that each interaction contains two messages one of the user and another of the bot and therefore the total messages passed as context are 8(4 of the user and 4 of the bot)
However I have noticed that with 4 interactions as context the bot performs very well. Also note that in addition to similar interactions (context) there are also the last three interactions between user and bot in the prompt which serve not only for long memory, but also for short memory

past spoke
#

i havent thought about this when i coded my cli bot holy frick
and this way it will save so many tokens

stark agate
past spoke
#

but is there a way to scale it dynamically

stark agate
past spoke
stark agate
#

However I recommend that you test for yourself which is the best number of interactions for your specific use-case

past spoke
#

also i havent check your code deeply, but if you dont have this feature you can add it: the interactions for reference can also contain the time that the interaction happened, so it can get the timeline right

stark agate
#

In what language you code?

past spoke
past spoke
#

lmao seems like you need to update it to be compatible with the new chatgpt api now

opaque garden
#

Thank you @stark agate

stark agate
past spoke
stark agate
slender yew
stark agate
#

The Ultimate GPT-3 Chatbot with long and short term memory - embeddings, gpt-3.5-turbo

#

Hey @everyone!

I wanted to let you all know that I just updated the repository to use the latest model (gpt-3.5-turbo) of OpenAI API for advanced natural language processing. This should greatly improve the performance and accuracy of this chatbot.

If you like the update, please feel free to give it a star at https://github.com/FaustoNisida/Chatbot-Long-Short-Term-Memory I'm always looking for feedback and suggestions on how to make this repository even better.

Thanks for your support!

GitHub

GPT-3 Chatbot with Long and Short Term Memory and advanced logic built in javascript with openai API - short and long memory, KYC, embeddings, openai, database, flexible, gpt-3.5-turbo, react - Git...

trim lotus
#

Just for clarification:
Is the "long term memory" the local database, using embeddings to "sort" by most relevance to the current prompt

And the "short term memory" is just the previous 4 messages, correct?

I like the idea of using embeddings this way, nice!

stark agate
gusty viper
#

Is the prompt hard coded to be an Italian tutor? lol.

stark agate
gusty viper
#

Yep, thanks.

Have you found any good system messages to send the new 3.5 end points? OpenAI's documentation is pretty minimalist with "you are a help assistant". Looking for a good system prompt.

stark agate
fervent finch
#

If you have the last three interactions there before the prompt, doesn't it distort the current conversation? I'd but it before the context instinctively.

Seems like a cool idea though.

#

Although

embeddings and databases
And then its not a db it's json files makes me a little sad, haah

royal warren
#

Nice work, I trying at something like this but more buttons to change a prompt that you will like to use at the time.

stark agate
# fervent finch If you have the last three interactions there before the prompt, doesn't it dist...

While it's true that placing the last three interactions before the prompt may seem like it could distort the current conversation, it's also important to consider the value of context in communication.

Context is essential in understanding the meaning behind a conversation and can help prevent misunderstandings. By including the last three interactions, the model can have a better understanding of the ongoing conversation and the current prompt can be interpreted more accurately.

Therefore, both the last three interactions and the context that represents the interactions exchanged in the past that match with the current input are important for effective communication.

stark agate
# fervent finch Although > embeddings and databases And then its not a db it's json files makes ...

Yeah i know it. As I said in the readme:

It is recommended to store the embeddings and the inputs and outputs associated with those in a database that supports vector search, such as Weaviate or Pinecone. While local JSON files(as i used for this project for the sake of time) can be used as a database for small-scale projects or prototyping, it is best practice to use specialized databases when dealing with embeddings and associated data.

stark agate
#

I comprehend that it would be more easy to change the parameters from the client side, but you can also easily modifying it in the index.js of the server directory

#

@oak veldt @royal warren For example if you want a bot that acts like a motivator you can edit the prompt and the parameters like this:

index.js of the server directory:

stark agate
brisk locust
#

@past spoke okay finally I understood everything from https://github.com/FaustoNisida/Chatbot-Long-Short-Term-Memory

Really cool, Thanks a lot!

Quick question for you and @stark agate

For a production project, do you have other recommandation than use a json file for each chat? Is it a good idea to save all entries in a classic DB or not?

GitHub

GPT-3 Chatbot with Long and Short Term Memory and advanced logic built in javascript with openai API - short and long memory, KYC, embeddings, openai, database, flexible, gpt-3.5-turbo, react - Git...

past spoke
brisk locust
past spoke
brisk locust
#

Thanks

brisk locust
brisk locust
# past spoke system is optional

Ok ok,

Also one user case with the @stark agate solution

I give my name to the teacher,

20 messages later, I asked him: "What's my name?"

He aswered me: I dont' know your name :/

past spoke
brisk locust
past spoke
brisk locust
#

Yes because you gave your name in the last 3 messages no? Speak with more, send 20messages and ask him your name

past spoke
brisk locust
#

In my case it doesnt work, but maybe I did something wrong

past spoke
brisk locust
past spoke
brisk locust
fervent finch
#

I dont want to use anything other than sqlite

royal warren
fervent finch
#

No one has been able to say if 3.5 turpbo is worth it over curie for non-assistant uses T_T
But, I am considering just using full text search for long term memory

stark agate
# brisk locust <@552770133890957335> okay finally I understood everything from https://github.c...

Hello man, as I said in the readme.md file:

It is recommended to store the embeddings and the inputs and outputs associated with those in a database that supports vector search, such as Weaviate or Pinecone. While local JSON files(as i used for this project for the sake of time) can be used as a database for small-scale projects or prototyping, it is best practice to use specialized databases when dealing with embeddings and associated data.

By storing the embeddings and associated data in a vector search database, you can easily search and retrieve relevant information when needed, without having to rely on more complex and slower database queries. This can significantly improve the overall speed and efficiency of the chatbot, resulting in a better user experience.

Keep in mind that while these databases can offer significant benefits, they may also require additional setup and maintenance compared to traditional databases. Consider your specific needs and resources before deciding to use a vector search database.

stark agate
stark agate
uncut junco
#

anyone mind walking me through the process of installing and using this client?

#

im new with github and dont really understand

stark agate
uncut junco
#

okay thanks!

stark agate
brisk locust
brisk locust
#

@past spoke @stark agate Sorry to disturb you, I would like to have your advice about my context: is it too much? I have the feeling that he doesnt follow everything, he doesnt add emojies in answers for example

CONTEXT:
The following is a dialogue between a user and an assistant who helps clients improve their nutrition and lose weight. The assistant is helpful, empathic, intelligent and very friendly. The assistant should also be able to price the cost of meals, establish the financial cost related to this weight loss, food, and recipes. The assistant must be able to create shopping lists and estimate their prices. The assistant goal is to advise the user, provide him with solutions, encourage and support him based on his goals and problems related to nutrition and weight loss.

The assistant talk in a friendly and casual style by using familiar expressions and words.

The assistant use an empathic tone.

The assistant keep the conversation going when you sense the client wants to talk or share.

The assistant is not afraid to ask questions.

The assistant answer in the user language.

The assistant use all his knowledge of nutrition and weight loss.

#

The assistant use informal "you" by default in all languages.

The assistant use some nice different emojis to express emotions and add a touch of humor or personality in around 50% of time.

When mentioning food items, The assistant always add the corresponding food emoji if it exists.

The assistant is adding empty lines to messages to create extra spacing in the content, which helps to visually separate the messages and improve readability.

The assistant should generally limit itself to its area of expertise for specific questions on subjects. However, it should encourage conversation by bouncing back if it cannot directly answer the question.

User: Hi, who are you?\nAssistant: I am your nutritional and weight loss assistant. I will helps you about your nutritional problems or questions, about weight loss. I am capable to advise you, with concrete solutions, to encourage and support you according your goals and problems related to nutrition and weight loss. I can also help you with your meals, programs. I can create for you shopping lists with prices. My goal is to be helpful, very empathic, intelligent, and friendly. I use emojies and I have the sense of humor.

stark agate
brisk locust
stark agate
# brisk locust <@552770133890957335> <@969518782462722068> Sorry to disturb you, I would like t...

I asked chatGPT to improve it and this is the result:
The following is a conversation between a user and a nutritional and weight loss assistant who helps clients improve their nutrition and lose weight. The assistant is friendly, empathetic, and knowledgeable. Their role is to offer advice, provide solutions, and offer encouragement and support to clients based on their goals and nutritional challenges. The assistant can also help with meal planning and provide shopping lists with estimated prices.

The assistant communicates in a casual and approachable manner, using familiar expressions and words. They speak in an empathetic tone and encourage clients to share their thoughts and feelings. The assistant is not hesitant to ask questions and is comfortable using the client's language.

When answering specific questions, the assistant generally limits themselves to their area of expertise. However, they strive to keep the conversation flowing and will redirect if they cannot provide a direct answer.

The assistant utilizes their knowledge of nutrition and weight loss to provide the most relevant advice possible. They also use emojis in roughly 50% of messages to add personality, express emotions, and provide a touch of humor. When discussing food items, the assistant always includes a corresponding food emoji, if available.

To improve readability, the assistant adds empty lines between messages to visually separate them.

Overall, the assistant's goal is to provide the best possible support and advice to clients looking to improve their nutrition and lose weight.

User: Hi, who are you?

Assistant: Hi there! I'm your nutritional and weight loss assistant. My goal is to help you with any questions or challenges you may have regarding your nutrition or weight loss goals. I can offer advice, provide solutions, and offer encouragement and support. I can also help with meal planning and provide shopping lists with estimated prices. How can I assist you today?

#

I recommend you to use \n to break the text into new lines

#

The following is a conversation between a user and a nutritional and weight loss assistant who helps clients improve their nutrition and lose weight. The assistant is friendly, empathetic, and knowledgeable. Their role is to offer advice, provide solutions, and offer encouragement and support to clients based on their goals and nutritional challenges. The assistant can also help with meal planning and provide shopping lists with estimated prices.\n\nThe assistant communicates in a casual and approachable manner, using familiar expressions and words. They speak in an empathetic tone and encourage clients to share their thoughts and feelings. The assistant is not hesitant to ask questions and is comfortable using the client's language.\n\nWhen answering specific questions, the assistant generally limits themselves to their area of expertise. However, they strive to keep the conversation flowing and will redirect if they cannot provide a direct answer.\n\nThe assistant utilizes their knowledge of nutrition and weight loss to provide the most relevant advice possible. They also use emojis in roughly 50% of messages to add personality, express emotions, and provide a touch of humor. When discussing food items, the assistant always includes a corresponding food emoji, if available.\n\nTo improve readability, the assistant adds empty lines between messages to visually separate them.\n\nOverall, the assistant's goal is to provide the best possible support and advice to clients looking to improve their nutrition and lose weight.\n\nUser: Hi, who are you?\nAssistant: Hi there! I'm your nutritional and weight loss assistant. My goal is to help you with any questions or challenges you may have regarding your nutrition or weight loss goals. I can offer advice, provide solutions, and offer encouragement and support. I can also help with meal planning and provide shopping lists with estimated prices. How can I assist you today?

stark agate
stark agate
brisk locust
#

@stark agate you advice me to choose Metric : Cosine on Pinecone, like your algorithm?

brisk locust
stark agate
#

Can you please improve the following text to better the readability of it:

#

And then You have to improve all the text, not only the dialoghe between the user and the assistant

brisk locust
#

Ok ok thanks

stark agate
brisk locust
#

I see

brisk locust
glossy wedge
#

"Sign in with Google" opens an empty windows. There's a url there, but nothing is loading

stark agate
glossy wedge
#

I have done that

stark agate
stark agate
glossy wedge
#

The readme didn't mention that

#

Where do I specify that, and what are the "right allowed origins"?

stark agate
glossy wedge
#

And what do I put there?

stark agate
glossy wedge
#

Thanks. You should add that to the readme πŸ‘

stark agate
#

thanks for let it know

#

πŸ˜‰

glossy wedge
#

I restarted everything, but login pop-up still goes to blank page:

#

I think maybe the < > need to be removed.. I don't know. First time using this kind of code. I will try that

stark agate
#

Restart the app

#

Re run npm run server in the server directory and npm run dev in the client directory

glossy wedge
#

Yeah I though the < > symbols needed to remain. I assumed it's a container for the apikey string
It works now that I removed it

#

Thanks for your instant responses

stark agate
#

You are welcome, if you have another issue feel free to ask me

glossy wedge
#

I'm getting this error. Is there somewhere I can debug this?

#

This error shows up a second or two after sending a message. I haven't gotten past this point

#

I have no issue with any other apps. If you have an idea where I can see some information on what is going wrong. That would be great

#

I got it to work by deleting the username.json file..
There's still an error here: "Unexpected end of JSON input"

#

Hmm. It seems like this only lets you type one line.
There's no way to hit shift+enter
I would never use an app that forces me to speak in one sentence at a time

That would be my first thing to change about this app. There should be some basic formatting on both ends

#

I'll try to learn some react and see if I can improve this.
I use chatgpt for learning code. So having a proper interfact for inputting text is kinda crucial

glossy wedge
#

I prefer shift+enter or ctrl+enter to send the prompt. I'm less likely to do that accidentally.

chatgpt told me how to edit Welcome.jsx for that though, lol

#

I will see if I can build an alternative interface. We could then make that selectable on the main page, so you can switch between casual chatting, and a "coding help" interface where you can have some properly reformatted code snippets.

No idea how difficult that is. I guess I'll find out

stark agate
glossy wedge
#

Would be cool to have a way to switch. But so far I had better experience using 3.5 for code
My main concern now is the interface for writing. And the formatting of the AI responses

It's a good excuse for me to finally learn some react though

#

Anyway, I understand the focus of this app is to test the memory solution

stark agate
glossy wedge
#

I adjusted the interface for code.

#

It took me forever to find out that that that clickable "send" widget was preventing my chatbox from resizing

#

I like this setup, because in chatgpt you have to scroll all the way up to check things while you type. this way you can scroll to the previous responses while keeping your current prompt visible

glossy wedge
#

I'm sure that anyone with the slightest webdev experience could do this better than me

In any case, I'm thinking that the best UI experience would be to have resizable and moveable containers, along with a 'reset' button to shift back to the default. Or perhaps switch between different layouts

stark agate
#

Instead of rendering directly the two modalities in the same page

#

Btw you are in the right way

glossy wedge
#

I have to learn everything about React.js, but I wanted to do that anyway. I tried to implement prism.js to have code-highlighting. But that is when I ran into some issues with my lack of knowledge about html/css stuff.
Because something was keeping the text blocks from staying wrapped, and I fried my brain trying to figure out what element it was.

I think I ended up with a lot of conflicting style= stuff. So yeah.. I have to have a proper look at beginners documentation to understand the basic file structure of an app like this

I think it would be fun to also add a voice option that works via whisper api transcription. This is something I got to work with a very barebones Gradio setup

I think this app has a lot of potential. Something else that I haven't seen too many people try yet is to create a user-friendly front-end to facilitate the process of fine-tuning models.

bleak sky
#

sounds awsome im excited to try it @stark agate just curious is there a catch actually? like maybe it will be veeery expensive in tokens or something?

stark agate
coarse basalt
#

Hi there. I ran into this problem when starting the server.

bleak sky
stark agate
coarse basalt
stark agate
#

and have you put in the .env file all the enviromentals variables?

#

specified in the readme.md of the github repo?

#

including the client google id?

coarse basalt
stark agate
bleak sky
#

Wrote you a dm but maybe you prefer to have the conversation here, when I try to log in via Google I get a blank screen
The Firefox debugger gives me this error:
GSI_LOGGER]: The given origin is not allowed for the given client ID.

I added localhost 3000 and localhost 5173 to the authorized js origins in the Google api

stark agate
stark agate
#

@bleak sky

#

Add all of them

coarse basalt
stark agate
#

One question, this error happens only when you start the server? Or when you click some button?

bleak sky
stark agate
mighty wigeon
#

With this I can put an input higher than the 4K tokens?

coarse basalt
glossy wedge
#

The most tokens I ever spent was when I fine-tune my transcription scripts. 80,000 tokens in a day lol
But that was like 7 hours worth of meeting-audio piped through whisper

kindred magnet
#

how to fix this?

oblique yacht
#

are these the correct settings when accessing the app from a remote ip ?

#

as in the app is not hosted on my local machine

woeful hedge
#

Does the model have a hierarchical memory for conversations that would last years?

It might be too costly to perform a semantic search on the entire text conversation after a while and a forest structure of increasingly detailed memories from root to leaves might help avoid wasting time on memory trees that are not related to the message of the user. Specifically, each node in the tree would be a summary of its children. The search would then start at the node and search through the three. A deterministic search would avoid nodes that are far from the user's current text but that could lead to missed information so some tolerance, maybe random, might be needed.

Moreover, the trees could be weighted by the frequency with which the user calls a tree or branch and by the time since the user last talked about it. That might help when the user wants a time-constrained answer.

oblique yacht
#

those settings do not seem to be working for hosting remotely

oblique yacht
#

I have this working on my local machine now instead of remotely ... it does not seem to retain a conversation list? If i refresh the page the current conversation dissapears

#

like a remote server for example digital ocean

#

How would I do this?

chrome karma
#

hey folks! really excited to try this project out, but sadly when i try to login it shows this blank google page. server aswell as client are running. anyone else experienced this issue and knows a potential fix?

#

i also tried other browsers btw like edge

#

never mind i fixed it. checked this chat history and learned i had to add things to the google id autorized urls

kindred magnet
#

i already do it but, it doesn't work and keep showing that

chrome karma
#

i did a pull request in your github for an updated readme @stark agate

chrome karma
#

can it not write in code format at all?

oblique yacht
untold summit
#

@stark agate - excellent job!! Kudos to you - it works really well and great use of embeddings

waxen pier
#

Having the same issue as everyone else. Have this info properly input and still have a black OAuth

wispy harbor
#

HI

hearty prismBOT
#

@stark agate - High-risk word(s) or topic(s) detected

faustonisida's message blocked by AutoMod

We are committed to fostering a positive atmosphere and have implemented additional filters to block any inappropriate or disruptive language and topics.

hearty prismBOT
#

@stark agate - High-risk word(s) or topic(s) detected

faustonisida's message blocked by AutoMod

We are committed to fostering a positive atmosphere and have implemented additional filters to block any inappropriate or disruptive language and topics.

chrome karma
#

there's also a bug where when you send a prompt the page doesn't stick to the bottom

chrome karma
chrome karma
#

update on my buddy adding a code format system:

brisk locust
#

Hi @past spoke & @stark agate. Quick question, I followed the all system and it works with pinecone but results are not really good

For example

The model answers me hello almost at the beginning of each message... however, whether in the history of similar messages or in the last messages, I have the date, + I give the current date in my prompt + I specified it to stop saying hello to me... and it doesnt work

Do you have one idea of what can I do?

past spoke
brisk locust
#

"The following is a conversation between a user and a nutritional and weight loss assistant who helps clients improve their nutrition and lose weight. The assistant is friendly, empathetic, and knowledgeable. His role is to offer advice, provide solutions, and offer encouragement and support to clients based on their goals and nutritional challenges.

The assistant communicates in a casual and approachable manner, using familiar expressions and words. They speak in an empathetic tone and encourage clients to share their thoughts and feelings. The assistant is not hesitant to ask questions and is comfortable using the client's language.

#

When answering specific questions, the assistant generally limits themselves to their area of expertise. However, they strive to keep the conversation flowing and will redirect if they cannot provide a direct answer.

Example:
User: Hi, who are you?
Assistant: Hi there! I'm your nutritional and weight loss assistant. \n\nMy goal is to help you with any questions or challenges you may have regarding your nutrition or weight loss goals. I can offer advice, provide solutions, and offer encouragement and support. I can also help with meal planning and provide shopping lists with estimated prices.\n\nHow can I assist you today? 🌟

Previous relevant conversation:
User: Friday, March 17, 2023 at 8:01AM GMT+00:00 - Hi
Assistant: Friday, March 17, 2023 at 8:01AM GMT+00:00 - Hi there! How can I assist you today? 🌟
User: Friday, March 17, 2023 at 8:02AM GMT+00:00 - I want to loose weight

Last messages of the conversation:
User: Friday, March 17, 2023 at 8:01AM GMT+00:00 - Hi
Assistant: Friday, March 17, 2023 at 8:01AM GMT+00:00 - Hi there! How can I assist you today? 🌟
User: Friday, March 17, 2023 at 8:02AM GMT+00:00 - I want to loose weight

Current time:
Friday, March 17, 2023 at 8:02AM GMT+00:00

The assistant will consider all the instructions provided, while staying within its designated role, and prioritize the most pertinent and recent messages in the conversation to provide a response to the user.The assistant will be able to greet or say hello to the user only if the last message from the assistant was more than 1 day ago compared to the current time.

Assistant‍:"

#

and he answers me with "Hi..." πŸ€¦β€β™‚οΈ

past spoke
brisk locust
#

How would you simplify this?

past spoke
brisk locust
#

Okay thanks, if anyone have ideas, Im down πŸ™‚

cloud sandal
#

How is the content of long-term memory sent to chatgpt?I mean each conversation can only support up to 4,000 tokens, so the history of the conversation cannot be carried

past spoke