Skip to content

Commit

Permalink
polyfill anext
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebCourier committed Sep 4, 2024
1 parent 8948d94 commit de9f366
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion guardrails/integrations/databricks/ml_flow_instrumentor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import wraps
import inspect
import sys
from typing import (
Any,
AsyncIterable,
Expand Down Expand Up @@ -39,6 +40,10 @@
raise ImportError("Please install mlflow to use this instrumentor")


if sys.version_info.minor < 10:
from guardrails.utils.polyfills import anext


# TODO: Abstract these methods and common logic into a base class
# that can be extended by other instrumentors
class MlFlowInstrumentor:
Expand Down Expand Up @@ -300,7 +305,7 @@ async def trace_async_stream_step_wrapper(
next_exists = True
while next_exists:
try:
res = await anext(gen) # type: ignore
res = await anext(gen)
yield res
except StopIteration:
next_exists = False
Expand Down
2 changes: 2 additions & 0 deletions guardrails/utils/polyfills.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def anext(aiter):
return aiter.__anext__()

0 comments on commit de9f366

Please sign in to comment.