Skip to content

Commit

Permalink
Add experimental marker
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Feb 26, 2024
1 parent d3581d5 commit abb8098
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
InitResourceContext,
OpExecutionContext,
)
from dagster._annotations import experimental
from dagster._core.errors import (
DagsterInvariantViolationError,
)
Expand All @@ -36,7 +37,7 @@ class ApiEndpointClassesEnum(Enum):
context_to_counters = WeakKeyDictionary()


def add_to_asset_metadata(
def _add_to_asset_metadata(
context: AssetExecutionContext, usage_metadata: dict, output_name: Optional[str]
):
if context not in context_to_counters:
Expand All @@ -48,6 +49,7 @@ def add_to_asset_metadata(
context.add_output_metadata(dict(counters), output_name)


@experimental
def with_usage_metadata(context: AssetExecutionContext, output_name: Optional[str], func):
"""This wrapper can be used on any endpoint of the
`openai library <https://github.com/openai/openai-python>`
Expand Down Expand Up @@ -132,13 +134,14 @@ def wrapper(*args, **kwargs):
}
if hasattr(usage, "completion_tokens"):
usage_metadata["openai.completion_tokens"] = usage.completion_tokens
add_to_asset_metadata(context, usage_metadata, output_name)
_add_to_asset_metadata(context, usage_metadata, output_name)

return response

return wrapper


@experimental
class OpenAIResource(ConfigurableResource):
"""This resource is wrapper over the
`openai library <https://github.com/openai/openai-python>`_.
Expand Down

0 comments on commit abb8098

Please sign in to comment.