import os from openai import OpenAI class ChatBot: def __init__(self, protocol: str = "You are a helpful assistant.", conversation: list[dict]): self.client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) self.protocol = protocol self.conversation = conversation self.history = [{"role": "system", "content": self.protocol}] + self.conversation def generate_response(self, prompt: str) -> str: self.history.append({"role": "user", "content": prompt}) completion = self.client.chat.completions.create( model="gpt-3.5-turbo", # NOTE: feel free to change it to gpt-4, or gpt-4o messages=self.history ) response = completion.choices[0].message.content self.history.append({"role": "assistant", "content": response}) return response def get_history(self) -> list: return self.history