diff --git a/adapter/azure/processor.go b/adapter/azure/processor.go index 797f652..3b0e30e 100644 --- a/adapter/azure/processor.go +++ b/adapter/azure/processor.go @@ -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", diff --git a/adapter/chatgpt/processor.go b/adapter/chatgpt/processor.go index 29baa48..668571a 100644 --- a/adapter/chatgpt/processor.go +++ b/adapter/chatgpt/processor.go @@ -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{ diff --git a/utils/buffer.go b/utils/buffer.go index 483383a..16d0f3b 100644 --- a/utils/buffer.go +++ b/utils/buffer.go @@ -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 {