rgbkrk / genai

What if GPT could help you notebook?
BSD 3-Clause "New" or "Revised" License
354 stars 37 forks source link

Consider a feedback loop #5

Closed rgbkrk closed 1 year ago

rgbkrk commented 1 year ago

For suggestions, we could use input to do back & forth between the user and ChatGPT.

# Assume messages is all the messages we sent prior as well as "assistant responses"
messages.append(completion["choices"][0]["message"])

user_input = input("chat> ")

while user_input is not "":
    user_message = {"role": "user", "content": user_input}
    messages.append(user_message)

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

    assistant_message = completion["choices"][0]["message"]
    messages.append(assistant_message)

    display(
        {
            "text/plain": assistant_message["content"],
            "text/markdown": assistant_message["content"],
        },
        raw=True,
    )

    user_input = input("chat> ")

It's not the best user experience. However, it'll work across all the jupyter platforms, even ipython at the command line.