Git Product home page Git Product logo

Comments (6)

SlickTorpedo avatar SlickTorpedo commented on August 23, 2024

Please let me test to make sure the code works before closing the issue though. I've got this code but it's still not working.

def chatbot2_response(query):
    max_retries = 20
    for attempt in range(1, max_retries + 1):
        try:
            for chunk in poe_client.send_message("capybara", query, with_chat_break=True):
                yield chunk["text_new"]
            break
        except Exception as e:
            logging.warning(f"SendMessageMutation returned an error: {e} | Retrying ({attempt}/{max_retries})")
            time.sleep(1)  # Add a sleep time to avoid overloading the server
    else:
        logging.error("SendMessageMutation failed after maximum retries")

@app.route("/chatbot2", methods=['GET', 'POST'])
def chatbot2():
    chatbot_2_question = flask.request.form.get('question')
    return Response(stream_with_context(chatbot2_response(chatbot_2_question)), mimetype='text/plain')

Output is just:
WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (1/20)
WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (2/20)
WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (3/20)
and the page wont load

from poe-api.

SlickTorpedo avatar SlickTorpedo commented on August 23, 2024

If I put it inside like this it does not work either.

@app.route("/chatbot2", methods=['GET', 'POST'])
def chatbot2():
    chatbot_2_question = flask.request.form.get('question')
    def chatbot2_response(query):
        max_retries = 20
        for attempt in range(1, max_retries + 1):
            try:
                for chunk in poe_client.send_message("capybara", query, with_chat_break=True):
                    yield chunk["text_new"]
                break
            except Exception as e:
                logging.warning(f"SendMessageMutation returned an error: {e} | Retrying ({attempt}/{max_retries})")
                time.sleep(1)
        else:
            logging.error("SendMessageMutation failed after maximum retries")
    return Response(stream_with_context(chatbot2_response(chatbot_2_question)), mimetype='text/plain')

from poe-api.

SlickTorpedo avatar SlickTorpedo commented on August 23, 2024

I apologize if my question seemed invalid I am just looking to get some help.

from poe-api.

ading2210 avatar ading2210 commented on August 23, 2024

I've gotten this library to work with Flask just fine. client.send_message is just a normal python generator, so you'd just create a wrapper around it and return that.

Something like this should work (untested though):

@app.route("/send")
def send_message():
  prompt = request.query.get("prompt")
  def generator():
    for chunk in client.send_message("capybara", prompt):
      yield json.dumps(chunk)+"\n"
  return Response(generator(), content_type="text/event-stream")

from poe-api.

SlickTorpedo avatar SlickTorpedo commented on August 23, 2024

Nope :(

WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (1/20)
WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (2/20)
WARNING:root:SendMessageMutation returned an error: Server Error | Retrying (3/20)

def chatbot2():
    chatbot_2_question = flask.request.form.get('question')
    def generator():
        for chunk in poe_client.send_message("capybara", chatbot_2_question):
            yield json.dumps(chunk)+"\n"
    return Response(generator(), content_type="text/event-stream")`````

from poe-api.

mrdc avatar mrdc commented on August 23, 2024

Nope :(

Your issue is not poe-api related, but python/flask.

from poe-api.

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.