mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
fix: fix base64 images additional billing
This commit is contained in:
parent
1128f0014f
commit
b95bf94503
@ -20,7 +20,7 @@ func formatMessages(props *ChatProps) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
props.Buffer.AddImage(obj)
|
||||
props.Buffer.AddImage(obj, url)
|
||||
|
||||
return &MessageContent{
|
||||
Type: "image_url",
|
||||
|
@ -18,7 +18,7 @@ func formatMessages(props *ChatProps) interface{} {
|
||||
if err != nil {
|
||||
globals.Info(fmt.Sprintf("cannot process image: %s (source: %s)", err.Error(), url))
|
||||
} else {
|
||||
props.Buffer.AddImage(obj)
|
||||
props.Buffer.AddImage(obj, url)
|
||||
}
|
||||
|
||||
return &MessageContent{
|
||||
|
@ -58,10 +58,15 @@ func (b *Buffer) GetChunk() string {
|
||||
return b.Latest
|
||||
}
|
||||
|
||||
func (b *Buffer) AddImage(image *Image) {
|
||||
func (b *Buffer) AddImage(image *Image, source string) {
|
||||
b.Images = append(b.Images, *image)
|
||||
|
||||
if b.Charge.IsBillingType(globals.TokenBilling) {
|
||||
b.Quota += float32(image.CountTokens(b.Model)) * b.Charge.GetInput()
|
||||
|
||||
// remove tokens from image source
|
||||
b.Quota -= CountInputToken(b.Charge, b.Model, []globals.Message{{Content: source, Role: globals.User}})
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) GetImages() Images {
|
||||
|
Loading…
Reference in New Issue
Block a user