I currently very confused; I was running a code that was working fine and now it is not. I am getting the error message that “context” is not defined. I will post the code below.
class CreateBot:
def __init__(self, system_prompt):
self.system = system_prompt
self.messages = [{"role": "system", "content": system_prompt}]
def chat(self):
print('To terminate conversation type in END')
#USER INPUT
question = ''
while question != "END":
question = input("")
df = pd.read_csv('results-2024-05-27T181109.csv')
context = df.nlargest(1,'score').iloc[0]['text']
print('n')
#ADD TO THE MESSAGES LIST OF DICT
self.messages.append({"role":"user","content":question})
#GRAB RESPONSE FROM CHATGPT
response = client.chat.completions.create(model = 'ft:gpt-3.5-turbo-0125:ai-lean::9TvnXq0q',
messages = self.messages)
#GRAB ASSISTANT MESSAGES (CONTENT)
content = response.choices[0].message.content
audio = client.audio.speech.create(
model = "tts-1",
voice = "alloy",
input = content)
audio.stream_to_file("tester.mp3")
print('n')
print(content)
print('n')
mixer.init()
mixer.music.load('tester.mp3')
mixer.music.play()
self.messages.append({"role":"assistant","content":content})
Then I go like this:
new_bot = CreateBot(system_prompt = f’You are an assistant that is extremely enthusiastic and loves to talk about pizza. You bring up pizza constantly and rely on the {context} to answer the question’)
This is when I get the error message (while trying to use context as part of the system prompt in an f-string), that context is not defined. I am very confused about how to work around this, especially because it was working earlier (and I don’t believe I changed anything!?) Any help would be very very much appreciated! Thank you!
I have tried moving the df and context variables around, but am pretty stuck.