A simple API wrapper for Poe.com using Httpx
Project description
Table of Contents:
Highlights:
- Log in with your Quora's token
- Auto Proxy requests
- Get Chat Ids & Chat Codes of bot(s)
- Create new chat thread
- Send messages
- Stream bot responses
- Support file attachments
- Retrieve suggested replies
- Stop message generation
- Delete chat threads
- Clear conversation context
- Purge messages of 1 bot
- Purge all messages of user
- Create custom bot
- Edit custom bot
- Delete a custom bot
- Get available bots
- Explore 3rd party bots
- Support multi-chat threads
Installation:
- First, install this library with the following command:
pip3 install -U poe-api-wrapper
- You can run an example of this library:
from poe_api_wrapper import Poe
token = "TOKEN_HERE"
Poe.chat_with_bot(token)
Documentation:
Available Bots:
- Assistant (capybara)
- Claude-instant-100k (a2_100k)
- Claude-2-100k (a2_2)
- Claude-instant (a2)
- ChatGPT (chinchilla)
- ChatGPT-16k (agouti)
- GPT-4 (beaver)
- GPT-4-32k (vizcacha)
- Google-PaLM (acouchy)
- Llama-2-7b (llama_2_7b_chat)
- Llama-2-13b (llama_2_13b_chat)
- Llama-2-70b (llama_2_70b_chat)
- Code-Llama-7b (code_llama_7b_instruct)
- Code-Llama-13b (code_llama_13b_instruct)
- Code-Llama-34b (code_llama_34b_instruct)
How to get your Token:
Sign in at https://www.quora.com/
F12 for Devtools (Right-click + Inspect)
- Chromium: Devtools > Application > Cookies > quora.com
- Firefox: Devtools > Storage > Cookies
- Safari: Devtools > Storage > Cookies
Copy the value of m-b
cookie
Basic Usage:
- Connecting to the API
from poe_api_wrapper import PoeApi
client = PoeApi("TOKEN_HERE")
# Using Client with proxy (default is False)
client = PoeApi("TOKEN_HERE", proxy=True)
- Getting Chat Ids & Chat Codes
# Get chat ids of all bots
client.get_chat_history()
# Output:
# ------------------ Chat History ------------------
# Chat ID | Chat Code | Bot Name
# --------------------------------------------------
# 59727831 | 2i58aywsckpnm0v7wyl | chinchilla
# 59727472 | 2i58bw1nfv0aq7eab6i | chinchilla
# 59726162 | 2i58ciex72dom7im83r | a2
# 59726106 | 2i58campfdh1yn9us8i | a2
# 59726052 | 2i58d5x8am0untzhaxp | a2
# 59724775 | 2i588127auu1k5ilri9 | capybara
# 59724472 | 2i588hu98sfob7dfifx | capybara
# 59724127 | 2i586nb5jwhhvtr8gk4 | a2
# 59722624 | 2i58qnkisefkly649ml | a2
# 59719138 | 2i58xtl3nftynxnsxxi | capybara
# 59667229 | 2i5e3a7vvpbvt4nrif8 | a2
# 59673297 | 2i5gzkx1x2wicy1tzwr | a2
# 59680790 | 2i5hperhw2irsy351gn | capybara
# --------------------------------------------------
print(client.get_chat_history())
# Output:
# {'chinchilla': [{'chatId': 59727831, 'chatCode': '2i58aywsckpnm0v7wyl', 'id': 'Q2hhdDo1OTcyNzgzMQ=='}, {'chatId': 59727472, 'chatCode': '2i58bw1nfv0aq7eab6i', 'id': 'Q2hhdDo1OTcyNzQ3Mg=='}], 'a2': [{'chatId': 59726162, 'chatCode': '2i58ciex72dom7im83r', 'id': 'Q2hhdDo1OTcyNjE2Mg=='}, {'chatId': 59726106, 'chatCode': '2i58campfdh1yn9us8i', 'id': 'Q2hhdDo1OTcyNjEwNg=='}, {'chatId': 59726052, 'chatCode': '2i58d5x8am0untzhaxp', 'id': 'Q2hhdDo1OTcyNjA1Mg=='}, {'chatId': 59724127, 'chatCode': '2i586nb5jwhhvtr8gk4', 'id': 'Q2hhdDo1OTcyNDEyNw=='}, {'chatId': 59722624, 'chatCode': '2i58qnkisefkly649ml', 'id': 'Q2hhdDo1OTcyMjYyNA=='}, {'chatId': 59667229, 'chatCode': '2i5e3a7vvpbvt4nrif8', 'id': 'Q2hhdDo1OTY2NzIyOQ=='}, {'chatId': 59673297, 'chatCode': '2i5gzkx1x2wicy1tzwr', 'id': 'Q2hhdDo1OTY3MzI5Nw=='}], 'capybara': [{'chatId': 59724775, 'chatCode': '2i588127auu1k5ilri9', 'id': 'Q2hhdDo1OTcyNDc3NQ=='}, {'chatId': 59724472, 'chatCode': '2i588hu98sfob7dfifx', 'id': 'Q2hhdDo1OTcyNDQ3Mg=='}, {'chatId': 59719138, 'chatCode': '2i58xtl3nftynxnsxxi', 'id': 'Q2hhdDo1OTcxOTEzOA=='}, {'chatId': 59680790, 'chatCode': '2i5hperhw2irsy351gn', 'id': 'Q2hhdDo1OTY4MDc5MA=='}]}
# Get chat ids of a bot
print(client.get_chat_history("capybara"))
# Output:
# {'capybara': [{'chatId': 59724775, 'chatCode': '2i588127auu1k5ilri9', 'id': 'Q2hhdDo1OTcyNDc3NQ=='}, {'chatId': 59724472, 'chatCode': '2i588hu98sfob7dfifx', 'id': 'Q2hhdDo1OTcyNDQ3Mg=='}, {'chatId': 59719138, 'chatCode': '2i58xtl3nftynxnsxxi', 'id': 'Q2hhdDo1OTcxOTEzOA=='}, {'chatId': 59680790, 'chatCode': '2i5hperhw2irsy351gn', 'id': 'Q2hhdDo1OTY4MDc5MA=='}]}
- Sending messages & Streaming responses
bot = "a2"
message = "What is reverse engineering?"
# Create new chat thread
# Streamed example:
for chunk in client.send_message(bot, message):
print(chunk["response"], end="", flush=True)
print("\n")
# Non-streamed example:
for chunk in client.send_message(bot, message):
pass
print(chunk["text"])
# You can get chatCode and chatId of created thread to continue the conversation
chatCode = chunk["chatCode"]
chatId = chunk["chatId"]
# Send message to an existing chat thread
# 1. Using chatCode
for chunk in client.send_message(bot, message, chatCode="2i58ciex72dom7im83r"):
print(chunk["response"], end="", flush=True)
# 2. Using chatId
for chunk in client.send_message(bot, message, chatId=59726162):
print(chunk["response"], end="", flush=True)
Note Display names are the same as the codenames for custom bots, you can simply pass the bot's display name into
client.send_message(bot, message)
- Adding file attachments
# Web urls example:
file_urls = ["https://sweet.ua.pt/jpbarraca/course/er-2122/slides/er-1-intro_to_re.pdf",
"https://www.kcl.ac.uk/warstudies/assets/automation-and-artificial-intelligence.pdf"]
for chunk in client.send_message(bot, "Compare 2 files and describe them in 300 words", file_path=file_urls):
print(chunk["response"], end="", flush=True)
# Local paths example:
local_paths = ["c:\users\snowby666\hello_world.py"]
for chunk in client.send_message(bot, "What is this file about?", file_path=local_paths):
print(chunk["response"], end="", flush=True)
- Retrieving suggested replies
for chunk in client.send_message(bot, "Introduce 5 books about clean code", suggest_replies=True):
print(chunk["response"], end="", flush=True)
print("\n")
for reply in chunk["suggestedReplies"]:
print(reply)
- Stopping message generation
# You can use an event to trigger this function
# Example:
import keyboard
for chunk in client.send_message(bot, message):
print(chunk["response"], end="", flush=True)
# Press Q key to stop the generation
if keyboard.is_pressed('q'):
client.cancel_message(chunk)
print("\nMessage is now cancelled")
break
- Deleting chat threads
# Delete 1 chat
# Using chatCode
client.delete_chat(bot, chatCode="2i58ciex72dom7im83r")
# Using chatId
client.delete_chat(bot, chatID=59726162)
# Delete n chats
# Using chatCode
client.delete_chat(bot, chatCode=["LIST_OF_CHAT_CODES"])
# Using chatId
client.delete_chat(bot, chatId=["LIST_OF_CHAT_IDS"])
# Delete all chats of a bot
client.delete_chat(bot, del_all=True)
- Clearing conversation context
# 1. Using chatCode
client.chat_break(bot, chatCode="2i58ciex72dom7im83r")
# 2. Using chatId
client.chat_break(bot, chatId=59726162)
- Purging messages of 1 bot
You can pass the number of messages to be deleted into client.purge_conversation(bot, chatId, chatCode, count)
(the default is 50)
# 1. Using chatCode
client.purge_conversation(bot, chatCode="2i58ciex72dom7im83r", count=10)
# 2. Using chatId
client.purge_conversation(bot, chatId=59726162, count=10)
- Purging all messages of user
client.purge_all_conversations()
- Creating a new Bot
client.create_bot("BOT_NAME", "PROMPT_HERE", base_model="a2")
- Editing a Bot
client.edit_bot("(NEW)BOT_NAME", "PROMPT_HERE", base_model='chinchilla')
- Deleting a Bot
client.delete_bot("BOT_NAME")
- Getting available Bots
# Get a defined number of bots (default is 25)
print(client.get_available_bots(count=10))
# Get all available bots
print(client.get_available_bots(get_all=True))
- Exploring 3rd party bots
# Explore section example:
# Get a defined number of bots (default is 50)
print(client.explore_bots(count=10))
# Get all available bots
print(client.explore_bots(explore_all=True))
# Search section example:
# Get a defined number of bots (default is 50)
print(client.explore_bots(search="Midjourney", count=30))
# Get all available bots
print(client.explore_bots(search="Midjourney", explore_all=True))
Misc:
- How to find chatCode manually?
Here is an example, the chatCode is 2i5bego6rzetfsevv5g
- What are the file types that poe-api-wrapper support?
Currently, this API only supports these file types for adding attachments
.docx | .txt | .py | .js | .ts | .html | .css | .csv | .c | .cs | .cpp | |
---|---|---|---|---|---|---|---|---|---|---|---|
Copyright:
This program is licensed under the GNU GPL v3. All code has been written by me, snowby666.
Copyright Notice:
snowby666/poe-api-wrapper: A simple API wrapper for poe.com using Httpx
Copyright (C) 2023 snowby666
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for poe_api_wrapper-1.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2438ee7a49307a66a96826373d96322ac973fe5eba774b7c5b57028ef80f2d57 |
|
MD5 | d26cec07932b53f7b138f12f36fe3605 |
|
BLAKE2b-256 | 5ee18ab65f786973a30d031d4a2ed88fac3ebf79c43f4a44c0edfdfea7dc2b15 |