Skip to content

Commit

Permalink
Merge pull request #2 from Pingdred/dev
Browse files Browse the repository at this point in the history
0.0.3
  • Loading branch information
Pingdred authored May 9, 2024
2 parents bdf3974 + 1d336d7 commit 95fb38f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 50 deletions.
58 changes: 10 additions & 48 deletions meowgram_connect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
from typing import Dict

from cat.log import log

from cat.mad_hatter.mad_hatter import MadHatter
from cat.mad_hatter.decorators import hook

Expand All @@ -22,28 +20,20 @@ def get_name(telegram_update):
return None

@hook
def before_agent_starts(agent_input: Dict, cat) -> Dict:

user_message = cat.working_memory["user_message_json"]
def after_cat_recalls_memories(cat) -> Dict:

user_message = cat.working_memory.user_message_json
# This key exist only if the message is from Meowgram
# if not exists we don't need to do anything
if "meowgram" not in user_message.keys():
return

# Get the name from the telegram update
telegram_update = json.loads(user_message["meowgram"]["update"])
name = get_name(telegram_update)

name = get_name(telegram_update)

log.critical(f"BEFORE: {name}, {not name}")

if name is None:
log.critical("NO")
return

agent_input["chat_history"] = agent_input["chat_history"].replace("- Human:", f"- {name}:")

return agent_input
# Update name in chat history
cat.working_memory.history[-1]["who"] = name


@hook
Expand All @@ -60,42 +50,14 @@ def before_cat_sends_message(message, cat):

message["meowgram"] = {
"send_params": {},
"settings": {},
}

send_params = message["meowgram"]["send_params"]
meowgram_settings = message["meowgram"]["settings"]

if settings["reply_to"]:
send_params["reply_to_message_id"] = telegram_update["message"]["message_id"]

return message


@hook
def agent_prompt_suffix(suffix, cat):
user_message = cat.working_memory["user_message_json"]

# This key exist only if the message is from Meowgram
# if not exists we don't need to do anything
if "meowgram" not in user_message.keys():
return

telegram_update = json.loads(user_message["meowgram"]["update"])

name = get_name(telegram_update)

if name is None:
return

suffix = f"""
# Context
{{episodic_memory}}
{{declarative_memory}}
{{tools_output}}
## Conversation until now:{{chat_history}}
- {name}: {{input}}
- AI: """

return suffix
meowgram_settings["show_tts_text"] = settings["show_tts_text"]


return message
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "Meowgram Connect",
"version": "0.0.2",
"version": "0.0.3",
"description": "Supercharge your Meowgram client with the Meowgram Connect plugin, enabling smooth integration with the Cheshire Cat framework.",
"author_name": "Emanuele Morrone",
"author_url": "https://www.linkedin.com/in/emanuele-morrone-25537423b/",
"plugin_url": "https://github.com/Pingdred/meowgram-connect",
"tags": "Telegram, client, integration",
"tags": "Telegram, meowgram client",
"thumb": "https://raw.githubusercontent.com/Pingdred/Meowgram/main/logo.png"
}
5 changes: 5 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class MeogramConnectSettings(BaseModel):
description="The Cheshire cat will quote the message it is responding to",
default=True
)
show_tts_text: bool = Field(
title="Show Voice Note Transciption",
description="Show transcript when the message is a voice note",
default=True
)


@plugin
Expand Down

0 comments on commit 95fb38f

Please sign in to comment.