Skip to content

Conversation

@ilayaperumalg
Copy link
Member

  • Remove model specific Usage implementations
  • Add Object getNativeUsage() to Usage interface
    • This will allow the model specific Usage data to be returned
    • At the client side, client needs to cast the return type of getNativeUsage into the corresponding Usage returned by the model API
  • Rename generationTokens to completionTokens
    • Since completion token name is more common among the models, renaming generation tokens into completion tokens
  • Change the prompt, completion and total token return types to Integer
  • Use DefaultUsage for most of the model specific usage handling
    • When initializing set the native usage to the model specific usage type

 - Remove model specific Usage implementations
 - Add `Object getNativeUsage()` to Usage interface
   - This will allow the model specific Usage data to be returned
   - At the client side, client needs to cast the return type of `getNativeUsage` into the corresponding Usage returned by the model API
 - Rename `generationTokens` to `completionTokens`
   - Since `completion` token name is more common among the models, renaming generation tokens into completion tokens
 - Change the prompt, completion and total token return types to Integer
 - Use DefaultUsage for most of the model specific usage handling
    - When initializing set the native usage to the model specific usage type

Resolves spring-projects#1407
public DefaultUsage(@JsonProperty("promptTokens") Integer promptTokens,
@JsonProperty("completionTokens") Integer completionTokens,
@JsonProperty("totalTokens") Integer totalTokens) {
this(promptTokens, completionTokens, totalTokens, null);
Copy link
Member

@markpollack markpollack Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native usage argument should not be null but Map.of, even though it is handled later.

DefaultUsage that = (DefaultUsage) o;
return Objects.equals(this.promptTokens, that.promptTokens)
&& Objects.equals(this.generationTokens, that.generationTokens)
&& Objects.equals(this.completionTokens, that.completionTokens)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equals should also include the nativeUsage field in the calculate, as well as for hascode/tostring

private final Long generationTokens;

private final Long totalTokens;
private final int totalTokens;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be Integer no?

* @author Ilayaperumal Gopinathan
* @since 0.7.0
*/
public class EmptyUsage implements Usage {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should think about getting rid of this and use 'new DefaultUsage(0,0)

@markpollack
Copy link
Member

markpollack commented Jan 27, 2025

Added support to ser/deser the native usage object
Changed the json ser/deser approach to use a factory method instead of ctors
Updated equals/hashmap/toString to include native usage object
Added more tests including one for backwards deser from M5 format.
Added upgrade notes to docs

We should discuss getting rid of EmtpyUsage, can call DefaultUsage(0, 0)

mergedin 4b64aa0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants