mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-15 20:53:42 +08:00
✨ add: add images api
This commit is contained in:
@@ -117,7 +117,7 @@ func SendRequest(req *http.Request, response any, outputResp bool) (*http.Respon
|
||||
// 将响应体重新写入 resp.Body
|
||||
resp.Body = io.NopCloser(&buf)
|
||||
} else {
|
||||
err = DecodeResponse(resp.Body, nil)
|
||||
err = DecodeResponse(resp.Body, response)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, types.ErrorWrapper(err, "decode_response_failed", http.StatusInternalServerError)
|
||||
|
||||
@@ -222,6 +222,8 @@ const (
|
||||
RelayModeEmbeddings
|
||||
RelayModeModerations
|
||||
RelayModeImagesGenerations
|
||||
RelayModeImagesEdit
|
||||
RelayModeImagesVariations
|
||||
RelayModeEdits
|
||||
RelayModeAudioSpeech
|
||||
RelayModeAudioTranscription
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -107,3 +108,21 @@ func CountTokenText(text string, model string) int {
|
||||
tokenEncoder := getTokenEncoder(model)
|
||||
return getTokenNum(tokenEncoder, text)
|
||||
}
|
||||
|
||||
func CountTokenImage(imageRequest types.ImageRequest) (int, error) {
|
||||
imageCostRatio, hasValidSize := DalleSizeRatios[imageRequest.Model][imageRequest.Size]
|
||||
|
||||
if hasValidSize {
|
||||
if imageRequest.Quality == "hd" && imageRequest.Model == "dall-e-3" {
|
||||
if imageRequest.Size == "1024x1024" {
|
||||
imageCostRatio *= 2
|
||||
} else {
|
||||
imageCostRatio *= 1.5
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 0, errors.New("size not supported for this image model")
|
||||
}
|
||||
|
||||
return int(imageCostRatio*1000) * imageRequest.N, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user