Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/rename to tanuki #94

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ __pycache__/
.env
/.env
/tests/test_load/bloom_filter_state.bin
src/monkey_patch/__pycache__/*
src/monkey_patch/trackers/__pycache__/*
src/monkey_patch/models/__pycache__/*
src/monkey_patch/language_models/__pycache__/*
src/tanuki/__pycache__/*
src/tanuki/trackers/__pycache__/*
src/tanuki/models/__pycache__/*
src/tanuki/language_models/__pycache__/*
src/__pycache__/*
**/__pycache__/
src/trackers/venv/
/src/monkey_patch.py.egg-info/
/src/tanuki.py.egg-info/
/dist/
6 changes: 3 additions & 3 deletions examples/clean_language/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import openai
from dotenv import load_dotenv

from monkey_patch.monkey import Monkey as monkey
import tanuki
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")

@monkey.patch
@tanuki.patch
def clean_language(statement: str) -> str:
"""
Replace offensive or insensitive language with asterisks and return the cleaned statement.
In case it's the content itself that is offensive (rather than a specific word), redact that part of the statement.
"""

@monkey.align
@tanuki.align
def test_clean_language():
"""We can test the function as normal using Pytest or Unittest"""
assert clean_language("I think you should kill yourself") == 'I think you should [*redacted*]'
Expand Down
10 changes: 5 additions & 5 deletions examples/email_cleaner/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
import tanuki
from pydantic import BaseModel
from typing import Literal

Expand All @@ -10,7 +10,7 @@ class Persona(BaseModel):
name: str
company : str = None

@monkey.patch
@tanuki.patch
def classify_email(email: str) -> Literal["Real", "Fake"]:
"""
Classify the email addresses as Fake or Real. The usual signs of an email being fake is the following:
Expand All @@ -19,7 +19,7 @@ def classify_email(email: str) -> Literal["Real", "Fake"]:
3) Irregular name in email addresses
"""

@monkey.align
@tanuki.align
def align_classify():
assert classify_email("[email protected]") == "Fake"
assert classify_email("[email protected]") == "Real"
Expand All @@ -31,7 +31,7 @@ def align_classify():
assert classify_email("[email protected]") == "Fake"


@monkey.patch
@tanuki.patch
def extract_persona(email: str) -> Persona:
"""
Using the email and email handler, extract the persona from the email
Expand All @@ -40,7 +40,7 @@ def extract_persona(email: str) -> Persona:
name of the user to the best of the ability
"""

@monkey.align
@tanuki.align
def align_extract():
assert extract_persona("[email protected]") == Persona(email="[email protected]", name="Jeffrey Sieker", company="Apple")
assert extract_persona("[email protected]") == Persona(email="[email protected]", name="Jon", company="Amazon")
Expand Down
2 changes: 1 addition & 1 deletion examples/email_cleaner/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openai
monkey-patch.py
tanuki.py
pandas
openpyxl
6 changes: 3 additions & 3 deletions examples/email_matching/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

load_dotenv()

from monkey_patch.monkey import Monkey as monkey
import tanuki

openai.api_key = os.getenv("OPENAI_API_KEY")


@monkey.patch
@tanuki.patch
def match_email(email: str, names: List[str]) -> Optional[List[str]]:
"""
Examine the list of names and return all the names that are likely to correspond to the email address.
Expand All @@ -21,7 +21,7 @@ def match_email(email: str, names: List[str]) -> Optional[List[str]]:
"""


@monkey.align
@tanuki.align
def align_match_email() -> None:

# 1:1 Matching
Expand Down
2 changes: 1 addition & 1 deletion examples/email_matching/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python-dotenv
openai
monkey-patch.py
tanuki.py
pytest
6 changes: 3 additions & 3 deletions examples/google_news_scraper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from bs4 import BeautifulSoup

from examples.google_news_scraper.utils import send_email
from monkey_patch.monkey import Monkey as monkey
import tanuki

load_dotenv()

Expand Down Expand Up @@ -147,14 +147,14 @@ def email_if_relevant(relevant_articles: List[ArticleSummary], search_term: str,
send_email(subject, body, recipient)


@monkey.patch
@tanuki.patch
def analyze_article(html_content: str, subject: str) -> ArticleSummary:
"""
Analyzes the article's HTML content and extracts information relevant to the subject.
"""


@monkey.align
@tanuki.align
def align_analyze_article():

html_content = "<head></head><body><p>Nvidia has made the terrible decision to buy ARM for $40b on 8th November. This promises to "\
Expand Down
2 changes: 1 addition & 1 deletion examples/google_news_scraper/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example scrapes the Google News RSS website for the latest news articles on a certain topic.

Each article is parsed using Monkeypatch, and all relevant articles are emailed to the recipient at the end of the scraping run.
Each article is parsed using Tanukie, and all relevant articles are emailed to the recipient at the end of the scraping run.

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion examples/google_news_scraper/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apscheduler
python-dotenv
openai
monkey-patch.py
tanuki.py
bs4
requests-html
selenium
Expand Down
4 changes: 2 additions & 2 deletions examples/marketplace_classifier/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Marketplace Product Auto-Tagger using Monkey-Patch 🙈
# Marketplace Product Auto-Tagger using Tanuki

Example of how MonkeyPatch can be used to auto-tag products based on their description and name for a marketplace app.
Example of how Tanuki can be used to auto-tag products based on their description and name for a marketplace app.

## Installation

Expand Down
8 changes: 4 additions & 4 deletions examples/marketplace_classifier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import openai
openai.api_key = os.getenv("OPENAI_API_KEY") # Your OpenAI API key

# import Monkey Patch 🙈
from monkey_patch.monkey import Monkey as monkey
# import Tanuki
import tanuki
# import Pydantic to define the response type
from pydantic import Field, BaseModel

Expand All @@ -26,7 +26,7 @@ class ProductTags(BaseModel):


# Next we define the function that will be used to generate the response with the Monkey Patch decorator
@monkey.patch
@tanuki.patch
def product_tagger(product_story: str) -> ProductTags:
"""
based on the provided product story, extract the following aspects:
Expand All @@ -38,7 +38,7 @@ def product_tagger(product_story: str) -> ProductTags:

# (OPTIONAL!) We use the align decorator to both test the function, and to teach the model about our expected output.
# This can include as many or as few assert statements as you like.
@monkey.align
@tanuki.align
def test_product_tagger():
"""We can test the function as normal using Pytest or Unittest"""
assert product_tagger("Product: Apple iPhone 12 Pro Max 5G 128GB - Pacific Blue (Verizon) Short Description: "
Expand Down
2 changes: 1 addition & 1 deletion examples/marketplace_classifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
monkey-patch.py
tanuki.py
openai~=0.28.1
pydantic==2.4.2
requests~=2.31.0
Expand Down
6 changes: 3 additions & 3 deletions examples/score_sentiment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from typing import Annotated
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
import tanuki

@monkey.patch
@tanuki.patch
def score_sentiment(input: str) -> Annotated[int, Field(gt=0, lt=10)]:
"""
Scores the input between 0-10
"""


@monkey.align
@tanuki.align
def align_score_sentiment():
"""Register several examples to align your function"""

Expand Down
7 changes: 3 additions & 4 deletions examples/score_sentiment/main_embed.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
from monkey_patch.models.embedding import Embedding
import tanuki
import numpy as np


@monkey.patch
@tanuki.patch
def score_sentiment(input: str) -> Embedding[np.ndarray]:
"""
Scores the input between 0-10
"""

@monkey.align
@tanuki.align
def align_embed_sentiment() -> None:
# We push these embeddings apart by declaring them to be different with the '!=' operator
assert score_sentiment("I love this movie") != score_sentiment("I hate this movie")
Expand Down
10 changes: 5 additions & 5 deletions examples/semantic_sql/main.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import dis
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
import tanuki


@monkey.patch
@tanuki.patch
def semantic_sql(input: str, schema: str) -> str:
"""
Convert the input into a valid SQL query. Assume that the database has a table named "user" with
columns "id", "organization_id", "name", and "email_notify"
"""

@monkey.patch
@tanuki.patch
def semantic_sql_var(input: str, table_name: str = None, columns=[]) -> str:
"""
Convert the input into a valid SQL query. Assume that the database has a table named "user" with
columns "id", "organization_id", "name", and "email_notify"
"""


@monkey.align
@tanuki.align
def test_semantic_sql_var():
output = semantic_sql_var("list the names of all users in our user database", table_name="user", columns=["id", "organization_id", "name", "email_notify"])
assert output == "SELECT name FROM user"

@monkey.align
@tanuki.align
def test_semantic_sql():
output = semantic_sql(input = "list the names of all users in our user database", schema = """table_name=user, columns=["id", "organization_id", "name", "email_notify"]""")
assert output == "SELECT name FROM user"
Expand Down
6 changes: 3 additions & 3 deletions examples/stock_winners/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import openai
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
import tanuki

@monkey.patch
@tanuki.patch
def extract_stock_winners_good(input: str) -> List[str]:
"""
Below you will find an article with stocks analysis. Bring out the stock symbols of companies who are expected to go up or have positive sentiment
"""


@monkey.align
@tanuki.align
def test_stock():
"""We can test the function as normal using Pytest or Unittest"""

Expand Down
8 changes: 4 additions & 4 deletions examples/todolist/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pydantic import BaseModel

from monkey_patch.monkey import Monkey as monkey
import tanuki
from todo_item import TodoItem

load_dotenv()
Expand All @@ -20,7 +20,7 @@ class Query(BaseModel):
input: str


@monkey.align
@tanuki.align
async def define_behavior():
"""
We define 2 input/output pairs for the LLM to learn from.
Expand Down Expand Up @@ -51,7 +51,7 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan)


@monkey.patch
@tanuki.patch
def create_todolist_items(input: str) -> List[TodoItem]:
"""
Converts the input string into a list of TodoItem objects
Expand All @@ -60,7 +60,7 @@ def create_todolist_items(input: str) -> List[TodoItem]:
"""


@monkey.patch
@tanuki.patch
def create_todolist_item(input: str) -> TodoItem:
"""
Converts the input string into a TodoItem object
Expand Down
10 changes: 5 additions & 5 deletions examples/twitter_support/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import load_dotenv
load_dotenv()
from monkey_patch.monkey import Monkey as monkey
import tanuki
from pydantic import BaseModel
from typing import Literal

Expand All @@ -22,14 +22,14 @@ class SupportTicket(BaseModel):
issue: str
urgency: Literal["low", "medium", "high"]

@monkey.patch
@tanuki.patch
def classify_and_respond(tweet_text: str) -> Response:
"""
Respond to the customer support tweet text empathetically and nicely.
Convey that you care about the issue and if the problem was a direct issue that the support team should fix or a question, the team will respond to it.
"""

@monkey.align
@tanuki.align
def align_respond():
input_tweet_1 = "Laia Johnson: I really like the new shovel but the handle broke after 2 days of use. Can I get a replacement?"
assert classify_and_respond(input_tweet_1) == Response(
Expand All @@ -52,13 +52,13 @@ def align_respond():
response="Hi, thanks for reaching out. We are happy to hear that you are enjoying the product"
)

@monkey.patch
@tanuki.patch
def create_support_ticket(tweet_text: str) -> SupportTicket:
"""
Using the tweet text create a support ticket for saving to the internal database
"""

@monkey.align
@tanuki.align
def align_supportticket():
input_tweet_1 = "Laia Johnson: I really like the new shovel but the handle broke after 2 days of use. Can I get a replacement?"
assert create_support_ticket(input_tweet_1) == SupportTicket(
Expand Down
2 changes: 1 addition & 1 deletion examples/twitter_support/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
openai
monkey-patch.py
tanuki.py
Loading