Skip to content
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

Simplify markdown table generation in magic command - %ai list #1251

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keerthi-swarna
Copy link
Collaborator

@keerthi-swarna keerthi-swarna commented Feb 19, 2025

Issue Reference: Issue-118

Description

Refactored the code responsible for generating markdown tables by replacing custom imperative logic with the py-markdown-table library.

Changes

  • Updated the _ai_list_command_markdown method in magics.py to generate markdown tables using the py-markdown-table library.
  • Modified the _ai_env_status_for_provider_markdown method to return the env_variable alongside its status in emoji form, replacing the previous approach where the emoji was appended to the env_variable string.
  • Added the py-markdown-table library as a dependency in pyproject.toml.
  • Updated the help text in the aws.py file to address an issue where markdown was not rendering correctly within a markdown table cell. To resolve this, markdown syntax was replaced with HTML tags to ensure proper rendering.

Testing

  • Verified the changes by running Jupyter Lab in a local environment setup.
  • Attached screenshots from the local environment for reference.
Screenshot 2025-02-19 at 6 43 35 PM Screenshot 2025-02-19 at 6 43 44 PM Screenshot 2025-02-19 at 6 43 55 PM

@keerthi-swarna keerthi-swarna added good first issue Good for newcomers enhancement New feature or request labels Feb 19, 2025
Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

@keerthi-swarna Great work! I left some feedback for you below.

One other issue I noticed is that the py-markdown-table dependency is not available on Conda Forge. Conda Forge is an alternative package registry that allows users to install jupyter-ai using conda, mamba, or micromamba. We can't merge this PR until that is available on Conda Forge, as otherwise installing Jupyter AI from Conda Forge would be broken.

Creating a new Conda Forge package from an existing PyPI package will be a challenge. I would love for you to own this because it is a great opportunity to develop a unique & useful skill. However, I also understand if you need more time before tackling this. Let's talk about this in our next 1:1.

Comment on lines +127 to +128
"<ul><li> For Cross-Region Inference use the appropriate `Inference profile ID` (Model ID with a region prefix, e.g., `us.meta.llama3-2-11b-instruct-v1:0`). See the [inference profiles documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html).</li></ul>"
"<ul><li> For custom/provisioned models, specify the model ARN (Amazon Resource Name) as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html).</li></ul>"
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the motivation behind this change? This doesn't seem related to the other changes.

@@ -30,6 +30,7 @@ dependencies = [
"typing_extensions>=4.5.0",
"click~=8.0",
"jsonpath-ng>=1.5.3,<2",
"py_markdown_table>=1.3.0"
Copy link
Member

Choose a reason for hiding this comment

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

We should have a version ceiling in each of our dependencies. Without a version ceiling, users may accidentally install py_markdown_table==2.* if a v2 version of that package were to be released.

Since upgrading a major version generally introduces breaking changes, we should prevent this by adding a version ceiling:

Suggested change
"py_markdown_table>=1.3.0"
"py_markdown_table>=1.3.0,<2.0.0"

providers_info_markdown_table
+ alias_markdown_table_header
+ alias_markdown_table
)

def _ai_list_command_text(self, single_provider=None):
Copy link
Member

Choose a reason for hiding this comment

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

Can we return the same string in both the Markdown & text views? The text view is only seen when running ipython from the command line. You can see the different output by running this in your terminal:

% ipython
Python 3.11.11 | packaged by conda-forge | (main, Dec  5 2024, 14:21:42) [Clang 18.1.8 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.30.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %reload_ext jupyter_ai_magics
In [2]: %ai list

Right now, when you run %ai list from the command line, it is calling _ai_list_command_text(), which produces something different. It seems weird that we have two different implementations for the same command. Can you explore showing the Markdown tables when %ai list is called from ipython directly?

To get started, the handle_list() method should be changed to:

    def handle_list(self, args: ListArgs):
        markdown = self._ai_list_command_markdown(args.provider_id)
        return TextOrMarkdown(
            markdown,
            markdown,
        )

@dlqqq dlqqq marked this pull request as draft February 20, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify Markdown table generation in magic commands
3 participants