-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from rgbkrk/tools
Tools
- Loading branch information
Showing
19 changed files
with
663 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,5 @@ Untitled*.ipynb | |
lcov.info | ||
|
||
ops.ipynb | ||
|
||
.jupyter_ystore.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .files import chat_functions as file_functions | ||
from .python import get_python_docs, run_python | ||
from .shell import chat_functions as shell_functions | ||
|
||
__all__ = [ | ||
"file_functions", | ||
"get_python_docs", | ||
"run_python", | ||
"shell_functions", | ||
] | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Let models pick and show color palettes to you.""" | ||
import hashlib | ||
from typing import List, Optional | ||
from pydantic import BaseModel, validator, Field | ||
|
||
from IPython.display import display | ||
|
||
|
||
class Palette(BaseModel): | ||
"""A palette of colors for the user to see.""" | ||
|
||
colors: List[str] = Field(..., description="A list of CSS colors to display.") | ||
name: Optional[str] = None | ||
|
||
@validator("colors", each_item=True) | ||
def check_color_validity(cls, v): | ||
if not isinstance(v, str): | ||
raise ValueError("Each color must be a string representation of a CSS color.") | ||
if not all(c.isalnum() or c in "#.,()% " for c in v): | ||
raise ValueError( | ||
"Color contains invalid characters. Only alphanumeric and CSS color specific characters are allowed." | ||
) | ||
return v | ||
|
||
def _repr_html_(self): | ||
html = "<div>" | ||
for color in self.colors: | ||
html += f'<div style="background-color:{color}; width:50px; height:50px; display:inline-block;"></div>' | ||
html += "</div>" | ||
|
||
return html | ||
|
||
def __repr__(self): | ||
"""Returns a string representation of the palette.""" | ||
return f"Palette({self.colors}, {self.name})" | ||
|
||
|
||
def _generate_palette_name(colors: List[str]) -> str: | ||
hash_object = hashlib.sha1("".join(colors).encode()) | ||
return f"palette-{hash_object.hexdigest()}" | ||
|
||
|
||
def show_colors(colors: List[str]): | ||
"""Shows a list of CSS colors for the user in their notebook.""" | ||
palette = Palette(colors=colors) | ||
|
||
display(palette) | ||
return "Displayed colors for user." |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.