Skip to content

Commit

Permalink
Cleaner error message (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Nov 5, 2024
1 parent 8781a12 commit 0d42ba6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
21 changes: 18 additions & 3 deletions python/langsmith/evaluation/_arunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,24 @@ def _ensure_async_traceable(
target: ATARGET_T,
) -> rh.SupportsLangsmithExtra[[dict], Awaitable]:
if not asyncio.iscoroutinefunction(target):
raise ValueError(
"Target must be an async function. For sync functions, use evaluate."
)
if callable(target):
raise ValueError(
"Target must be an async function. For sync functions, use evaluate."
" Example usage:\n\n"
"async def predict(inputs: dict) -> dict:\n"
" # do work, like chain.invoke(inputs)\n"
" return {...}\n"
"await aevaluate(predict, ...)"
)
else:
raise ValueError(
"Target must be a callable async function. "
"Received a non-callable object. Example usage:\n\n"
"async def predict(inputs: dict) -> dict:\n"
" # do work, like chain.invoke(inputs)\n"
" return {...}\n"
"await aevaluate(predict, ...)"
)
if rh.is_traceable_function(target):
return target # type: ignore
return rh.traceable(name="AsyncTarget")(target)
Expand Down
11 changes: 10 additions & 1 deletion python/langsmith/evaluation/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,16 @@ def _ensure_traceable(
) -> rh.SupportsLangsmithExtra[[dict], dict]:
"""Ensure the target function is traceable."""
if not callable(target):
raise ValueError("Target must be a callable function.")
raise ValueError(
"Target must be a callable function. For example:\n\n"
"def predict(inputs: dict) -> dict:\n"
" # do work, like chain.invoke(inputs)\n"
" return {...}\n\n"
"evaluate(\n"
" predict,\n"
" ...\n"
")"
)
if rh.is_traceable_function(target):
fn = target
else:
Expand Down

0 comments on commit 0d42ba6

Please sign in to comment.