Skip to content

Commit

Permalink
check kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed Apr 2, 2024
1 parent 8a28d7e commit 4560ae9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion instructor/messages_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ async def __call__(


def messages_middleware(func: Callable) -> MessageMiddleware:
import inspect

if "messages" not in inspect.signature(func).parameters:
raise ValueError("`messages` must be a parameter of the middleware function")

class _Middleware(MessageMiddleware):
def __call__(
self, messages: List[ChatCompletionMessageParam]
) -> List[ChatCompletionMessageParam]:
return func(messages)
return func(messages=messages)

return _Middleware()

0 comments on commit 4560ae9

Please sign in to comment.