Chris4K commited on
Commit
1b32152
·
verified ·
1 Parent(s): 2054366

Rename text_download.py to push_notification.py

Browse files
Files changed (2) hide show
  1. push_notification.py +57 -0
  2. text_download.py +0 -21
push_notification.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from exponent_server_sdk import (
2
+ DeviceNotRegisteredError,
3
+ PushClient,
4
+ PushMessage,
5
+ PushServerError,
6
+ PushTicketError,
7
+ )
8
+ import os
9
+
10
+ from transformers.tools.base import Tool
11
+
12
+ # Description for the tool
13
+ PUSH_NOTIFICATION_DESCRIPTION = (
14
+ "This is a tool that sends a push notification using Expo. It takes two inputs: "
15
+ "`token`, which is the Expo push token of the recipient, and `message`, which is the "
16
+ "message to send. It does not return any output."
17
+ )
18
+
19
+ class PushNotificationTool(Tool):
20
+ description = PUSH_NOTIFICATION_DESCRIPTION
21
+ name = "push_notification"
22
+ inputs = ["token", "message"]
23
+ outputs = []
24
+
25
+ def __call__(self, token, message):
26
+ try:
27
+ # Replace 'your_expo_token' with your actual Expo push notification token
28
+ response = PushClient().publish(
29
+ PushMessage(to=token, body=message)
30
+ )
31
+ except PushServerError as exc:
32
+ # Encountered some likely formatting/validation error.
33
+ print(f"Error: {exc.errors}")
34
+ raise
35
+ except DeviceNotRegisteredError:
36
+ # Mark the push token as inactive
37
+ print("Device not registered.")
38
+ # Add logic to handle inactive push token in your application
39
+ except PushTicketError as exc:
40
+ # Encountered some other per-notification error.
41
+ print(f"Push ticket error: {exc.push_response._asdict()}")
42
+ raise
43
+
44
+ try:
45
+ # We got a response back, but we don't know whether it's an error yet.
46
+ # This call raises errors so we can handle them with normal exception flows.
47
+ response.validate_response()
48
+ except DeviceNotRegisteredError:
49
+ # Mark the push token as inactive
50
+ print("Device not registered.")
51
+ # Add logic to handle inactive push token in your application
52
+ except PushTicketError as exc:
53
+ # Encountered some other per-notification error.
54
+ print(f"Push ticket error: {exc.push_response._asdict()}")
55
+ raise
56
+
57
+ return None # No output is expected
text_download.py DELETED
@@ -1,21 +0,0 @@
1
- import requests
2
- from bs4 import BeautifulSoup
3
-
4
- from transformers.tools.base import Tool
5
-
6
-
7
- TEXT_DOWNLOAD_DESCRIPTION = (
8
- "This is a tool that downloads a file from a `url`. It takes the `url` as input, and returns the text"
9
- " contained in the file."
10
- )
11
-
12
-
13
- class TextDownloadTool(Tool):
14
-
15
- inputs = ['text']
16
- outputs = ['text']
17
- description = TEXT_DOWNLOAD_DESCRIPTION
18
-
19
- def __call__(self, url):
20
- return BeautifulSoup(requests.get(url).text, features="html.parser").get_text()
21
-