fixed bug not checking status in answer_question

added sparky name to end of prompt to stop it from writing its name
This commit is contained in:
phixxy 2024-03-19 22:51:39 -07:00
parent edf5cf2763
commit d2f0026c76

View file

@ -212,6 +212,9 @@ class ChatGPT(commands.Cog):
try: try:
async with self.http_session.post(url, json=data, headers=self.headers) as resp: async with self.http_session.post(url, json=data, headers=self.headers) as resp:
response_data = await resp.json() response_data = await resp.json()
if resp.status != 200:
self.logger.error(f"Error occurred in answer_question: {response_data}")
return "Error occurred in answer_question"
response = response_data['choices'][0]['message']['content'] response = response_data['choices'][0]['message']['content']
input_tokens = response_data['usage']['prompt_tokens'] input_tokens = response_data['usage']['prompt_tokens']
output_tokens = response_data['usage']['completion_tokens'] output_tokens = response_data['usage']['completion_tokens']
@ -526,7 +529,7 @@ class ChatGPT(commands.Cog):
async def chat_response(self, ctx, channel_vars, chat_history_string): async def chat_response(self, ctx, channel_vars, chat_history_string):
async with ctx.channel.typing(): async with ctx.channel.typing():
await asyncio.sleep(1) await asyncio.sleep(1)
prompt = f"You are a {channel_vars['personality']} chat bot named Sparkytron 3000 created by @phixxy.com. Your personality should be {channel_vars['personality']}. You are currently in a {channel_vars['channel_topic']} chatroom. The message history is: {chat_history_string}" prompt = f"You are a {channel_vars['personality']} chat bot named Sparkytron 3000 created by @phixxy.com. Your personality should be {channel_vars['personality']}. You are currently in a {channel_vars['channel_topic']} chatroom. The message history is: {chat_history_string}\nSparkytron 3000: "
response = await self.answer_question(prompt) response = await self.answer_question(prompt)
if "Sparkytron 3000:" in response[0:17]: if "Sparkytron 3000:" in response[0:17]:
response = response.replace("Sparkytron 3000:", "") response = response.replace("Sparkytron 3000:", "")