fix: fix base64 images additional billing

This commit is contained in:
Zhang Minghan 2024-02-15 17:33:27 +08:00
parent 1128f0014f
commit b95bf94503
3 changed files with 9 additions and 4 deletions

View File

@ -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",

View File

@ -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{

View File

@ -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)
b.Quota += float32(image.CountTokens(b.Model)) * b.Charge.GetInput()
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 {