Skip to main content

Open AI bot

This bot makes an API call to OpenAI and processes the user input. It uses GPT-3.5 Turbo.

from typing import List
from textbase import bot, Message
from textbase.models import OpenAI

# Load your OpenAI API key
OpenAI.api_key = ""

# Prompt for GPT-3.5 Turbo
SYSTEM_PROMPT = """You are chatting with an AI. There are no specific prefixes for responses, so you can ask or talk about anything you like.
The AI will respond in a natural, conversational manner. Feel free to start the conversation with any question or topic, and let's have a
pleasant chat!

def on_message(message_history: List[Message], state: dict = None):

# Generate GPT-3.5 Turbo response
bot_response = OpenAI.generate(
message_history=message_history, # Assuming history is the list of user messages

return {
"messages": [bot_response],
"state": state