added help to identify emotes by name

This commit is contained in:
jenz 2026-03-13 19:33:56 +01:00
parent abffb94069
commit 091c0fb73a

View File

@ -1,6 +1,6 @@
#!/home/nonroot/stoat_retarded_ai_tree/venv/bin/python3
from settings import stoat_url, stoat_token, stoat_url_get_last_message, claude_api_key, replicate_api_key
from settings import stoat_url, stoat_token, stoat_url_get_last_message, claude_api_key, replicate_api_key, stoat_server_emotes
import requests
import time
import base64
@ -10,6 +10,15 @@ import replicate as replicate_client
from PIL import Image
import io
def get_custom_emotes():
headers = {
"x-bot-token": f"{stoat_token}",
"Content-Type": "application/json"
}
r = requests.get(stoat_server_emotes, headers=headers)
js = r.json()
return js
def send_post_message_to_stoat(claude_response, fileContent, sleep_seconds):
message = claude_response["message"]
metrics = claude_response["metrics"]
@ -78,7 +87,7 @@ def check_if_emote_reacted():
def is_custom_emote(emote_key):
return emote_key.isascii() and emote_key.isalnum()
def send_claude_message(reacted_emote, metrics):
def send_claude_message(reacted_emote, metrics, custom_emotes_json):
if is_custom_emote(reacted_emote):
img_response = requests.get("https://stoat.unloze.com/autumn/emojis/" + reacted_emote)
img_data = img_response.content
@ -97,6 +106,13 @@ def send_claude_message(reacted_emote, metrics):
img_base64 = base64.b64encode(img_data).decode("utf-8")
emote_name = ""
for custom_emote_js in custom_emotes_json:
if custom_emote_js['_id'] == reacted_emote:
emote_name = custom_emote_js['name']
print('found emote name: ', emote_name)
break
response = requests.post(
"https://api.anthropic.com/v1/messages",
headers={
@ -122,7 +138,7 @@ def send_claude_message(reacted_emote, metrics):
},
{
"type": "text",
"text": f"Current metrics: {metrics}\nWhat does this emote do to the tree?"
"text": f"Current metrics: {metrics}\nCustom emote name (use this as a hint to identify the emote, ignore if empty): '{emote_name}'.\nDescribe what you see in the image, then decide what it does to the tree."
}
]
}
@ -165,11 +181,12 @@ def replicate_fetch_image(image_prompt):
return output[0].read()
def main():
custom_emotes_json = get_custom_emotes()
while True:
reacted_emote, metrics = check_if_emote_reacted()
print(reacted_emote, metrics)
if reacted_emote:
claude_response = send_claude_message(reacted_emote, metrics)
claude_response = send_claude_message(reacted_emote, metrics, custom_emotes_json)
replicate_image_response = replicate_fetch_image(claude_response["image_prompt"])
sleep_seconds = claude_response.get("sleep_seconds", 30)