Skip to content

Commit

Permalink
style: run black (#1192)
Browse files Browse the repository at this point in the history
* style: run black

* [style] black formatting - include tests and other files
  • Loading branch information
atangwbd committed Jun 23, 2023
1 parent 52658eb commit ed023a1
Show file tree
Hide file tree
Showing 95 changed files with 5,913 additions and 4,504 deletions.
76 changes: 38 additions & 38 deletions feathr_project/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

project = 'Feathr Feature Store'
copyright = '2023, Feathr Community'
author = 'Feathr Community'
project = "Feathr Feature Store"
copyright = "2023, Feathr Community"
author = "Feathr Community"

# The short X.Y version
version = '1.0'
version = "1.0"
# The full version, including alpha/beta/rc tags
release = '1.0.0'
release = "1.0.0"


# -- General configuration ---------------------------------------------------
Expand All @@ -39,30 +40,30 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinx_rtd_theme',
'sphinx.ext.napoleon',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
"sphinx_rtd_theme",
"sphinx.ext.napoleon",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -74,7 +75,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'setup.py']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "setup.py"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
Expand All @@ -85,7 +86,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -96,7 +97,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -112,7 +113,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'feathrdoc'
htmlhelp_basename = "feathrdoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -121,15 +122,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -139,19 +137,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'feathr.tex', 'feathr Documentation',
'Feathr Community', 'manual'),
(master_doc, "feathr.tex", "feathr Documentation", "Feathr Community", "manual"),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'feathr', 'feathr Documentation',
[author], 1)
]
man_pages = [(master_doc, "feathr", "feathr Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -160,9 +154,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'feathr', 'feathr Documentation',
author, 'feathr', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"feathr",
"feathr Documentation",
author,
"feathr",
"One line description of project.",
"Miscellaneous",
),
]


Expand All @@ -181,15 +181,15 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}

# -- Options for todo extension ----------------------------------------------

Expand Down
90 changes: 45 additions & 45 deletions feathr_project/feathr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,49 @@


__all__ = [
'FeatureJoinJobParams',
'FeatureGenerationJobParams',
'FeathrClient',
'DerivedFeature',
'FeatureAnchor',
'Feature',
'ValueType',
'WindowAggTransformation',
'TypedKey',
'DUMMYKEY',
'BackfillTime',
'MaterializationSettings',
'MonitoringSettings',
'RedisSink',
'HdfsSink',
'MonitoringSqlSink',
'AerospikeSink',
'FeatureQuery',
'LookupFeature',
'Aggregation',
'get_result_df',
'AvroJsonSchema',
'Source',
'InputContext',
'HdfsSource',
'SnowflakeSource',
'KafkaConfig',
'KafKaSource',
'ValueType',
'BooleanFeatureType',
'Int32FeatureType',
'Int64FeatureType',
'FloatFeatureType',
'DoubleFeatureType',
'StringFeatureType',
'BytesFeatureType',
'FloatVectorFeatureType',
'Int32VectorFeatureType',
'Int64VectorFeatureType',
'DoubleVectorFeatureType',
'FeatureNameValidationError',
'ObservationSettings',
'FeaturePrinter',
'SparkExecutionConfiguration',
"FeatureJoinJobParams",
"FeatureGenerationJobParams",
"FeathrClient",
"DerivedFeature",
"FeatureAnchor",
"Feature",
"ValueType",
"WindowAggTransformation",
"TypedKey",
"DUMMYKEY",
"BackfillTime",
"MaterializationSettings",
"MonitoringSettings",
"RedisSink",
"HdfsSink",
"MonitoringSqlSink",
"AerospikeSink",
"FeatureQuery",
"LookupFeature",
"Aggregation",
"get_result_df",
"AvroJsonSchema",
"Source",
"InputContext",
"HdfsSource",
"SnowflakeSource",
"KafkaConfig",
"KafKaSource",
"ValueType",
"BooleanFeatureType",
"Int32FeatureType",
"Int64FeatureType",
"FloatFeatureType",
"DoubleFeatureType",
"StringFeatureType",
"BytesFeatureType",
"FloatVectorFeatureType",
"Int32VectorFeatureType",
"Int64VectorFeatureType",
"DoubleVectorFeatureType",
"FeatureNameValidationError",
"ObservationSettings",
"FeaturePrinter",
"SparkExecutionConfiguration",
__version__,
]
]
20 changes: 11 additions & 9 deletions feathr_project/feathr/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from IPython.core.magic import Magics, line_magic, magics_class

from feathr.chat.feathr_chat import FeathrChat
Expand All @@ -7,32 +6,35 @@

chatBot = FeathrChat()
dsl_learned = False


@magics_class
class FeathrMagic(Magics):

@line_magic
def feathr(self, question):
scope = get_ipython().get_local_scope(stack_depth=2)
client = scope.get('client')
scope = get_ipython().get_local_scope(stack_depth=2)
client = scope.get("client")
global dsl_learned
if client:
prompt_generator = PromptGenerator(client)
if not dsl_learned:
ask_to_teach = "I am going to teach you a DSL, could you learn it?"
chatBot.ask_llm_in_notebook(ask_to_teach)
dsl = '\n Feathr DSL: \n' + prompt_generator.get_feathr_dsl_prompts()
dsl = "\n Feathr DSL: \n" + prompt_generator.get_feathr_dsl_prompts()
chatBot.ask_llm_in_notebook(dsl)

ask_to_teach = "Do you want to see the full source code for the APIs?"
chatBot.ask_llm_in_notebook(ask_to_teach)
dsl = '\n Feathr DSL: \n' + prompt_generator.get_full_dsl_source_code()
dsl = "\n Feathr DSL: \n" + prompt_generator.get_full_dsl_source_code()
chatBot.ask_llm_in_notebook(dsl)

dsl_learned = True
question_with_prompt = prompt_generator.process_question(question)
chatBot.ask_llm_in_notebook(question_with_prompt)
else:
print("'client' is not defined in the notebook. Please create a FeathrClient instance named as 'client' before using Feathr chat. e.g. client = FeathrClient('/path/to/your/workspace') ")
print(
"'client' is not defined in the notebook. Please create a FeathrClient instance named as 'client' before using Feathr chat. e.g. client = FeathrClient('/path/to/your/workspace') "
)


def load_ipython_extension(ipython):
Expand Down
7 changes: 5 additions & 2 deletions feathr_project/feathr/chat/feathr_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from revChatGPT.V3 import Chatbot
from feathr.chat.notebook_utils import *


class FeathrChat(object):
def __init__(self):
key = self.get_api_key()
Expand All @@ -19,7 +20,9 @@ def ask_llm_in_notebook(self, question_with_prompt: str):
if not self.chat_bot:
key = self.get_api_key()
if not key:
raise RuntimeError("Please set environment variable CHATGPT_API_KEY before using Feathr Chat. You can get your API key for ChatGPT at https://platform.openai.com/account/api-keys. For example, run: os.environ['CHATGPT_API_KEY'] = 'your api key' and retry.")
raise RuntimeError(
"Please set environment variable CHATGPT_API_KEY before using Feathr Chat. You can get your API key for ChatGPT at https://platform.openai.com/account/api-keys. For example, run: os.environ['CHATGPT_API_KEY'] = 'your api key' and retry."
)
self.chat_bot = Chatbot(key)

content = self.chat_bot.ask(question_with_prompt)
Expand All @@ -31,6 +34,6 @@ def ask_llm_in_notebook(self, question_with_prompt: str):
create_new_cell(code)
else:
print(content)

def is_a_code_gen_question(self, question_with_prompt):
return "explain" not in question_with_prompt.lower() and "what" not in question_with_prompt.lower()
9 changes: 5 additions & 4 deletions feathr_project/feathr/chat/notebook_utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from IPython.core.getipython import get_ipython
import re


def create_new_cell(contents):
shell = get_ipython()
payload = dict(
source='set_next_input',
source="set_next_input",
text=contents,
replace=False,
)
shell.payload_manager.write_payload(payload, single=False)


def extract_code_from_string(input_str, lang='python'):

def extract_code_from_string(input_str, lang="python"):
"""Extract the code block for a given language"""
pattern = fr'```({lang}|\s*)\n(.*?)\n```'
pattern = rf"```({lang}|\s*)\n(.*?)\n```"
# Use the re.findall() function to extract the code block
match = re.search(pattern, input_str, re.DOTALL)
# Check if any code block was found
Expand Down
Loading

0 comments on commit ed023a1

Please sign in to comment.