@@ -11,7 +11,11 @@ use lazy_static::lazy_static;
11
11
use regex:: Regex ;
12
12
use serde:: { Deserialize , Serialize } ;
13
13
14
- use crate :: agent:: { generator:: Message , state:: SharedState , Invocation } ;
14
+ use crate :: agent:: {
15
+ generator:: { ChatResponse , Message } ,
16
+ state:: SharedState ,
17
+ Invocation ,
18
+ } ;
15
19
16
20
use super :: { ChatOptions , Client } ;
17
21
@@ -109,7 +113,7 @@ impl Client for GroqClient {
109
113
& self ,
110
114
state : SharedState ,
111
115
options : & ChatOptions ,
112
- ) -> anyhow:: Result < ( String , Vec < Invocation > ) > {
116
+ ) -> anyhow:: Result < ChatResponse > {
113
117
let mut chat_history = vec ! [
114
118
groq_api_rs:: completion:: message:: Message :: SystemMessage {
115
119
role: Some ( "system" . to_string( ) ) ,
@@ -247,9 +251,9 @@ impl Client for GroqClient {
247
251
return Err ( error) ;
248
252
}
249
253
250
- let choice = match resp. unwrap ( ) {
254
+ let ( response , choice) = match resp. unwrap ( ) {
251
255
groq_api_rs:: completion:: client:: CompletionOption :: NonStream ( resp) => {
252
- resp. choices . first ( ) . unwrap ( ) . to_owned ( )
256
+ ( resp. clone ( ) , resp . choices . first ( ) . unwrap ( ) . to_owned ( ) )
253
257
}
254
258
groq_api_rs:: completion:: client:: CompletionOption :: Stream ( _) => {
255
259
return Err ( anyhow ! ( "Groq streaming is not supported yet, if this happens please open an issue on GitHub" ) ) ;
@@ -298,7 +302,14 @@ impl Client for GroqClient {
298
302
}
299
303
}
300
304
301
- Ok ( ( content, invocations) )
305
+ Ok ( ChatResponse {
306
+ content,
307
+ invocations,
308
+ usage : Some ( super :: Usage {
309
+ input_tokens : response. usage . prompt_tokens ,
310
+ output_tokens : response. usage . completion_tokens ,
311
+ } ) ,
312
+ } )
302
313
}
303
314
}
304
315
0 commit comments