#create "memory" for a chatbot with gpt-3.5-turbo

1 messages · Page 1 of 1 (latest)

vague willow
#

I have to create a chatbot to interact with restaurant clients, to collect food orders from them and do the regular employee job.
i have trained my model on an Arabic dataset, but when i use the model on my local machine ‘PyCharm’ it answer the questions but without memory!.
like if i tell him ‘Hi my name is Saif’ then after that i ask him ‘What is my name?’ the model answers ‘i dont know’, so any code to help to build a memory with my model?

vapid patioBOT
#

Hi @vague willow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To create a "memory" for your chatbot using the gpt-3.5-turbo model, you need to maintain the conversation history. This is done by including the past messages in the messages parameter every time you make a call to the API. Each message has two properties: role and content. The role can be 'system', 'user', or 'assistant', and content is the text of the message from the role.

Here is an example of how you can structure your conversation:

import openai

openai.api_key = "your-api-key"

conversation_history = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hi my name is Saif"},
]

response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=conversation_history
)

# Add the assistant's reply to the conversation history
conversation_history.append({"role": "assistant", "content": response['choices'][0]['message']['content']})

# Now if you ask "What is my name?", include the conversation history
response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=conversation_history + [{"role": "user", "content": "What is my name?"}]
)

In this example, the conversation history is maintained in the conversation_history list. Every time a new message is added, it is appended to this list. This way, the model has access to all previous messages and can use this information to generate responses that take the conversation history into account.

Please note that you need to be using OpenAI Python v0.27.0 for the code to work (source (https://github.com/openai/openai-python/issues/242)).

Also, remember to replace "your-api-key" with your actual OpenAI API key.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@vague willow kapa.ai is still learning and improving, please let us know how it did by reacting below

vague willow
#

@vapid patio isn't that old library code? like ancient?

vapid patioBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Yes, you're correct. The OpenAI Python library has been updated since the version mentioned in the previous response. The latest version of the library as of the information in the extracts is 1.3.5 (source (https://github.com/openai/openai-python/issues/883)).

The code for creating a "memory" for your chatbot using the gpt-3.5-turbo model with the latest version of the library would be similar, but you should always refer to the latest documentation or the GitHub repository for the most accurate and up-to-date information.

Please note that the conversation history approach (i.e., including all previous messages in the messages parameter for each API call) is a common method for maintaining state in a conversation with the model, regardless of the specific version of the library you're using.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@vague willow kapa.ai is still learning and improving, please let us know how it did by reacting below

vague willow
#

@vapid patio example with latest library? Will it work?

vapid patioBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, it seems that the OpenAI Python library has indeed been updated, and the method for creating a "memory" for your chatbot using the gpt-3.5-turbo model has changed slightly. However, the fundamental approach of maintaining the conversation history remains the same.

Unfortunately, the extracts do not provide a specific code example using the latest version of the library. Therefore, I can't provide a confident answer with a code example.

However, the general approach would still involve maintaining a list of previous messages and including this list in the messages parameter for each API call. Each message in the list should still be a dictionary with role and content keys, where role can be 'system', 'user', or 'assistant', and content is the text of the message from the role.

For the most accurate and up-to-date information, I recommend referring to the official OpenAI API documentation (https://platform.openai.com/docs) or the OpenAI Python library GitHub repository (https://github.com/openai/openai-python).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@vague willow kapa.ai is still learning and improving, please let us know how it did by reacting below

timber smelt
#

@vague willow how would you have liked kapa to answer? is there a specific pice of the docs you would it like to have pulled up. We are always looking for new failure cases to add to our eval suite and this might be a good one

vague willow
# timber smelt <@268335106714763264> how would you have liked kapa to answer? is there a specif...

I've been testing Kapa.ai vs regular ChatGPT GPT-4.... For this one, I think kapa should've 1) realized it was suggesting an old library, 2) explain the difference between Chat Completion and Completion (Legacy) endpoints maybe?

Overall, it's been useful. I've been testing in on questions from the OAI Discourse...

https://community.openai.com/t/finetuned-gpt3-5-chatbot-memory/576788/3

OpenAI Developer Forum

Welcome… To create a “memory” for your chatbot using the gpt-3.5-turbo model, you need to maintain the conversation history. This is done by including the past messages in the messages parameter every time you make a call to the API. Each message has two properties: role and content . The role can be ‘system’, ‘user’, or ‘assistant’, and conten...

timber smelt
#

@vague willow I did some digging and this where the initial answer comes from: https://community.openai.com/t/finetuned-gpt3-5-chatbot-memory/576788/2

So I am not sure if this a failure case? The forum reply is only 9 days old and marked as solution so it would be reasonable to assume from kapas perspective that it can use that answer.

I guess there is some added complexity given that this is the same post your are testing with? It is sort of an infinite loop

vague willow