Skip to content
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
9 changes: 8 additions & 1 deletion guardrails/async_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,14 @@ async def _exec(
Returns:
The raw text output from the LLM and the validated output.
"""
api = get_async_llm_ask(llm_api, *args, **kwargs) # type: ignore
api = None

if llm_api is not None or kwargs.get("model") is not None:
api = get_async_llm_ask(llm_api, *args, **kwargs) # type: ignore

if self._output_formatter is not None:
api = self._output_formatter.wrap_async_callable(api) # type: ignore

if kwargs.get("stream", False):
runner = AsyncStreamRunner(
output_type=self._output_type,
Expand Down
11 changes: 10 additions & 1 deletion guardrails/formatters/base_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from guardrails.llm_providers import (
ArbitraryCallable,
AsyncPromptCallableBase,
PromptCallableBase,
)

Expand All @@ -17,7 +18,15 @@ class BaseFormatter(ABC):
@abstractmethod
def wrap_callable(self, llm_callable: PromptCallableBase) -> ArbitraryCallable: ...

@abstractmethod
def wrap_async_callable(
self, llm_callable: PromptCallableBase
) -> AsyncPromptCallableBase: ...


class PassthroughFormatter(BaseFormatter):
def wrap_callable(self, llm_callable: PromptCallableBase):
def wrap_callable(self, llm_callable: PromptCallableBase): # type: ignore
return llm_callable # Noop

def wrap_async_callable(self, llm_callable: PromptCallableBase): # type: ignore
return llm_callable # Noop
3 changes: 3 additions & 0 deletions guardrails/formatters/json_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,6 @@ def fn(
raise ValueError(
"JsonFormatter can only be used with HuggingFace*Callable."
)

def wrap_async_callable(self, llm_callable):
raise NotImplementedError()