Skip to content

Commit

Permalink
Refractor streamlit env registration
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarthik108 committed Aug 24, 2023
1 parent c613cc3 commit e99afd9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ snowdev <command> [options]

- `--udf <udf_name>`: Name or identifier for the UDF you want to deploy.
- `--sproc <sproc_name>`: Name or identifier for the Stored Procedure you want to deploy.
- `--streamlit <streamlit_name>`: Name or identifier for the Streamlit application you want to deploy.
- `--streamlit <streamlit_name>`: Name or identifier for the Streamlit application you want to deploy. (This is still in PrPr)
- `--upload <upload_item>`: Specifies what to upload. Currently supported options: `static`.
- `--package <package_name>`: Specifies the name of the package to zip and upload to the static folder.
- `--embed`: Used with the `ai` command to run embeddings.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "snowdev"
version = "0.1.16"
version = "0.1.17"
description = "snowdev: DevOps toolkit for Snowflake, facilitating seamless deployment of UDFs, stored procedures, and Streamlit apps using Snowpark's capabilities right from your local environment."
authors = ["kaarthik <[email protected]>"]
readme = "README.md"
Expand Down
Empty file added snowdev/fillers/__init__.py
Empty file.
Empty file.
Empty file.
Empty file added snowdev/fillers/udf/__init__.py
Empty file.
27 changes: 24 additions & 3 deletions snowdev/functions/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import pkg_resources

import toml
from langchain.chains import LLMChain, RetrievalQA
Expand Down Expand Up @@ -101,6 +102,28 @@ def append_dependencies_to_toml(dependencies_dict):
with open(toml_path, "w") as f:
toml.dump(data, f)

@staticmethod
def write_environment_file(component_folder, template_type):
"""
This is temporary, until we have a better way to auto create environment files through Langchain output parsers.
"""
file_map = {"streamlit": "fill.yml", "udf": "fill.toml", "sproc": "fill.toml"}
source_file_name = file_map.get(template_type)

if not source_file_name:
return

content = pkg_resources.resource_string(
f"snowdev.fillers.{template_type}", source_file_name
).decode("utf-8")

target_file_name = (
"environment.yml" if template_type == "streamlit" else source_file_name
)

with open(os.path.join(component_folder, target_file_name), "w") as env_file:
env_file.write(content)

@staticmethod
def create_new_ai_component(component_name, prompt, template_type):
# Ensure that the template_type is valid
Expand Down Expand Up @@ -147,6 +170,7 @@ def create_new_ai_component(component_name, prompt, template_type):

component_folder = os.path.join("src", template_type, component_name)
os.makedirs(component_folder, exist_ok=True)
SnowBot.write_environment_file(component_folder, template_type)

filename = "app.py"
if template_type == "streamlit":
Expand All @@ -155,9 +179,6 @@ def create_new_ai_component(component_name, prompt, template_type):
with open(os.path.join(component_folder, filename), "w") as f:
f.write(response_content)

dependencies = {"some-library": "1.0.0", "another-library": "2.0.1"}
SnowBot.append_dependencies_to_toml(dependencies)

print(
colored(
f"✅ {template_type.upper()} {component_name} generated successfully using AI!",
Expand Down
7 changes: 4 additions & 3 deletions snowdev/functions/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create_stage_if_not_exists(self, stage_name):
def get_connection_details_from_yml(self, directory):
"""
Parse the environment.yml file and extract the connection details.
# Not supported yet
"""
yml_path = os.path.join(directory, "environment.yml")

Expand Down Expand Up @@ -76,7 +77,7 @@ def upload_to_stage(self, file_path, stage_name, app_name):
def create_streamlit_app(self, func_name, stage_name, app_name):
self.database = self.session.get_current_database().replace('"', "")
streamlit_name = func_name.replace("_", " ").capitalize()

self.session.sql(
f"""
CREATE OR REPLACE STREAMLIT "{streamlit_name}"
Expand All @@ -93,9 +94,9 @@ def handler_streamlit(self, filepath):
print(colored(f"Error: The directory {directory} does not exist.", "red"))
return

self.connection_details = self.get_connection_details_from_yml(directory)
# self.connection_details = self.get_connection_details_from_yml(directory)

self.apply_connection_details(directory)
# self.apply_connection_details(directory) # Modifying yml is not supported

print(colored("Deploying STREAMLIT APP:", "cyan"))
print("Directory:", colored(directory, "yellow"))
Expand Down
2 changes: 1 addition & 1 deletion snowdev/functions/utils/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Config(BaseModel):
"snowdev.functions.utils", "knowledge"
)


class DocumentProcessor:
def __init__(self, secrets: Secrets, config: Config):
self.loader_py = DirectoryLoader(config.docs_dir, glob="**/*.py")
Expand All @@ -30,7 +31,6 @@ def __init__(self, secrets: Secrets, config: Config):
)
self.embeddings = OpenAIEmbeddings(openai_api_key=secrets.OPENAI_API_KEY)


def process(self) -> Dict[str, Any]:
data_py = self.loader_py.load()
data_md = self.loader_md.load()
Expand Down
1 change: 1 addition & 0 deletions snowdev/functions/utils/snowpark_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ def generate_documentation(cls):

cls._write_to_markdown_file(filepath, all_items)


if __name__ == "__main__":
SnowparkMethods.generate_documentation()

0 comments on commit e99afd9

Please sign in to comment.