Skip to content

Conversation

@ilayaperumalg
Copy link
Member

  • This PR introduces Usage accessor to retrieve the usage metadata fields from the ChatCompletion Usage response metadata - Having UsageAccessor would help enable the clients getting access to the entire metadata instead of pre-defined set of metadata
  • Add utility method to UsageUtils to parseLong value from the metadata value object
  • Add tests

  - This PR introduces Usage accessor to retrieve the usage metadata fields from the ChatCompletion Usage response metadata
     - Having UsageAccessor would help enable the clients getting access to the entire metadata instead of pre-defined set of metadata
  - Add utility method to UsageUtils to parseLong value from the metadata value object
  - Add tests
@ilayaperumalg ilayaperumalg force-pushed the anthropic-usage-accessor branch from e06d9db to ac32938 Compare January 15, 2025 12:29
}

@Override
public String toString() {
Copy link
Member Author

Choose a reason for hiding this comment

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

should be removed as this is implicit.

return UsageUtils.parseLong(this.usage.get(CACHE_READ_INPUT_TOKENS));
}

public Map<String, Object> getUsage() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Rename this to getUsageData()

*
* @author Ilayaperumal Gopinathan
*/
public record AnthropicUsageAccessor(Map<String, Object> usage) implements Usage {
Copy link
Member Author

Choose a reason for hiding this comment

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

Can be simplified to AnthropicUsage

*
* @author Ilayaperumal Gopinathan
*/
public record AnthropicUsageAccessor(Map<String, Object> usage) implements Usage {
Copy link
Member Author

Choose a reason for hiding this comment

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

For the extensibility let's not make this record

*/
public static Long parseLong(Object value) {
if (value == null) {
return null;
Copy link
Member Author

@ilayaperumalg ilayaperumalg Jan 15, 2025

Choose a reason for hiding this comment

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

If null, return -1

@markpollack
Copy link
Member

Closing this PR as the design to return the 'native' usage classes with a method Object getNativeUsage on the Usage interface was preferred.

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