Package: poe-api-wrapper
Poe API WrapperA simple API wrapper for Poe.com using Httpx📚 Table of ContentsHighlightsInstallationDocumentationAvailable Default BotsHow to get your TokenBasic UsageBots Group Chat (beta)MiscContributingRun debugWays to contributeContributorsCopyrightCopyright Notice✨ HighlightsAuthenticationLog in with your Quora's token or Poe's tokenAuto Proxy requestsMessage AutomationCreate new chat threadSend messagesStream bot responsesRetry the last messageSupport file attachmentsRetrieve suggested repliesStop message generationDelete chat threadsClear conversation contextPurge messages of 1 botPurge all messages of userFetch previous messagesShare and import messagesChat ManagementGet Chat Ids & Chat Codes of bot(s)Bot ManagementCreate custom botEdit custom botDelete a custom botKnowledge Base Customization(New)Get available knowledge basesUpload knowledge bases for custom botsEdit knowledge bases for custom botsDiscoveryGet available botsGet a user's botsGet available categoriesExplore 3rd party bots and usersBots Group Chat(Beta)Create a group chatDelete a group chatGet created groupsGet group dataSave group chat historyLoad group chat history🔧 InstallationFirst, install this library with the following command:pip install -U poe-api-wrapperOr you can install a proxy-support version of this library forPython 3.9+pip install -U poe-api-wrapper[proxy]You can run an example of this library:frompoe_api_wrapperimportPoeExampletoken="TOKEN_HERE"PoeExample(token).chat_with_bot()🦄 DocumentationAvailable Default BotsDisplay NameModelToken LimitWordsAccess TypeAssistantcapybara4K3KClaude-instant-100ka2_100k100K75KClaude-2-100ka2_2100K75KClaude-instanta29K7KChatGPTchinchilla4K3KGPT-3.5-Turbogpt3_52k1.5KGPT-3.5-Turbo-Instructchinchilla_instruct2K1.5KChatGPT-16kagouti16K12KGPT-4beaver4K3KGPT-4-32kvizcacha32K24KGoogle-PaLMacouchy8K6KLlama-2-7bllama_2_7b_chat2K1.5KLlama-2-13bllama_2_13b_chat2K1.5KLlama-2-70bllama_2_70b_chat2K1.5KCode-Llama-7bcode_llama_7b_instruct4K3KCode-Llama-13bcode_llama_13b_instruct4K3KCode-Llama-34bcode_llama_34b_instruct4K3KSolar-Miniupstage_solar_0_70b_16bit2K1.5K[!IMPORTANT]The data on token limits and word counts listed above are approximate and may not be entirely accurate, as the pre-prompt engineering process of poe.com is private and not publicly disclosed.How to get your TokenPoe API Wrapper accepts both quora.com and poe.com tokens. Pick one that works best for you.Quora TokenSign in athttps://www.quora.com/F12 for Devtools (Right-click + Inspect)Chromium: Devtools > Application > Cookies > quora.comFirefox: Devtools > Storage > CookiesSafari: Devtools > Storage > CookiesCopy the value ofm-bcookiePoe TokenSign in athttps://poe.com/F12 for Devtools (Right-click + Inspect)Chromium: Devtools > Application > Cookies > poe.comFirefox: Devtools > Storage > CookiesSafari: Devtools > Storage > CookiesCopy the value ofp-bcookie[!NOTE]
Make sure you have logged in poe.com usingthe same emailwhich registered on quora.com.Basic UsageConnecting to the APIfrompoe_api_wrapperimportPoeApiclient=PoeApi("TOKEN_HERE")# Using Client with proxy (default is False)client=PoeApi("TOKEN_HERE",proxy=True)Getting Chat Ids & Chat Codes# Get chat data of all bots (this will fetch all available threads)print(client.get_chat_history()['data'])>>Output:{'chinchilla':[{'chatId':74397929,'chatCode':'2ith0h11zfyvsta1u3z','id':'Q2hhdDo3NDM5NzkyOQ==','title':'Comparison'}],'code_llama_7b_instruct':[{'chatId':74397392,'chatCode':'2ithbduzsysy3g178hb','id':'Q2hhdDo3NDM5NzM5Mg==','title':'Decent Programmers'}],'a2':[{'chatId':74396838,'chatCode':'2ith9nikybn4ksn51l8','id':'Q2hhdDo3NDM5NjgzOA==','title':'Reverse Engineering'},{'chatId':74396452,'chatCode':'2ith79n4x0p0p8w5yue','id':'Q2hhdDo3NDM5NjQ1Mg==','title':'Clean Code'}],'leocooks':[{'chatId':74396246,'chatCode':'2ith82wj0tjrggj46no','id':'Q2hhdDo3NDM5NjI0Ng==','title':'Pizza perfection'}],'capybara':[{'chatId':74396020,'chatCode':'2ith5o3p8c5ajkdwd3k','id':'Q2hhdDo3NDM5NjAyMA==','title':'Greeting'}]}# Get chat data of a bot (this will fetch all available threads)print(client.get_chat_history("a2")['data'])>>Output:{'a2':[{'chatId':74396838,'chatCode':'2ith9nikybn4ksn51l8','id':'Q2hhdDo3NDM5NjgzOA==','title':'Reverse Engineering'},{'chatId':74396452,'chatCode':'2ith79n4x0p0p8w5yue','id':'Q2hhdDo3NDM5NjQ1Mg==','title':'Clean Code'}]}# Get a defined number of most recent chat threads (using count param will ignore interval param)# Fetching all botsprint(client.get_chat_history(count=20)['data'])# Fetching 1 botprint(client.get_chat_history(bot="a2",count=20)['data'])# You can pass the number of bots fetched for each interval to both functions. (default is 50)# Fetching 200 chat threads of all bots each intervalprint(client.get_chat_history(interval=200)['data'])# Fetching 200 chat threads of a bot each intervalprint(client.get_chat_history(bot="a2",interval=200)['data'])# Pagination Example:# Fetch the first 20 chat threadshistory=client.get_chat_history(count=20)pages=[history['data']]new_cursor=history['cursor']# Set a while loop with a condition of your choicewhilenew_cursor!=None:# Fetch the next 20 chat threads with new_cursornew_history=client.get_chat_history(count=20,cursor=new_cursor)# Append the next 20 chat threadsnew_cursor=new_history['cursor']pages.append(new_history['data'])# Print the pages (20 chat threads each page)forpageinrange(len(pages)):print(f'This is page{page+1}')forbot,valueinpages[page].items():forthreadinvalue:print({bot:thread})Sending messages & Streaming responsesbot="a2"message="What is reverse engineering?"# Create new chat thread# Streamed example:forchunkinclient.send_message(bot,message):print(chunk["response"],end="",flush=True)print("\n")# Non-streamed example:forchunkinclient.send_message(bot,message):passprint(chunk["text"])# You can get chatCode and chatId of created thread to continue the conversationchatCode=chunk["chatCode"]chatId=chunk["chatId"]# You can get the meaningful title as welltitle=chunk["title"]# Send message to an existing chat thread# 1. Using chatCodeforchunkinclient.send_message(bot,message,chatCode="2i58ciex72dom7im83r"):print(chunk["response"],end="",flush=True)# 2. Using chatIdforchunkinclient.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 intoclient.send_message(bot, message)Retrying the last messageforchunkinclient.retry_message(chatCode):print(chunk['response'],end='',flush=True)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"]forchunkinclient.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"]forchunkinclient.send_message(bot,"What is this file about?",file_path=local_paths):print(chunk["response"],end="",flush=True)[!NOTE]
The files size limit is different for each model.Retrieving suggested repliesforchunkinclient.send_message(bot,"Introduce 5 books about clean code",suggest_replies=True):print(chunk["response"],end="",flush=True)print("\n")forreplyinchunk["suggestedReplies"]:print(reply)Stopping message generation# You can use an event to trigger this function# Example:# Note that keyboard library may not be compatible with MacOS, Linux, Ubuntuimportkeyboardforchunkinclient.send_message(bot,message):print(chunk["response"],end="",flush=True)# Press Q key to stop the generationifkeyboard.is_pressed('q'):client.cancel_message(chunk)print("\nMessage is now cancelled")breakDeleting chat threads# Delete 1 chat# Using chatCodeclient.delete_chat(bot,chatCode="2i58ciex72dom7im83r")# Using chatIdclient.delete_chat(bot,chatId=59726162)# Delete n chats# Using chatCodeclient.delete_chat(bot,chatCode=["LIST_OF_CHAT_CODES"])# Using chatIdclient.delete_chat(bot,chatId=["LIST_OF_CHAT_IDS"])# Delete all chats of a botclient.delete_chat(bot,del_all=True)Clearing conversation context# 1. Using chatCodeclient.chat_break(bot,chatCode="2i58ciex72dom7im83r")# 2. Using chatIdclient.chat_break(bot,chatId=59726162)Purging messages of 1 bot# Purge a defined number of messages (default is 50)# 1. Using chatCodeclient.purge_conversation(bot,chatCode="2i58ciex72dom7im83r",count=10)# 2. Using chatIdclient.purge_conversation(bot,chatId=59726162,count=10)# Purge all messsages of the thread# 1. Using chatCodeclient.purge_conversation(bot,chatCode="2i58ciex72dom7im83r",del_all=True)# 2. Using chatIdclient.purge_conversation(bot,chatId=59726162,del_all=True)Purging all messages of userclient.purge_all_conversations()Fetching previous messsages# Get a defined number of messages (default is 50)# Using chatCodeprevious_messages=client.get_previous_messages('code_llama_34b_instruct',chatCode='2itg2a7muygs42v1u0k',count=2)# Using chatIdprevious_messages=client.get_previous_messages('code_llama_34b_instruct',chatId=74411139,count=2)formessageinprevious_messages:print(message)>>Output:{'author':'human','text':'nice to meet you','messageId':2861709279}{'author':'code_llama_34b_instruct','text':" Nice to meet you too! How are you doing today? Is there anything on your mind that you'd like to talk about? I'm here to listen and help",'messageId':2861873125}# Get all previous messages# Using chatCodeprevious_messages=client.get_previous_messages('code_llama_34b_instruct',chatCode='2itg2a7muygs42v1u0k',get_all=True)# Using chatIdprevious_messages=client.get_previous_messages('code_llama_34b_instruct',chatId=74411139,get_all=True)formessageinprevious_messages:print(message)>>Output:{'author':'human','text':'hi there','messageId':2861363514}{'author':'code_llama_34b_instruct','text':" Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?",'messageId':2861363530}{'author':'chat_break','text':"",'messageId':2872383991}{'author':'human','text':'nice to meet you','messageId':2861709279}{'author':'code_llama_34b_instruct','text':" Nice to meet you too! How are you doing today? Is there anything on your mind that you'd like to talk about? I'm here to listen and help",'messageId':2861873125}[!NOTE]
It will fetch messages from the latest to the oldest, but the order to be displayed is reversed.Getting available knowledge basesprint(client.get_available_knowledge(botName="BOT_NAME"))>>Output:{'What is Quora?':[86698],'Founders of Quora':[86705]}Uploading knowledge bases# 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"]source_ids=client.upload_knowledge(file_path=file_urls)print(source_ids)>>Output:{'er-1-intro_to_re.pdf':[86344],'automation-and-artificial-intelligence.pdf':[86345]}# Local paths example:local_paths=["c:\\users\\snowby666\\hello_world.py"]source_ids=client.upload_knowledge(file_path=local_paths)print(source_ids)>>Output:{'hello_world.py':[86523]}# Plain texts example:knowledges=[{"title":"What is Quora?","content":"Quora is a popular online platform that enables users to ask questions on various topics and receive answers from a diverse community. It covers a wide range of subjects, from academic and professional queries to personal experiences and opinions, fostering knowledge-sharing and meaningful discussions among its users worldwide."},{"title":"Founders of Quora","content":"Quora was founded by two individuals, Adam D'Angelo and Charlie Cheever. Adam D'Angelo, who previously served as the Chief Technology Officer (CTO) at Facebook, and Charlie Cheever, a former Facebook employee as well, launched Quora in June 2009. They aimed to create a platform that would enable users to ask questions and receive high-quality answers from knowledgeable individuals. Since its inception, Quora has grown into a widely used question-and-answer platform with a large user base and a diverse range of topics covered."},]source_ids=client.upload_knowledge(text_knowledge=knowledges)print(source_ids)>>Output:{'What is Quora?':[86368],'Founders of Quora':[86369]}# Hybrid example:source_ids=client.upload_knowledge(file_path=file_urls,text_knowledge=knowledges)print(source_ids)>>Output:{'What is Quora?':[86381],'Founders of Quora':[86383],'er-1-intro_to_re.pdf':[86395],'automation-and-artificial-intelligence.pdf':[86396]}Editing knowledge bases (Only for plain texts)client.edit_knowledge(knowledgeSourceId=86381,title='What is Quora?',content='Quora is a question-and-answer platform where users can ask questions, provide answers, and engage in discussions on various topics.')Creating a new Botclient.create_bot("BOT_NAME","PROMPT_HERE",base_model="a2")# Using knowledge bases (you can use source_ids from uploaded knowledge bases for your custom bot)client.create_bot("BOT_NAME","PROMPT_HERE",base_model="a2",knowledgeSourceIds=source_ids,shouldCiteSources=True)Editing a Botclient.edit_bot("(NEW)BOT_NAME","PROMPT_HERE",base_model='chinchilla')# Adding knowledge basesclient.edit_bot("(NEW)BOT_NAME","PROMPT_HERE",base_model='chinchilla',knowledgeSourceIdsToAdd=source_ids,shouldCiteSources=True)# Removing knowledge basesclient.edit_bot("(NEW)BOT_NAME","PROMPT_HERE",base_model='chinchilla',knowledgeSourceIdsToRemove=source_ids,shouldCiteSources=True)[!TIP]
You can also use bothknowledgeSourceIdsToAddandknowledgeSourceIdsToRemoveat the same time.Deleting a Botclient.delete_bot("BOT_NAME")Getting available bots (your bots section)# Get a defined number of bots (default is 25)print(client.get_available_bots(count=10))# Get all available botsprint(client.get_available_bots(get_all=True))Getting a user's botshandle='poe'print(client.get_user_bots(user=handle))Getting available categoriesprint(client.get_available_categories())>>Output:['Official','Popular','New','ImageGen','AI','Professional','Funny','History','Cooking','Advice','Mind','Programming','Travel','Writing','Games','Learning','Roleplay','Utilities','Sports','Music']Exploring 3rd party bots and users# Explore section example:# Get a defined number of bots (default is 50)print(client.explore(count=10))# Get all available botsprint(client.explore(explore_all=True))# Search for bots by query example:# Get a defined number of bots (default is 50)print(client.explore(search="Midjourney",count=30))# Get all available botsprint(client.explore(search="Midjourney",explore_all=True))# Search for bots by category example (default is defaultCategory):# Get a defined number of bots (default is 50)print(client.explore(categoryName="Popular",count=30))# Get all available botsprint(client.explore(categoryName="AI",explore_all=True))# Search for people example:# Get a defined number of people (default is 50)print(client.explore(search="Poe",entity_type='user',count=30))# Get all available peopleprint(client.explore(search="Poe",entity_type='user',explore_all=True))Sharing & Importing messages# Share a defined number of messages (from the lastest to the oldest)# Using chatCodeshareCode=client.share_chat("a2",chatCode="2roap5g8nd7s28ul836",count=10)# Using chatIdshareCode=client.share_chat("a2",chatId=204052028,count=10)# Share all messages# Using chatCodeshareCode=client.share_chat("a2",chatCode="2roap5g8nd7s28ul836")# Using chatIdshareCode=client.share_chat("a2",chatId=204052028)# Set up the 2nd Client and import messages from the shareCodeclient2=PoeApi("2nd_TOKEN_HERE")print(client2.import_chat(bot,shareCode))>>Output:{'chatId':72929127,'chatCode':'2iw0xcem7a18wy1avd3'}Bots Group Chat (beta)Creating a group chatbots=[{'bot':'yayayayaeclaude','name':'Yae'},{'bot':'gepardL','name':'gepard'},{'bot':'SayukiTokihara','name':'Sayuki'}]client.create_group(group_name='Hangout',bots=bots)[!NOTE]botarg is the model/displayName.namearg is the one you'd mention them in group chat.Sending messages and Streaming responses in group chat# User engagement example:whileTrue:message=str(input('\n\033[38;5;121mYou :\033[0m'))prev_bot=""forchunkinclient.send_message_to_group(group_name='Hangout',message=message):ifchunk['bot']!=prev_bot:print(f"\n\033[38;5;121m{chunk['bot']}:\033[0m",end='',flush=True)prev_bot=chunk['bot']print(chunk['response'],end='',flush=True)print('\n')# Auto-play example:whileTrue:prev_bot=""forchunkinclient.send_message_to_group(group_name='Hangout',autoplay=True):ifchunk['bot']!=prev_bot:print(f"\n\033[38;5;121m{chunk['bot']}:\033[0m",end='',flush=True)prev_bot=chunk['bot']print(chunk['response'],end='',flush=True)print('\n')# Preset history example:preset_path="c:\\users\\snowby666\\preset.json"prev_bot=""forchunkinclient.send_message_to_group(group_name='Hangout',autoplay=True,preset_history=preset_path):ifchunk['bot']!=prev_bot:print(f"\n\033[38;5;121m{chunk['bot']}:\033[0m",end='',flush=True)prev_bot=chunk['bot']print(chunk['response'],end='',flush=True)print('\n')whileTrue:forchunkinclient.send_message_to_group(group_name='Hangout',autoplay=True):ifchunk['bot']!=prev_bot:print(f"\n\033[38;5;121m{chunk['bot']}:\033[0m",end='',flush=True)prev_bot=chunk['bot']print(chunk['response'],end='',flush=True)print('\n')[!NOTE]
You can also change your name in group chat by passing a new one to the above function:client.send_message_to_group('Hangout', message=message, user='Danny')If you want to auto save the conversation_log, just simply set this to true:client.send_message_to_group('Hangout', message=message, autosave=True)Deleting a group chatclient.delete_group(group_name='Hangout')Getting created groupsprint(client.get_available_groups())Getting group dataprint(client.get_group(group_name='Hangout'))Saving group chat history# Save as json in the same directoryclient.save_group_history(group_name='Hangout')# Save with a local path (json only)local_path="c:\\users\\snowby666\\log.json"client.save_group_history(group_name='Hangout',file_path=local_path)Loading group chat historyprint(client.load_group_history(file_path=local_path))MiscHow to find chatCode manually?Here is an example, the chatCode is 2i5bego6rzetfsevv5gWhat are the file types that poe-api-wrapper support?Currently, this API only supports these file types for adding attachments.pdf.docx.txt.md.py.js.ts.html.css.csv.c.cs.cpp.lua.rs.rb.go.java🙌 ContributingWe would love to develop poe-api-wrapper together with our community! 💕Run debugFirst, clone this repo:git clone https://github.com/snowby666/poe-api-wrapper.git
cd poe-api-wrapperThen run the test cases:python -m pip install -e .[tests]
toxWays to contributeTry poe-api-wrapper and give feedbackAdd new integrations with openPRHelp with openissuesorcreate your ownShare your thoughts and suggestions with usRequest a feature by submitting a proposalReport a bugImprove documentation:fix incomplete or missing docs, bad wording, examples or explanations.Contributors🤝 CopyrightThis program is licensed under theGNU GPL v3. Most code has been written by me,snowby666.Copyright Noticesnowby666/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/>.