forked from myreader-io/myGPTReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e61969a
commit 84f02c9
Showing
4 changed files
with
137 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import requests | ||
|
||
CF_ACCESS_CLIENT_ID = os.environ.get('CF_ACCESS_CLIENT_ID') | ||
CF_ACCESS_CLIENT_SECRET = os.environ.get('CF_ACCESS_CLIENT_SECRET') | ||
|
||
def update_message_token_usage(user_id, message_id, message_type, llm_token_usage=0, embedding_token_usage=0) -> bool: | ||
endpoint_url = "https://api.myreader.io/api/message" | ||
headers = { | ||
'CF-Access-Client-Id': CF_ACCESS_CLIENT_ID, | ||
'CF-Access-Client-Secret': CF_ACCESS_CLIENT_SECRET, | ||
} | ||
data = { | ||
'user': { | ||
"user_from": "slack", | ||
"user_platform_id": user_id | ||
}, | ||
"message": { | ||
"message_platform_id": message_id, | ||
"message_type": message_type, | ||
"llm_token_usage": llm_token_usage, | ||
"embedding_token_usage": embedding_token_usage | ||
} | ||
} | ||
response = requests.post(endpoint_url, headers=headers, data=data) | ||
if response.status_code == 200: | ||
try: | ||
json_response = response.json() | ||
if 'error' in json_response: | ||
return False | ||
return True | ||
except: | ||
return "Error: Unable to parse JSON response" | ||
else: | ||
return f"Error: {response.status_code} - {response.reason}" | ||
|
||
def get_user(user_id): | ||
endpoint_url = f"https://api.myreader.io/api/user/slack/{user_id}" | ||
headers = { | ||
'CF-Access-Client-Id': CF_ACCESS_CLIENT_ID, | ||
'CF-Access-Client-Secret': CF_ACCESS_CLIENT_SECRET, | ||
} | ||
response = requests.get(endpoint_url, headers=headers) | ||
if response.status_code == 200: | ||
try: | ||
json_response = response.json() | ||
if 'error' in json_response: | ||
return None | ||
return json_response | ||
except: | ||
return "Error: Unable to parse JSON response" | ||
else: | ||
return f"Error: {response.status_code} - {response.reason}" |