From 42e4d0055155dada2db9c31df06a3238decf3328 Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Fri, 6 Jun 2025 19:19:57 -0700 Subject: [PATCH] Minor fixes --- bsky.py | 11 +++++++---- bsky_utils.py | 15 ++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bsky.py b/bsky.py index 076656d..86093f8 100644 --- a/bsky.py +++ b/bsky.py @@ -23,9 +23,10 @@ logging.basicConfig( logger = logging.getLogger("void_bot") -# Create a client +# Create a client with extended timeout for LLM operations CLIENT= Letta( - token=os.environ["LETTA_API_KEY"] + token=os.environ["LETTA_API_KEY"], + timeout=300 # 5 minutes timeout for API calls ) # Use the "Bluesky" project @@ -110,6 +111,8 @@ def process_mention(void_agent, atproto_client, notification_data): # Get thread context as YAML string thread_context = thread_to_yaml_string(thread) + print(thread_context) + # Create a prompt for the Letta agent with thread context prompt = f"""You received a mention on Bluesky from @{author_handle} ({author_name or author_handle}). @@ -183,8 +186,8 @@ Use the bluesky_reply tool to send a response less than 300 characters.""" logger.error(f"Failed to send reply to @{author_handle}") return False else: - logger.warning(f"No reply generated for mention from @{author_handle}") - return False + logger.warning(f"No reply generated for mention from @{author_handle}, removing notification from queue") + return True except Exception as e: logger.error(f"Error processing mention: {e}") diff --git a/bsky_utils.py b/bsky_utils.py index 80a768c..9a178d3 100644 --- a/bsky_utils.py +++ b/bsky_utils.py @@ -33,7 +33,6 @@ STRIP_FIELDS = [ "tags", "associated", "thread_context", - "image", "aspect_ratio", "thumb", "fullsize", @@ -59,8 +58,10 @@ STRIP_FIELDS = [ "muted", "muted_by_list", "root_author_like", - "embed", "entities", + "ref", + "mime_type", + "size", ] def convert_to_basic_types(obj): """Convert complex Python objects to basic types for JSON/YAML serialization.""" @@ -116,23 +117,23 @@ def strip_fields(obj, strip_field_list): def thread_to_yaml_string(thread, strip_metadata=True): """ Convert thread data to a YAML-formatted string for LLM parsing. - + Args: thread: The thread data from get_post_thread strip_metadata: Whether to strip metadata fields for cleaner output - + Returns: YAML-formatted string representation of the thread """ # First convert complex objects to basic types basic_thread = convert_to_basic_types(thread) - + if strip_metadata: # Create a copy and strip unwanted fields cleaned_thread = strip_fields(basic_thread, STRIP_FIELDS) else: cleaned_thread = basic_thread - + return yaml.dump(cleaned_thread, indent=2, allow_unicode=True, default_flow_style=False) @@ -279,7 +280,7 @@ def reply_to_notification(client: Client, notification: Any, reply_text: str) -> else: post_uri = None post_cid = None - + if not post_uri or not post_cid: logger.error("Notification doesn't have required uri/cid fields") return None -- 2.51.2