Skip to content

Commit

Permalink
discord: track actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Aug 23, 2023
1 parent d01ee8e commit ee8351a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions examples/discord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ async def close_thread(thread: discord.Thread):
async def on_ready():
print(f"We have logged in as {client.user}")

def diff(history, processed):
return [item for item in processed if item not in history]

def analyze_history(history, processed, callback, channel):
diff_list = diff(history, processed)
for item in diff_list:
if item["role"] == "function":
content = item["content"]
# Function result
callback(channel.send(f"⚙️ Processed: {content}"))
if item["role"] == "assistant" and "function_call" in item:
function_name = item["function_call"]["name"]
function_parameters = item["function_call"]["arguments"]
# Function call
callback(channel.send(f"⚙️ Called: {function_name} with {function_parameters}"))

def run_localagi_thread_history(history, message, thread, loop):
agent.channel = message.channel
def call(thing):
Expand All @@ -106,15 +122,15 @@ def reasoning_callback(name, reasoning):
)
# remove bot ID from the message content
message.content = message.content.replace(f"<@{client.user.id}>", "")

conversation_history = localagi.evaluate(
message.content,
history,
subtaskContext=True,
)

analyze_history(history, conversation_history, call, thread)
call(sent_message.edit(content=f"<@{user.id}> {conversation_history[-1]['content']}"))


def run_localagi_message(message, loop):
agent.channel = message.channel
def call(thing):
Expand Down Expand Up @@ -147,6 +163,7 @@ def reasoning_callback(name, reasoning):
[],
subtaskContext=True,
)
analyze_history([], conversation_history, call, message.channel)
call(sent_message.edit(content=f"<@{user.id}> {conversation_history[-1]['content']}"))

def run_localagi(interaction, prompt, loop):
Expand Down Expand Up @@ -201,6 +218,7 @@ def reasoning_callback(name, reasoning):
messages,
subtaskContext=True,
)
analyze_history(messages, conversation_history, call, interaction.channel)
call(sent_message.edit(content=f"<@{user.id}> {conversation_history[-1]['content']}"))

@client.tree.command()
Expand Down

0 comments on commit ee8351a

Please sign in to comment.