WordPress / WordPress/php-ai-client

Improve handling of unprovided usage statistics

Open
#158 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[Priority] Low
Dominant language
PHP
Stars
308
Forks
84
Avg merge
7d 21h
Merged PRs (30d)
2

Description

The TokenUsage DTO right now has a couple of limitations to it:

  1. It can't be null in the GenerativeAiResult DTO, so it's assumed to always be supplied
  2. The individual properties of TokenUsage are all non-nullable, so they must also be supplied

The work around for this has been to do something like new TokenUsage(0, 0, 0) to indicate the values weren't provided. This is confusing and makes it hard to distinguish between statistics not being provided versus actual values. This will become even more important if we add additional properties in the future that only some providers support.

I recommend making the properties nullable as well as the TokenUsage instance nullable in GenerativeAiResult.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TokenUsage and GenerativeAiResult DTO definitions and the tests that cover their construction or serialization. Trace how missing usage statistics are currently represented, then update the DTO contracts so both the TokenUsage value and its individual properties can be absent. Done means callers can distinguish unprovided statistics from zero values and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.