Skip to content

support to launch Aqua services without jupyterlab #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2025

Conversation

mayoor
Copy link
Member

@mayoor mayoor commented Feb 15, 2025

No description provided.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 15, 2025
darenr
darenr previously approved these changes Feb 15, 2025
Copy link

📌 Cov diff with main:

Coverage-50%

📌 Overall coverage:

Coverage-56.68%

ahosler
ahosler previously approved these changes Feb 16, 2025
Copy link

📌 Cov diff with main:

Coverage-50%

📌 Overall coverage:

Coverage-56.60%

@mayoor mayoor dismissed stale reviews from darenr and ahosler via 8180950 February 18, 2025 21:37
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

📌 Cov diff with main:

Coverage-0%

📌 Overall coverage:

Coverage-19.46%

Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-58.61%

mrDzurb
mrDzurb previously approved these changes Feb 18, 2025
logger = getLogger(__name__)
config_location = os.path.join(os.getcwd(), ".env")
if os.path.exists(config_location):
logger.info(f"Loading environment variables from {config_location}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

if load_dotenv(dotenv_path=config_location):
    logger.info(f"Environment variables successfully loaded from {config_location}.")

Do we want to use this option as well?

 verbose: Whether to output a warning the .env file is missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the else part to warning

Are you suggesting that we log based on the verbose option? By default we dont show anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, we could show the success message if any variables were loaded, but then I thought it would be useful to know which variables were not loaded and verbose flag i guess can give us such info? If we do this we don't need to show the logger.info(f"Loading environment variables from {config_location}").

But it was marked as NIT in any case :) we can leave it as is.

logger.info("Environment variables loaded successfully")
else:
logger.info(
f"{config_location} not found. Conside using `.env` file to setup defalut environment variables"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Conside -> Consider
defalut -> default

logger.info(
    f"{config_location} not found. Consider using a `.env` file to set up default environment variables."
)



def prepare(self):
self.set_header("Access-Control-Allow-Origin", "*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add a couple of more headers? Something like:

self.set_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
self.set_header("Access-Control-Allow-Headers", "Content-Type, Authorization")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont handle Authorization and tornado dont seem to mind that these headers are not part of it.

# Patch the prepare method to allow CORS request
if os.environ.get(AQUA_CORS_ENABLE, "0") == "1":
for _, handler in __handlers__:
handler.prepare = prepare
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are dynamically patching the prepare method of handlers to set the Access-Control-Allow-Origin header based on the AQUA_CORS_ENABLE environment variable. I'm wondering, wouldn't it be better instead of patching the existing handlers, create some another base handler that will contain all the required settings, and then we can do something like this:

handlers = [
        (r"/aqua/" + url, type(f"{handler.__name__}WithCorse", (handler, CORSEMixin), {}))
        for url, handler in __handlers__
    ]

Or maybe even simpler

def patch_handler_for_cors(handler_cls) -> None:
    original_prepare = getattr(handler_cls, "prepare", None)

    def new_prepare(self, *args, **kwargs):
        if original_prepare:
            original_prepare(self, *args, **kwargs)
        self.set_header("Access-Control-Allow-Origin", "*")
    
    handler_cls.prepare = new_prepare

I don’t have a strong opinion on this, but I’m concerned that we might unintentionally override existing logic in the prepare method for one of the AQUA handlers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am making the default prepare as just pass. This method is there only because the APIHandler class in the jupyterlab has this method which checks for CORS. We dont want jupyterlab's logic to come when we are launching this as a standalone. Hence I am overriding it.

Which one do you think is more readable though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yours is definitely more readable. The decorator only makes sense to me if we're concerned about preserving the original prepare method that we're overriding here.

pyproject.toml Outdated
@@ -207,6 +207,14 @@ pii = [
]
llm = ["langchain>=0.2", "langchain-community", "langchain_openai", "pydantic>=2,<3", "evaluate>=0.4.0"]
aqua = ["jupyter_server"]
aquaapi = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we integrate this directly into [aqua]? Is jupyter_server our concern?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss this and decide. Wanted to keep only the dependency required for the API server. I am not sure if we are using [aqua] profile anywhere other than the dev setup. If we are not using aqua anywhere else, we can remove jupyter_server and rename aquaapi to aqua

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, don't know how the aqua currently used, i thought we use it container, but we don't. I guess we can remove it, and just mention in dev docs that jupyter_server is required for dev purpose.

Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

@mayoor mayoor changed the base branch from main to aqua_apiserver February 21, 2025 00:32
@mayoor mayoor merged commit 43e0977 into aqua_apiserver Feb 21, 2025
12 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants