Whenever I run this code, I get an error that says “Object of type Message is not JSON serializable”. The code is supposed to create a chatbot to the local host. There is an API key involved and this code is based off of a tutorial video.
import chainlit as cl
import openai
import os
os.environ['OPENAI_API_KEY'] = 'random API key'
openai.api_key = 'random API key'
@cl.on_message
async def main(message : str):
response = openai.ChatCompletion.create(
model = 'gpt-4-1106-preview',
messages = [
{"role": "assistant", "content": "you are an assistant that is obsessed with legos"},
{"role": "user", "content":message}
],
temperature = 1,
)
await cl.Message(content =f" {response['choices'][0]['message']['content']}",).send()
I tried importing JSON and such, but that didn’t work. I am trying to get the chatbot to reply to the user with a message. However, I still ended up getting the same error message as previously stated.