File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed
Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,12 @@ tests:
3434 role : model
3535 content :
3636 - text : ' {"messages":[{"content":[{"text":"hello"}],"role":"user"}]}'
37+ usage :
38+ inputCharacters : 5
39+ outputCharacters : 59
40+ inputImages : 0
41+ inputVideos : 0
42+ inputAudioFiles : 0
43+ outputImages : 0
44+ outputVideos : 0
45+ outputAudioFiles : 0
Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17- import { genkit , z } from 'genkit' ;
17+ import { MessageData , genkit , z } from 'genkit' ;
18+ import { getBasicUsageStats } from 'genkit/model' ;
1819
1920const ai = genkit ( {
2021 plugins : [ ] ,
@@ -30,16 +31,18 @@ ai.defineModel(
3031 // So swap the order here to match Go.
3132 const m = input . messages [ 0 ] ;
3233 input . messages [ 0 ] = { content : m . content , role : m . role } ;
34+ const message : MessageData = {
35+ role : 'model' ,
36+ content : [
37+ {
38+ text : JSON . stringify ( input ) ,
39+ } ,
40+ ] ,
41+ } ;
3342 return {
3443 finishReason : 'stop' ,
35- message : {
36- role : 'model' ,
37- content : [
38- {
39- text : JSON . stringify ( input ) ,
40- } ,
41- ] ,
42- } ,
44+ message,
45+ usage : getBasicUsageStats ( input . messages , message ) ,
4346 } ;
4447 }
4548) ;
You can’t perform that action at this time.
0 commit comments