Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add usage to runs and run steps #1090

Merged
merged 1 commit into from
Jan 20, 2024
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
19 changes: 19 additions & 0 deletions src/openai/types/beta/threads/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ToolAssistantToolsCode",
"ToolAssistantToolsRetrieval",
"ToolAssistantToolsFunction",
"Usage",
]


Expand Down Expand Up @@ -61,6 +62,17 @@ class ToolAssistantToolsFunction(BaseModel):
Tool = Union[ToolAssistantToolsCode, ToolAssistantToolsRetrieval, ToolAssistantToolsFunction]


class Usage(BaseModel):
completion_tokens: int
"""Number of completion tokens used over the course of the run."""

prompt_tokens: int
"""Number of prompt tokens used over the course of the run."""

total_tokens: int
"""Total number of tokens used (prompt + completion)."""


class Run(BaseModel):
id: str
"""The identifier, which can be referenced in API endpoints."""
Expand Down Expand Up @@ -152,3 +164,10 @@ class Run(BaseModel):
[assistant](https://platform.openai.com/docs/api-reference/assistants) used for
this run.
"""

usage: Optional[Usage] = None
"""Usage statistics related to the run.

This value will be `null` if the run is not in a terminal state (i.e.
`in_progress`, `queued`, etc.).
"""
19 changes: 18 additions & 1 deletion src/openai/types/beta/threads/runs/run_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .tool_calls_step_details import ToolCallsStepDetails
from .message_creation_step_details import MessageCreationStepDetails

__all__ = ["RunStep", "LastError", "StepDetails"]
__all__ = ["RunStep", "LastError", "StepDetails", "Usage"]


class LastError(BaseModel):
Expand All @@ -22,6 +22,17 @@ class LastError(BaseModel):
StepDetails = Union[MessageCreationStepDetails, ToolCallsStepDetails]


class Usage(BaseModel):
completion_tokens: int
"""Number of completion tokens used over the course of the run step."""

prompt_tokens: int
"""Number of prompt tokens used over the course of the run step."""

total_tokens: int
"""Total number of tokens used (prompt + completion)."""


class RunStep(BaseModel):
id: str
"""The identifier of the run step, which can be referenced in API endpoints."""
Expand Down Expand Up @@ -91,3 +102,9 @@ class RunStep(BaseModel):

type: Literal["message_creation", "tool_calls"]
"""The type of run step, which can be either `message_creation` or `tool_calls`."""

usage: Optional[Usage] = None
"""Usage statistics related to the run step.
This value will be `null` while the run step's status is `in_progress`.
"""