Skip to content

Instantly share code, notes, and snippets.

View skrawcz's full-sized avatar

Stefan Krawczyk skrawcz

View GitHub Profile
"""
This module demonstrates a telephone application
using Burr that:
- captions an image
- creates caption embeddings (for analysis)
- creates a new image based on the created caption
"""
import os
import uuid
@skrawcz
skrawcz / ai_response.py
Created June 19, 2024 22:56
Gist for the Hamilton, Burr, FalkorDB blog post
@action(
reads=["chat_history"],
writes=["chat_history"],
)
def AI_generate_response(state: State, client: openai.Client) -> tuple[dict, State]:
"""AI step to generate the response."""
messages = state["chat_history"]
response = client.chat.completions.create(
model="gpt-4-turbo-preview",
messages=messages,
@skrawcz
skrawcz / parameterize_sources_example.py
Last active July 19, 2024 17:25
@parameterize_sources example. This will create
# functions.py - declare and link your transformations as functions....
import pandas as pd
from hamilton.function_modifiers import parameterize_sources
def a(input: pd.Series) -> pd.Series:
return input % 7
def b(a: pd.Series) -> pd.Series:
return a * 2
@skrawcz
skrawcz / parameterizing_config.py
Last active July 19, 2024 17:16
Shows how to potentially get around boilerplate config loading code by parameterizing it
# %%cell_to_module config_plate --display
from hamilton.function_modifiers import parameterize, source, value
class TablePaths:
pass # your code here
table_names = ["vendor", "predictions"] # update this
@parameterize(
@skrawcz
skrawcz / run.py
Created July 19, 2024 18:07
Gist for guest post on blog
# python 3.12
"""
Hamilton demo. Runs the Hamilton code.
"""
import sys
import pprint
@skrawcz
skrawcz / ray_burr_option1.py
Created August 12, 2024 23:55
Shows how to wrap a burr application for delegation to Ray. This is one possible strategy to make things run on Ray.
import copy
from IPython.display import Image, display
from IPython.core.display import HTML
import openai
from burr.core import ApplicationBuilder, State, default, graph, when
from burr.core.action import action
from burr.tracking import LocalTrackingClient
@skrawcz
skrawcz / application.py
Last active October 18, 2024 19:07
Burr for workflow management of science work
import copy
from IPython.display import Image, display
from IPython.core.display import HTML
from burr.core import ApplicationBuilder, State, default, graph, when
from burr.core.action import action
from burr.tracking import LocalTrackingClient
@action(reads=[], writes=["output_folder"])
@skrawcz
skrawcz / show_fixture.py
Created December 30, 2024 16:51
gist for pytest blog post
import pytest
@pytest.fixture(scope="module")
def database_connection():
"""Fixture that creates a DB connection"""
db_client = SomeDBClient()
yield db_client
print("\nStopped client:\n")
def test_my_function(database_connection):