Skip to content

Commit

Permalink
Merge pull request #244 from PrefectHQ/ai-functions-library
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin authored Apr 22, 2023
2 parents 9300d99 + 5fb839f commit bc31086
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Data cleaning
# AI Functions for data

> "Data cleaning is 80% of data science."
>
Expand Down Expand Up @@ -172,7 +172,7 @@ The Python string method [`.title()`](https://docs.python.org/3/library/stdtypes

```python

from marvin.ai_functions.data import title_case
from marvin.ai_functions.strings import title_case

title_case("the european went over to canada, eh?")
# The European Went Over to Canada, Eh?
Expand Down
16 changes: 16 additions & 0 deletions docs/guide/ai_functions/strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# AI Functions for strings

## Actual title case

Return a title case string that you would want to use in a title.

The Python string method [`.title()`](https://docs.python.org/3/library/stdtypes.html#str.title) makes the first letter of every word uppercase and the remaing letters lowercase. This result isn't what you want to use for the title of a piece of writing, generally. `title_case` takes a string and returns a string you can use in a title.

```python

from marvin.ai_functions.strings import title_case

title_case("the european went over to canada, eh?")
# The European Went Over to Canada, Eh?
```

2 changes: 1 addition & 1 deletion docs/guide/concepts/ai_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fix_sentence("he go to mcdonald and buy burg") # "He goes to McDonald's and buys
```

### Cleaning data
Cleaning data is such an important use case that Marvin has an entire module dedicated to it, including AI functions for categorization, standardization, entity extraction, and context-aware fills for missing values. See [the data cleaning documentation](/guide/use_cases/data_cleaning) for more information.
Cleaning data is such an important use case that Marvin has an entire module dedicated to it, including AI functions for categorization, standardization, entity extraction, and context-aware fills for missing values. See [the data cleaning documentation](/guide/ai_functions/data) for more information.
### Unit testing LLMs
One of the difficulties of building an AI library is unit testing it! While it's possible to make LLM outputs deterministic by setting the temperature to zero, a small change to a prompt could result in very different outputs. Therefore, we want a way to assert that an LLM's output is "approximately equal" to an expected value.

Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ nav:
- Loaders: guide/concepts/loaders_and_documents.md
- Infrastructure: guide/concepts/infra.md
- Plugins: guide/concepts/plugins.md
- AI Functions:
- Data: guide/ai_functions/data.md
- Strings: guide/ai_functions/strings.md
- Use Cases:
- Data cleaning: guide/use_cases/data_cleaning.md
- Enforcing LLM output formats: guide/use_cases/enforcing_format.md
- Slackbot: guide/use_cases/slackbot.md
- Development:
Expand Down
2 changes: 2 additions & 0 deletions src/marvin/ai_functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .base import ai_fn

from . import data, strings
9 changes: 1 addition & 8 deletions src/marvin/ai_functions/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING

from marvin import ai_fn
from marvin.ai_functions import ai_fn

if TYPE_CHECKING:
from pandas import DataFrame
Expand Down Expand Up @@ -58,10 +58,3 @@ def standardize(data: list[str], format: str) -> list[str]:
Given a list of data, standardize the data to the given format. For example,
the format could be "phone number", "sentence case", "ISO date", etc.
"""


@ai_fn
def title_case(input: str) -> str:
"""
Given a string {input} change the case to make it APA style guide title case.
"""
8 changes: 8 additions & 0 deletions src/marvin/ai_functions/strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from marvin.ai_functions import ai_fn


@ai_fn
def title_case(input: str) -> str:
"""
Given a string {input} change the case to make it APA style guide title case.
"""
9 changes: 0 additions & 9 deletions tests/llm_tests/ai_functions/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,3 @@ def test_standardize_case(self):
format="Proper case",
)
assert result == ["Brown Cow", "Small Dog", "Big Cat", "Medium-Sized Bird"]


class TestTitleCase:
def test_short_prepositions_not_capitalized(self):
result = data_fns.title_case(
input="let me go to the store",
)

assert result == "Let Me Go to the store"
10 changes: 10 additions & 0 deletions tests/llm_tests/ai_functions/test_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from marvin.ai_functions import strings as string_fns


class TestTitleCase:
def test_short_prepositions_not_capitalized(self):
result = string_fns.title_case(
input="let me go to the store",
)

assert result == "Let Me Go to the store"

0 comments on commit bc31086

Please sign in to comment.