File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 66
77from agentex .lib .types .llm_messages import (
88 Delta ,
9+ Usage ,
910 Choice ,
1011 ToolCall ,
1112 Completion ,
@@ -21,6 +22,8 @@ def _concat_chunks(_a: None, b: Any):
2122@_concat_chunks .register
2223def _ (a : Completion , b : Completion ) -> Completion :
2324 a .choices = [_concat_chunks (* c ) for c in zip (a .choices , b .choices , strict = False )]
25+ a .usage = _concat_chunks (a .usage , b .usage )
26+
2427 return a
2528
2629
@@ -35,6 +38,17 @@ def _(a: Choice, b: Choice) -> Choice:
3538 a .finish_reason = a .finish_reason or b .finish_reason
3639 return a
3740
41+ @_concat_chunks .register
42+ def _ (a : Usage | None , b : Usage | None ) -> Usage | None :
43+ if a is not None and b is not None :
44+ return Usage (
45+ prompt_tokens = a .prompt_tokens + b .prompt_tokens ,
46+ completion_tokens = a .completion_tokens + b .completion_tokens ,
47+ total_tokens = a .total_tokens + b .total_tokens ,
48+ )
49+ else :
50+ return a or b
51+
3852
3953@_concat_chunks .register
4054def _ (a : Delta , b : Delta ) -> Delta :
You can’t perform that action at this time.
0 commit comments