Skip to content

Commit c8eaf67

Browse files
authored
enhance: add run usage method (#97)
Signed-off-by: Donnie Adams <[email protected]>
1 parent 415de95 commit c8eaf67

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

run.go

+15
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ func (r *Run) ParentCallFrame() (CallFrame, bool) {
118118
return r.calls.ParentCallFrame(), true
119119
}
120120

121+
// Usage returns all the usage for this run.
122+
func (r *Run) Usage() Usage {
123+
var u Usage
124+
r.callsLock.RLock()
125+
defer r.callsLock.RUnlock()
126+
127+
for _, c := range r.calls {
128+
u.CompletionTokens += c.Usage.CompletionTokens
129+
u.PromptTokens += c.Usage.PromptTokens
130+
u.TotalTokens += c.Usage.TotalTokens
131+
}
132+
133+
return u
134+
}
135+
121136
// ErrorOutput returns the stderr output of the gptscript.
122137
// Should only be called after Bytes or Text has returned an error.
123138
func (r *Run) ErrorOutput() string {

0 commit comments

Comments
 (0)