- 
                Notifications
    You must be signed in to change notification settings 
- Fork 104
Refactor cost computation #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Now we compute the cost once, when we create the turn. The makes a lot of things simpler, e.g. we no longer need to track the variant in `the$tokens`, and unit tests get simpler. I also introduce `Chat$get_cost_details()` (ported from #810) to make it easier to inspect the raw details of a chat. Includes a fix for #804 by logging as part of `Chat$add_turn()`. This breaks #743 in a new way: for now batch chat usage isn't logged at all. But I think it makes sense to fix that in another PR. I've also added `map_tokens()` helper to hide the awkward use of `vapply()` in a few places (and to make the output more consistent)
        
          
                R/chat.R
              
                Outdated
          
        
      | private$provider, | ||
| # TODO: store better representation in Turn object | ||
| exec(tokens, !!!as.list(system@tokens)), | ||
| system@cost | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system here really means assistant, right? Worth fixing that naming now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah that confused me too. Might as well fix now.
        
          
                R/turns.R
              
                Outdated
          
        
      | tokens = c(0, 0, 0), | ||
| duration = NA_real_ | ||
| duration = NA_real_, | ||
| cost = NA_real_ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer tokens and cost to be next to one another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the minor comments are addressed
Now we compute the cost once, when we create the turn. The makes a lot of things simpler, e.g. we no longer need to track the variant in
the$tokens, and unit tests get simpler. I also introduceChat$get_cost_details()(ported from #810) to make it easier to inspect the raw details of a chat.Includes a fix for #804 by logging as part of
Chat$add_turn(). This breaks #743 in a new way: for now batch chat usage isn't logged at all. But I think it makes sense to fix that in another PR.I've also added
map_tokens()helper to hide the awkward use ofvapply()in a few places (and to make the output more consistent)