-
Notifications
You must be signed in to change notification settings - Fork 316
Add the possibility to get the number of remaining messages #46
Conversation
poe-api/src/poe.py
Outdated
def get_remaining_messages(self, chatbot): | ||
url = f'https://poe.com/_next/data/{self.next_data["buildId"]}/{chatbot}.json' | ||
limited_chatbots = ["GPT-4", "Claude+"] | ||
if chatbot in limited_chatbots: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to make the request manually when there's already a client.get_bot
function for this.
poe-api/src/poe.py
Outdated
@@ -147,6 +147,16 @@ def get_bot_names(self): | |||
bot_names[bot_nickname] = bot_obj["displayName"] | |||
return bot_names | |||
|
|||
def get_remaining_messages(self, chatbot): | |||
url = f'https://poe.com/_next/data/{self.next_data["buildId"]}/{chatbot}.json' | |||
limited_chatbots = ["GPT-4", "Claude+"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to hardcode the bot names, that'll just cause the function to break whenever Poe changes their bots.
poe-api/src/poe.py
Outdated
remaining_count = r.json()["pageProps"]["payload"]["chatOfBotDisplayName"]["defaultBotObject"]["messageLimit"]["numMessagesRemaining"] | ||
return remaining_count | ||
else: | ||
raise Exception(f"Chatbot {chatbot} is not limited or doesn't exist.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe don't raise an exception for if the chatbot doesn't have a limit. The numMessagesRemaining
value is present on all chatbots anyways, and it'll just be null
if there isn't a limit.
poe-api/src/poe.py
Outdated
@@ -147,6 +147,10 @@ def get_bot_names(self): | |||
bot_names[bot_nickname] = bot_obj["displayName"] | |||
return bot_names | |||
|
|||
def get_remaining_messages(self, chatbot): | |||
chat_data = self.get_bot(chatbot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.get_bot
takes the bot display name as an input, so you'd have to do self.get_bot(self.bot_names[chatbot])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to use the name "GPT-4" directly but it's true that using the official code names is better
I don't know if I implemented it the way you want but I personally needed it and maybe other people did too