Skip to content

Is it possible to make the chatbot remember the previous chat? #1921

Answered by DarkOperation
SuhaoCoding asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible. For example, [{"role":"user","content":"hi"},{"role":"assistant","content":"Hello there! How can I assist you today?"},{"role":"user","content":"who are u?"}] is mean, what user sent to model message with conent hi, model sent to user message with content Hello there! How can I assist you today? and user sent to model message with content who are u?.

Here is example:

from g4f.client import Client

client = Client()
messages = []
while True:
    messages.append({"role": "user", "content": input("Enter message to ChatGPT: ")})
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=messages,
    )
    messages.append({"role": "assi…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@SuhaoCoding
Comment options

Answer selected by SuhaoCoding
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants