Skip to content

Commit

Permalink
update message history system
Browse files Browse the repository at this point in the history
use a list instead of a dict like a fcking idiot... IDK WHY I DID IT THAT WAY IN THE FIRST PLACE...
  • Loading branch information
kytpbs committed Nov 5, 2023
1 parent 143f4ff commit d6dd5ba
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/GPT.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
from typing import OrderedDict
import discord

import openai
Expand All @@ -17,10 +16,9 @@
logging.critical("OPEN_AI_KEY is not set in .env file")

async def create_message_history(channel: discord.abc.Messageable, limit:int = 10):
message_history = OrderedDict()
message_history = []
async for message in channel.history(limit=limit):
if message.author not in message_history:
message_history[message.author] = message.content
message_history.append((message.author, message.content))
return message_history


Expand Down Expand Up @@ -54,14 +52,14 @@ def question(message: str, user_name: str = "MISSING", server_name: str = SERVER
logging.debug(f"{tokens} tokens used")
return answer

def chat(main_message: str, message_history: OrderedDict[discord.User, str]):
def chat(main_message: str, message_history: list[tuple[discord.User, str]]):
messages = [
{
"role": "system",
"content": f"You are a discord bot named '{BOT_NAME}' in a discord server named {SERVER_NAME}",
},
]
for user, message in message_history.items():
for user, message in message_history:
if user.bot:
messages.append({
"role": "assistant",
Expand Down

0 comments on commit d6dd5ba

Please sign in to comment.