Code Monkey home page Code Monkey logo

chatbot_rkguo's Introduction

Chatbot with API for Ruikang Guo

Context: Ruikang Guo resume 2023.08.03

Dependencies

pip install fastapi uvicorn[standard] llama_index openai

Running the app

python -m uvicorn Main:app --reload

Endpoints

/

returns hello mundo

/api/v1/{your question here}

returns a response

CORS config

CORS is a security feature implemented by web browsers to prevent web pages from making requests to a different domain than the one that served the web page. This security measure is in place to protect users from potential security vulnerabilities.

If we don’t do any configuration, the application cannot return anything to the frontend due to CORS error.

# Add these lines
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# Configure CORS
origins = ["https://rkguo.xyz"]  # Replace with your allowed origin(s)

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True, # Optional
    allow_methods=["*"],  # Optional, You can adjust the HTTP methods as needed
    allow_headers=["*"],  # Optional, You can adjust the allowed headers as needed
)

Deployment Process

Deployed to Heroku

  1. Create requirements.txt

    pip freeze > requirements.txt
  2. Create a “Procfile”

    web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}
    
  3. Create a gitignore

    **/__pycache__/
    .env
    dep
    lambda_artifact.zip
    *.pyc
    *.pyo
    venv/
    
  4. Install Heroku CLI

    The Heroku CLI | Heroku Dev Center

  5. Heroku CLI Login

    heroku login
  6. Create a new Heroku App

    Skip this step if you already created an app using the heroku web GUI

    heroku create your-app-name
  7. Add Heroku remote

    git remote add heroku https://git.heroku.com/your-app-name.git
  8. Push to heroku

    git push heroku your-main-or-master-branch-name
  9. Deal with .env files

    Using Heroku Dashboard:

    You can set, modify, or view environment variables from the Heroku dashboard:

    • Navigate to Heroku Dashboard
    • Select your application.
    • Go to the "Settings" tab.
    • Find the "Config Vars" section and use the "Reveal Config Vars" button.
    • Here you can add key-value pairs equivalent to what you have in your .env file.

chatbot_rkguo's People

Contributors

leoguodnas avatar

Watchers

Ruikang (Leo) Guo 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.