client icon indicating copy to clipboard operation
client copied to clipboard

feat: usageMetadata in GenerateContentResponse

Open xavierandueza opened this issue 1 year ago • 1 comments

Context

Google's GenerateContentResponse includes a "usageMetadata".

The above has reference to 4 attributes of the usageMetadata, however the actual returned response currently only includes the 3 listed here in their API Reference. The raw response was checked and tested to ensure this.

This contains useful information about the:

  • Number of response tokens used
  • Number of tokens in the prompt
  • Total number of tokens.

Changes

This involved the creation of the UsageMetadata class, and modifications to the GenerateContentResponse class.

UsageMetadata Creation

This class implements the UsageMetadata (1.4.1) response as per the Gemini API.

GenerateContentResponse Changes

Integrated the new UsageMetadata class to include these.

xavierandueza avatar Aug 11 '24 03:08 xavierandueza

@aydinfatih and/or @bradleybernard if you could check this out when you get the time that'd be great 👍

xavierandueza avatar Aug 12 '24 01:08 xavierandueza

First of all, thank you very much for your contribution.

I didn't see the tests in this PR. I just did a general update to the package and included this feature, so I'm closing this PR.

https://github.com/google-gemini-php/client/pull/32

aydinfatih avatar Sep 28 '24 14:09 aydinfatih