Skip to main content

A reverse engineered API wrapper for Quora's Poe

Project description

Python Poe API

PyPi Version

This is a reverse engineered API wrapper for Quora's Poe, which allows you free access to OpenAI's ChatGPT and GPT-4, as well as Antropic's Claude.

Features:

  • Log in with token
  • Download bot list
  • Send messages
  • Stream bot responses
  • Clear conversation context
  • Download conversation history
  • Delete messages
  • Purge messages from conversation

Installation:

You can install this library by running the following command:

pip3 install poe-api

Documentation:

An example can be be found in /examples/example.py.

Using the Client:

To use this library, simply import poe and create a poe.Client instance, passing in your token as the only argument. You can find your token in the p-b field in your browser's cookies.

import poe
client = poe.Client("TOKEN_HERE")

Note that the following examples assume client is the name of your poe.Client instance.

Downloading the Available Bots:

The client downloads all of the available bots upon initialization and stores them within poe.Client.bots. A dictionary that maps bot codenames to their display names can be found at poe.Client.bot_names. If you want to refresh these values, you can call poe.Client.get_bots.

print(client.bot_names)
#{'capybara': 'Sage', 'beaver': 'GPT-4', 'a2_2': 'Claude+', 'a2': 'Claude', 'chinchilla': 'ChatGPT', 'nutria': 'Dragonfly'}

Sending Messages:

You can use the poe.Client.send_message function to send a message to a chatbot, which accepts the following arguments:

  • chatbot - The codename of the chatbot. (example: capybara)
  • message - The message to send to the chatbot.
  • with_chat_break = False - Whether the conversation context should be cleared.

The function is a generator which returns the most recent version of the generated message whenever it is updated.

Streamed Example:

message = "Summarize the GNU GPL v3"
for chunk in client.send_message("capybara", message):
  print(chunk["text_new"], end="", flush=True)

Non-Streamed Example:

message = "Summarize the GNU GPL v3"
for chunk in client.send_message("capybara", message):
  pass
print(chunk["text"])

Clearing the Conversation Context:

If you want to clear the the context of a conversation without sending a message, you can use client.send_chat_break. The only argument is the codename of the bot whose context will be cleared.

client.send_chat_break("capybara")

The function returns the message which represents the chat break.

Downloading Conversation History:

To download past messages in a conversation, use the client.get_message_history function, which accepts the following arguments:

  • chatbot - The codename of the chatbot.
  • count = 25 - The number of messages to download.
  • cursor = None - The message ID to start at instead of the latest one.
message_history = client.get_message_history("capybara", count=10)
print(json.dumps(message_history, indent=2))
"""
[
  {
    "node": {
      "id": "TWVzc2FnZToxMDEwNzYyODU=",
      "messageId": 101076285,
      "creationTime": 1679298157718888,
      "text": "",
      "author": "chat_break",
      "linkifiedText": "",
      "state": "complete",
      "suggestedReplies": [],
      "vote": null,
      "voteReason": null,
      "__typename": "Message"
    },
    "cursor": "101076285",
    "id": "TWVzc2FnZUVkZ2U6MTAxMDc2Mjg1OjEwMTA3NjI4NQ=="
  },
  ...
]
"""

Deleting Messages:

To delete messages, use the client.delete_message function, which accepts a single argument. You can pass a single message ID into it to delete a single message, or you can pass a list of message IDs to delete multiple messages at once.

Deleting a Single Message:

#delete a single message
client.delete(96105719)

#delete multiple messages at once
client.delete([96105719, 96097108, 96097078, 96084421, 96084402])

Purging a Conversation:

To purge an entire conversation, or just the last few messages, you can use the client.purge_messages function. This function accepts the following arguments:

  • chatbot - The codename of the chatbot.
  • count = None - The number of messages to be deleted, starting from the latest one. The default behavior is to delete every single message.
#purge just the last 10 messages
client.purge_conversation("capybara", count=10)

#purge the entire conversation
client.purge_conversation("capybara")

Misc:

Changing the Logging Level:

If you want to show debug messages, simply call poe.logger.setLevel.

import poe
poe.logger.setLevel(logging.INFO)

Setting a Custom User-Agent:

If you want to change the user-agent that is being spoofed, set poe.user_agent.

import poe
poe.user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"

Copyright:

This program is licensed under the GNU GPL v3. All code, with the exception of the GraphQL queries, has been written by me, ading2210.

Most of the GraphQL queries are taken from muharamdani/poe, which is licenced under the ISC License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

poe_api-0.1.0-py3-none-any.whl (28.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page