Skip to content

Commit

Permalink
extract snowpark methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarthik108 committed Aug 22, 2023
1 parent 9061568 commit e46e830
Show file tree
Hide file tree
Showing 9 changed files with 905 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SnowDev - Snowpark Devops

[![Documentation](https://img.shields.io/badge/documentation-view-blue)](docs/quickstart.md) ![PyPI Downloads](https://img.shields.io/pypi/dm/snowdev)

SnowDev is a command-line utility designed for deploying various components related to Snowflake such as UDFs, stored procedures, and Streamlit applications using **Snowpark**. This tool streamlines tasks like initializing directories, local testing, uploading, and auto create components code using AI.

## Setup
Expand Down Expand Up @@ -76,10 +78,12 @@ snowdev <command> [options]
- [x] Support for Streamlit
- [x] AI interactions for embedding and suggestions
- [ ] Use AI to modify existing code for optimization
- [ ] AI to add the packages to toml file
- [ ] Adding more granularity for AI commands
- [ ] Support for snowflake Tasks



## Contributions

Feel free to contribute to SnowDev by submitting pull requests or opening issues on the project's GitHub repository.
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.8"
version = "0.1.9"
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
17 changes: 14 additions & 3 deletions snowdev/functions/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re

import toml
from langchain.chains import LLMChain, RetrievalQA
Expand All @@ -14,7 +15,9 @@
)
from snowdev.functions.utils.templates.udf import TEMPLATE as UDF_TEMPLATE
from snowdev.functions.utils.ingest import DocumentProcessor, Secrets, Config
from snowdev.functions.utils.snowpark_methods import SnowparkMethods

MODEL = "gpt-4"

class SnowBot:

Expand All @@ -33,6 +36,7 @@ def ai_embed():
config = Config()
doc_processor = DocumentProcessor(secrets, config)
try:
SnowparkMethods.generate_documentation()
result = doc_processor.process()
print(colored("✅ Documents have been successfully embedded!", "green"))
return result
Expand Down Expand Up @@ -62,8 +66,8 @@ def get_chain_gpt(db):
Get a chain for chatting with a vector database.
"""
llm = ChatOpenAI(
model_name="gpt-4",
temperature=0.5,
model_name=MODEL,
temperature=0,
openai_api_key=os.environ["OPENAI_API_KEY"],
max_tokens=500,
)
Expand Down Expand Up @@ -126,7 +130,14 @@ def create_new_ai_component(component_name, prompt, template_type):
vectordb = Chroma(persist_directory="chroma_db", embedding_function=embeddings)
chain = SnowBot.get_chain_gpt(vectordb)
response_content = chain(prompt)["result"]
response_content = response_content.split("```python\n")[1].split("\n```")[0]

matches = re.findall(r"```(?:python)?\n(.*?)\n```", response_content, re.DOTALL)

if matches:
# Take the first match, as there might be multiple code blocks
response_content = matches[0].strip()
else:
print(colored("Unexpected response content format. Expected code block not found. Please try again", "red"))

component_folder = os.path.join("src", template_type, component_name)
os.makedirs(component_folder, exist_ok=True)
Expand Down
4 changes: 2 additions & 2 deletions snowdev/functions/utils/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Secrets(BaseModel):
class Config(BaseModel):
chunk_size: int = 1000
chunk_overlap: int = 0
docs_dir: str = "snowdev/snow_functions/utils/knowledge"
docs_glob: str = "**/*.py"
docs_dir: str = "snowdev/functions/utils/knowledge"
docs_glob: str = "**/*"


class DocumentProcessor:
Expand Down
Loading

0 comments on commit e46e830

Please sign in to comment.