Skip to content

Commit

Permalink
Fix whitespace issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin committed Apr 22, 2023
1 parent 5b0644e commit e7bcd17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
26 changes: 24 additions & 2 deletions src/marvin/ai_functions/strings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import asyncio
import functools
import inspect

from marvin.ai_functions import ai_fn


def _strip_result(fn):
"""
A decorator that automatically strips whitespace from the result of
calling the function
"""

@functools.wraps(fn)
def wrapper(*args, **kwargs):
result = fn(*args, **kwargs)
if inspect.iscoroutine(result):
result = asyncio.run(result)
return result.strip()

return wrapper


@_strip_result
@ai_fn
def fix_capitalization(text: str) -> str:
"""
Given `text`, fix any capitalization errors. Do not change the text in any
other way.
Given `text`, which represents complete sentences, fix any capitalization
errors.
"""


@_strip_result
@ai_fn
def title_case(text: str) -> str:
"""
Expand Down
6 changes: 2 additions & 4 deletions tests/llm_tests/ai_functions/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class TestFixCapitalization:
def test_fix_capitalization(self):
def test_fix_capitalization(self, gpt_4):
result = string_fns.fix_capitalization("the european went over to canada, eh?")
assert result == "The European went over to Canada, eh?"

Expand All @@ -13,8 +13,6 @@ def test_title_case(self):
assert result == "The European Went Over to Canada, Eh?"

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

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

0 comments on commit e7bcd17

Please sign in to comment.