Skip to content

Instantly share code, notes, and snippets.

import marvin
from marvin import ai_fn
marvin.settings.llm_model = 'gpt-4'
@ai_fn
def semantic_deduplication(new_item: str, existing_items: list[str]) -> list[str]:
"""
Check if the `new_item` is semantically the same as any of the `existing_items`.
If it is, update the existing item's description with the new one.
@jlowin
jlowin / score_customer_emails_with_marvin.py
Created March 31, 2023 18:27
Scoring emails with Marvin
from marvin import ai_fn
import pydantic
class EmailDetails(pydantic.BaseModel):
is_positive: bool = pydantic.Field(
description="Whether the email has a positive tone"
)
action_items: list[str] = pydantic.Field(
"Follow-up questions, rewritten as single sentences that are understandable"
from marvin import ai_fn
@ai_fn
def generate_people(n: int) -> list[dict]:
"""Generates a list of n people with random names and ages."""
generate_people(n=2) # [{'name': 'Olivia', 'age': 30}, {'name': 'Ethan', 'age': 22}]
from prefect import task, Flow, Parameter
from prefect.tasks.control_flow import case
@task
def send_email(email):
print(f"Sending an email to {email}")
@task
Hey all,
As some of you already know, we're in the process of moving Airflow into the Apache incubator. This will involve a number of infrastructure and process changes. These changes will include:
1) Migration of airbnb/airflow code base to Apache's Git repository.
2) Migration of Google groups mailing list (this list) to Apache developer list.
3) Migration of Travis CI to use the Apache Git repository.
4) Migration of GitHub wiki to Apache Confluence wiki.
5) Migration of GitHub Issues to Apache Jira.
6) Migration of all existing pull requests to the Apache GitHub account.
@jlowin
jlowin / gist:3874776
Created October 11, 2012 19:08
Scan bug?
import numpy as np
import theano
import theano.tensor as tt
# this is the input
inp = np.arange(10).reshape(-1,1)
print 'this is the input: {}'.format(inp)
# this is the expected output
exp_out = np.zeros((10,1)); exp_out[4:] = inp[:-4]
@jlowin
jlowin / ggplot2.r
Created November 13, 2009 03:04
choropleth ggplot code
library(ggplot2)
#extract reference data
mapcounties <- map_data("county")
mapstates <- map_data("state")
#merge data with ggplot county coordinates
mapcounties$county <- with(mapcounties , paste(region, subregion, sep = ","))
mergedata <- merge(mapcounties, unemp_data, by.x = "county", by.y = "counties")
mergedata <- mergedata[order(mergedata$order),]
@jlowin
jlowin / maps.r
Created November 13, 2009 03:03
choropleth maps code
library(maps)
#align data with map definitions
mapnames <- map("county",plot=FALSE)[4]$names
colorsmatched <- unemp_data$colorBuckets [match(mapnames ,unemp_data$counties)]
#draw map
map("county",col = colors[unemp_data$colorBuckets[match(mapnames ,unemp_data$counties)]],fill = TRUE,resolution = 0,lty = 0,projection = "polyconic")
map("state",col = "white",fill=FALSE,add=TRUE,lty=1,lwd=1,projection="polyconic")
@jlowin
jlowin / data.r
Created November 13, 2009 03:02
choropleth data prep
#load data
stateAbbr <- read.csv("state abbr.csv")
rownames(stateAbbr) <- stateAbbr$ABB
unemp_data <- read.csv("unemp_county.csv")
#get county names in correct format
countyNames <- sapply(as.character(unemp_data$CountyName),strsplit,", ")
counties <- sapply(countyNames ,"[",1)
states <- sapply(countyNames ,"[",2)
states <- as.character(stateAbbr[states,2])