Code Monkey home page Code Monkey logo

Comments (9)

snowby666 avatar snowby666 commented on June 6, 2024

Can you check if the tokens are valid. I set up a fastapi with multi clients and it worked fine for me

from poe-api-wrapper.

wingeva1986 avatar wingeva1986 commented on June 6, 2024

Can you check if the tokens are valid. I set up a fastapi with multi clients and it worked fine for me

yes,I tried,they are valid when just single client. and also valid status on quora.com

from poe-api-wrapper.

snowby666 avatar snowby666 commented on June 6, 2024

Thats weird. Here are my fastapi set up, hope it can help you:
api.py

from fastapi import FastAPI
from fastapi import WebSocket

from poe_api_wrapper import PoeApi

clients = {}
app = FastAPI()

@app.get("/")
def index():
    return {}

@app.websocket("/ws/{token}/{bot}/{message}")
async def send_message(websocket: WebSocket, token: str, bot: str, message: str):
    await websocket.accept()
    client = PoeApi(token)
    for chunk in client.send_message(bot=bot, message=message):
        await websocket.send_text(chunk['response'])

    await websocket.close(code=1000)

client.py

import websocket

class Client():
    def __init__(self, token, bot, message):
        self.token = token
        self.bot = bot
        self.message = message
        self.connect_to_websocket()
    
    def on_message(self, ws, message):
        print(message, end='', flush=True)

    def on_close(self, ws):
        print("WebSocket connection closed")

    def connect_to_websocket(self):
        self.message = self.message.replace(' ', '%20')
        ws = websocket.WebSocketApp(
            f'ws://127.0.0.1:8000/ws/{self.token}/{self.bot}/{self.message}',
            on_message=self.on_message,
            on_close=self.on_close
        )
        ws.run_forever()


# Example usage
client1 = Client("TOKEN_1", "a2", "Hello World")
client2 = Client("TOKEN_2", "a2", "Write a 500 word essay on Design Patterns")
client3 = Client("TOKEN_3", "chinchilla", "Write a simple snake game in Python")

Cmds:

uvicorn api:app --reload   

then

python client.py

from poe-api-wrapper.

snowby666 avatar snowby666 commented on June 6, 2024

Uhm I wonder whats inside this function?
get_client(token)

from poe-api-wrapper.

wingeva1986 avatar wingeva1986 commented on June 6, 2024

Uhm I wonder whats inside this function? get_client(token)

def get_client(token) -> PoeApi:
client_poe = PoeApi(token)
return client_poe

from poe-api-wrapper.

wingeva1986 avatar wingeva1986 commented on June 6, 2024

oh, the 2 tokens are invalid,but why?they seems valid on quora.com.

can u find out the reason?

from poe-api-wrapper.

snowby666 avatar snowby666 commented on June 6, 2024

Did you use different browser profiles for each client?
If no then the tokens should be unique for each browser profile.
Or you can try deleting the cookies and then login again

from poe-api-wrapper.

wingeva1986 avatar wingeva1986 commented on June 6, 2024

Did you use different browser profiles for each client? If no then the tokens should be unique for each browser profile. Or you can try deleting the cookies and then login again

oh,I think I found the reason, u must signin poe.com using the same email which registered on quora.com.

from poe-api-wrapper.

snowby666 avatar snowby666 commented on June 6, 2024

I think I will add this note to the document just in case

from poe-api-wrapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.