Skip to content

Commit

Permalink
Merge pull request #2 from josiasbudaydeveloper/testing-context-chang…
Browse files Browse the repository at this point in the history
…es-feature

Breaking changes in index.js: now the chatbot will always answer the questions separately
  • Loading branch information
josiasbudaydeveloper authored Mar 5, 2023
2 parents 835f48c + b33ef95 commit 4757e60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# cloudwalk-self-driven-bank-gpt-chatbot
This is a ChatBot project to explain about the CloudWalk's Self Driven Bank project, based on OpenAI's GPT technology.

## Version 2.0.0
Breaking changes about the chatbot logic:
### Now the chatbot will always answer the questions separately
#### Explanation
The previous intention was build something like ChatGPT, where it can understand the changes in the context during the conversasion.

This is a complex feature and may be it will be implemented in the future, but for now, I will make all questions be treated separetely.

In addition, another disadvantage is that every new question will send the entire information about CloudWalk, so the costs will be a little higher, because the API charges $0.002/token.

#### In summary, these are the disadvantages of this solution:
The chat do not understand any information between the questions
The costs related to the API behind the chat will be a little higher, because the API charges $0.002/token and the messages of the question will always be with the entire information about CloudWalk.

## Project Description
This is the description of my project of OpenAI API's usage showcase.

Expand Down Expand Up @@ -65,8 +79,11 @@ const completion = await openai.createChatCompletion({
});
```

Still about how the project works, the Socket.io library to creates a websocket between the client and server.
For every new question, the server responds based on the previous messages in the chat.
Still about how the project works, the Socket.io library to creates a websocket between the client and server.

~~For every new question, the server responds based on the previous messages in the chat.~~

> For now, in reason of trouble with the AI understanding related to the changes of context during the conversation, the chatbot will treat all conversation messages separetaly.
## Installation
To install this project, you need to follow these steps:
Expand Down
35 changes: 8 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,19 @@ app.get('/', (req, res) => {

/* Configuring Socket.io */
io.on('connection', (socket) => {
const arrayMessages = [];
let counter = 0;

socket.on('chat message', async (msg) => {
if (arrayMessages.length == 0) {
arrayMessages.push({
role: 'user',
content: `${information} Based on this information, please answer my question: ${msg}`
});
}

socket.on('chat message', async (msg) => {
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: arrayMessages,
messages: [{
"role": "user",
"content": `${information} Based on this information, please answer my question: ${msg}`
}]
});

if (arrayMessages.lenght % 2 == 0) {
arrayMessages.push({
role: 'user',
content: msg
});
}
else {
arrayMessages.push({
role: 'assistant',
content: completion.data.choices[0].message.content
});
}

const answer = completion.data.choices[0].message.content;

io.emit('chat message', msg);
io.emit('chat message', completion.data.choices[0].message.content);
counter++;
io.emit('chat message', answer);
});
});

Expand Down

0 comments on commit 4757e60

Please sign in to comment.