Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Add the possibility to get the number of remaining messages #46

Merged
merged 3 commits into from
Apr 16, 2023
Merged

Add the possibility to get the number of remaining messages #46

merged 3 commits into from
Apr 16, 2023

Conversation

Snowad14
Copy link
Contributor

I don't know if I implemented it the way you want but I personally needed it and maybe other people did too

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:
Copy link
Owner

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.

@@ -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+"]
Copy link
Owner

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.

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.")
Copy link
Owner

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.

@@ -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)
Copy link
Owner

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])

Copy link
Contributor Author

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

@ading2210 ading2210 merged commit eb4125a into ading2210:main Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants