FineTuned GPT3.5 chatbot memory

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?

Hi Saif and welcome to the forum

LLMs today don’t have short-term memory other than what you pass to them in every single completion request. Simply put: you always need to send chat history (or its summary) as a part of messages.

2 Likes

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 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.

Hope you stick around. If you’ve got specific questions after you go over the docs and Quick Start guide, feel free to let us know. We’ve got a great developer community here.

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 (GitHub - openai/openai-python: The official Python library for the OpenAI API).

3 Likes