Skip to content

Commit

Permalink
refactor(runner): update LLM 'tokens_used' to usage (#402)
Browse files Browse the repository at this point in the history
This commit updates the `tokens_used` field in the LLM API spec with
`usage` to make it more compatible with the OpenAI spec.
  • Loading branch information
rickstaa authored Jan 27, 2025
1 parent cd56616 commit a11302b
Show file tree
Hide file tree
Showing 8 changed files with 2,732 additions and 96 deletions.
1,246 changes: 1,246 additions & 0 deletions gateway.openapi.yaml

Large diffs are not rendered by default.

1,390 changes: 1,390 additions & 0 deletions openapi.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions runner/app/pipelines/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async def generate(
index=0
)
],
tokens_used=LLMTokenUsage(
usage=LLMTokenUsage(
prompt_tokens=input_tokens,
completion_tokens=total_tokens,
total_tokens=input_tokens + total_tokens
Expand Down Expand Up @@ -266,7 +266,7 @@ async def generate(
finish_reason="stop"
)
],
tokens_used=LLMTokenUsage(
usage=LLMTokenUsage(
prompt_tokens=input_tokens,
completion_tokens=total_tokens,
total_tokens=input_tokens + total_tokens
Expand Down
2 changes: 1 addition & 1 deletion runner/app/routes/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def llm(
finish_reason="stop"
)
],
tokens_used=last_chunk.tokens_used,
usage=last_chunk.usage,
id=last_chunk.id,
model=last_chunk.model,
created=last_chunk.created
Expand Down
2 changes: 1 addition & 1 deletion runner/app/routes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LLMResponse(BaseModel):
id: str
model: str
created: int
tokens_used: LLMTokenUsage
usage: LLMTokenUsage
choices: List[LLMChoice]


Expand Down
4 changes: 2 additions & 2 deletions runner/gateway.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ components:
created:
type: integer
title: Created
tokens_used:
usage:
$ref: '#/components/schemas/LLMTokenUsage'
choices:
items:
Expand All @@ -958,7 +958,7 @@ components:
- id
- model
- created
- tokens_used
- usage
- choices
title: LLMResponse
LLMTokenUsage:
Expand Down
4 changes: 2 additions & 2 deletions runner/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ components:
created:
type: integer
title: Created
tokens_used:
usage:
$ref: '#/components/schemas/LLMTokenUsage'
choices:
items:
Expand All @@ -1104,7 +1104,7 @@ components:
- id
- model
- created
- tokens_used
- usage
- choices
title: LLMResponse
LLMTokenUsage:
Expand Down
176 changes: 88 additions & 88 deletions worker/runner.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a11302b

Please sign in to comment.