Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,61 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_bluesky_post(handle:str)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""Fetches the most recent post from a Bluesky account.
|
| 15 |
Args:
|
| 16 |
+
The Bluesky handle without the domain (e.g., 'beccalewy')
|
| 17 |
+
Returns:
|
| 18 |
+
A string containing the most recent post content or an error message
|
| 19 |
"""
|
| 20 |
+
import requests
|
| 21 |
+
|
| 22 |
+
# Format handle properly
|
| 23 |
+
if not "." in handle:
|
| 24 |
+
full_handle = f"{handle}.bsky.social"
|
| 25 |
+
else:
|
| 26 |
+
full_handle = handle
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
# Step 1: Get the user's DID
|
| 30 |
+
profile_url = "https://bsky.social/xrpc/app.bsky.actor.getProfile"
|
| 31 |
+
profile_response = requests.get(profile_url, params={"actor": full_handle})
|
| 32 |
+
profile_response.raise_for_status()
|
| 33 |
+
profile_data = profile_response.json()
|
| 34 |
+
|
| 35 |
+
user_did = profile_data.get("did")
|
| 36 |
+
display_name = profile_data.get("displayName", full_handle)
|
| 37 |
+
|
| 38 |
+
if not user_did:
|
| 39 |
+
return f"Could not find a Bluesky account for @{handle}"
|
| 40 |
+
|
| 41 |
+
# Step 2: Get the most recent post
|
| 42 |
+
feed_url = "https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed"
|
| 43 |
+
feed_response = requests.get(feed_url, params={"actor": user_did, "limit": 1})
|
| 44 |
+
feed_response.raise_for_status()
|
| 45 |
+
feed_data = feed_response.json()
|
| 46 |
+
|
| 47 |
+
# Check if there are any posts
|
| 48 |
+
if not feed_data.get("feed") or len(feed_data["feed"]) == 0:
|
| 49 |
+
return f"@{handle} has no posts on Bluesky"
|
| 50 |
+
|
| 51 |
+
# Extract post information
|
| 52 |
+
latest_post = feed_data["feed"][0]["post"]
|
| 53 |
+
post_text = latest_post["record"]["text"]
|
| 54 |
+
post_time = latest_post["record"]["createdAt"]
|
| 55 |
+
|
| 56 |
+
# Format the result for the AI agent
|
| 57 |
+
result = f"{display_name} (@{handle}) posted on {post_time}:\n\"{post_text}\""
|
| 58 |
+
return result
|
| 59 |
+
|
| 60 |
+
except requests.exceptions.HTTPError as e:
|
| 61 |
+
if e.response.status_code == 404:
|
| 62 |
+
return f"No Bluesky account found for @{handle}"
|
| 63 |
+
else:
|
| 64 |
+
return f"HTTP error when accessing Bluesky API: {e}"
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return f"Error fetching Bluesky post: {e}"
|
| 67 |
|
| 68 |
@tool
|
| 69 |
def get_current_time_in_timezone(timezone: str) -> str:
|