Add the possibility to get the number of remaining messages#46
Add the possibility to get the number of remaining messages#46ading2210 merged 3 commits intoading2210:mainfrom Snowad14:patch-1
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.
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
|
|
||
| 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.
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.
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
| return bot_names | ||
|
|
||
| def get_remaining_messages(self, chatbot): | ||
| chat_data = self.get_bot(chatbot) |
There was a problem hiding this comment.
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.
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