Git Product home page Git Product logo

quizgptservice's Introduction

Quick flask guide

Prerequisites

  • Sign up for OpenAI and get your secret key. This is rotated periodically so needs to be updated.
  • Recommended to instead use a Python virtual environment. Download the following dependencies with requirements.txt instead. Else:
  • Install Python
  • Install Flask pip install Flask
  • Install RabbitMQ pip install pika
  • Install OpenAI pip install requests
  • Install dotenv to enable Environment Variables pip install python-dotenv

How to Run

To run the application, use the flask command or python -m flask. You need to tell the Flask where your application is with the --app option.

  1. Create .env file (ask Pan for credentials) (OpenAI console):
OPENAI_SECRET_KEY="Get your own from the OpenAI console"
RABBITMQ_HOSTNAME='Ask Pan'
RABBITMQ_USER='Ask Pan'
RABBITMQ_PORT='5672'
RABBITMQ_PASSWORD='Ask Pan'
RABBITMQ_PREFIX='amqps://'
ENVIRONMENT='prod'
SENDER="Ask Pan"
  1. Run RabbitMQ locally: docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.11-management
  2. flask --app app.py run (py -m flask --app app.py run)
    • To run in debug mode (automatic changes): py -m flask --app app run --debug
  3. Go to root of localhost site to start the RabbitMQ connection (http://127.0.0.1:5000)

RabbitMQ dashboard to manage messages:


Deployment

Python Flask App

Flask==1.1.4
MarkupSafe==2.0.1

------- PYTHONANYWHERE DOESN'T WORK WITH NON-PUBLIC APIs -> Use the Vercel deployed URL.

RabbitMQ

RabbitMQ message formats:

Receiving message format:

  • number: number of questions to generate
  • text: text to generate questions from
  • id: unique identifier for quiz
  • sender: has to be an allowed sender

Sending message format:

  • id: unique identifier for quiz
  • number: number of questions generated
  • results: list of question-answer pairs
  • sender: has to be an allowed sender

E.g.:

{
    "id": 1,
    "number": 3,
    "text": "Data structures and algorithms. Medium difficulty.",
    "sender": SENDER from env file
}
{
    "id": 2,
    "number": 3,
    "text": "Vegetables and fruits. Medium difficulty.",
    "sender": SENDER from env file
}

Notes

  • If PythonAnywhere hosted instance doesn't connect to hosted RabbitMQ instance. Simply run the Python service locally to the hosted RabbitMQ instance.

quizgptservice's People

Contributors

fryingpannn avatar

Watchers

Kostas Georgiou avatar  avatar

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.