Skip to content

Commit

Permalink
feat(api): add usage to runs and run steps (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Jan 20, 2024
1 parent 05cd753 commit 6c116df
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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`.
"""

0 comments on commit 6c116df

Please sign in to comment.