From ba9aa5504175f80c9cf0e8dd5bac990f9d21ee7c Mon Sep 17 00:00:00 2001 From: vagusx Date: Wed, 22 Nov 2023 14:17:03 +0800 Subject: [PATCH 1/3] feat: add MOCK env variable for debugging purposes --- README.md | 3 +++ backend/main.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6dfabc..9337a40 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ echo "OPENAI_API_KEY=sk-your-key" > .env poetry install poetry shell poetry run uvicorn main:app --reload --port 7001 + +# Useful for debugging purposes when you don't want to waste GPT4-Vision credits +MOCK=true poetry run uvicorn main:app --reload --port 7001 ``` Run the frontend: diff --git a/backend/main.py b/backend/main.py index 72b4dd7..1dc9333 100644 --- a/backend/main.py +++ b/backend/main.py @@ -33,7 +33,7 @@ app.add_middleware( # Useful for debugging purposes when you don't want to waste GPT4-Vision credits # Setting to True will stream a mock response instead of calling the OpenAI API -SHOULD_MOCK_AI_RESPONSE = False +SHOULD_MOCK_AI_RESPONSE = os.environ.get("MOCK", False) app.include_router(screenshot.router) From e7c9394946ff9d6a6ef4c259111c79059151f226 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Thu, 23 Nov 2023 11:27:59 -0500 Subject: [PATCH 2/3] update README --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 239e2bf..7a56758 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,6 @@ echo "OPENAI_API_KEY=sk-your-key" > .env poetry install poetry shell poetry run uvicorn main:app --reload --port 7001 - -# Useful for debugging purposes when you don't want to waste GPT4-Vision credits -MOCK=true poetry run uvicorn main:app --reload --port 7001 ``` Run the frontend: @@ -48,6 +45,12 @@ Open http://localhost:5173 to use the app. If you prefer to run the backend on a different port, update VITE_WS_BACKEND_URL in `frontend/.env.local` +For debugging purposes, if you don't want to waste GPT4-Vision credits, you can run the backend in mock mode (which streams a pre-recorded response): + +```bash +MOCK=true poetry run uvicorn main:app --reload --port 7001 +``` + ## Docker If you have Docker installed on your system, in the root directory, run: @@ -69,12 +72,10 @@ The app will be up and running at http://localhost:5173. Note that you can't dev **NYTimes** -| Original | Replica | -| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | +| Original | Replica | +| --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Screenshot 2023-11-20 at 12 54 03 PM | Screenshot 2023-11-20 at 12 59 56 PM | - - **Instagram page (with not Taylor Swift pics)** https://github.com/abi/screenshot-to-code/assets/23818/503eb86a-356e-4dfc-926a-dabdb1ac7ba1 From e8874fdbd44161c955df64f768e16a215dcd54d8 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Thu, 23 Nov 2023 11:30:19 -0500 Subject: [PATCH 3/3] coerce to bool --- backend/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index eeb096f..93d2e9a 100644 --- a/backend/main.py +++ b/backend/main.py @@ -33,7 +33,8 @@ app.add_middleware( # Useful for debugging purposes when you don't want to waste GPT4-Vision credits # Setting to True will stream a mock response instead of calling the OpenAI API -SHOULD_MOCK_AI_RESPONSE = os.environ.get("MOCK", False) +# TODO: Should only be set to true when value is 'True', not any abitrary truthy value +SHOULD_MOCK_AI_RESPONSE = bool(os.environ.get("MOCK", False)) app.include_router(screenshot.router)