Gpt-4o-mini not remembering past answers

I am attaching an api to my webpage, it is supposed to be an AI that will help people find services, but the API does not remember any prior messages sent by the user. Also I wanted to use an assistant from the dashboard that I created but I am not sure how to deploy the assistant, cause the instructions I find are unclear.

from openai import OpenAI
from flask import Flask, request, jsonify, render_template

client = OpenAI(my API key)
app = Flask(__name__)
prompt = "my prompt"

@app.route('/')
def index():
    return render_template('depthnav_trial.html')


@app.route('/', methods=['POST'])
def chat():
    data = request.get_json()
    message = data.get('message')
    

    response = chat_client.chat.completions.create(
        
        model="gpt-4o",
        messages=[
            {"role": "system", "content": prompt},
            {"role": "user", "content": message}
        ],
        max_tokens=50
    )

    return jsonify({'reply': response.choices[0].message.content.strip()})

if __name__ == '__main__':
    app.run(port=5000, debug=True)

Hey @kahmed23 - Welcome to the forums!

This right here is an example of chat completions. Single request and response; you are not storing conversations as context to retrieve. I would highly suggest you take a look and use OpenAI Assistants API to achieve what you are looking for. Take a look at my previous post to get started with implementation.

2 Likes

Thanks I figured out how to store using completions. I understand it’s pretty horrible for time because it takes a minute to load sometimes but it works for what I am using it for. I just used sessions. I may upgrade to the assistants API in the future but this is my first coding project and it is working decently. Thank you for your help though I really appreciate it.

1 Like