mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-13 20:03:44 +08:00
refactor: add GetRatio to Adaptor
This commit is contained in:
@@ -3,16 +3,18 @@ package zhipu
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/songquanpeng/one-api/common/helper"
|
||||
"github.com/songquanpeng/one-api/relay/adaptor"
|
||||
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
||||
"github.com/songquanpeng/one-api/relay/billing/ratio"
|
||||
"github.com/songquanpeng/one-api/relay/meta"
|
||||
"github.com/songquanpeng/one-api/relay/model"
|
||||
"github.com/songquanpeng/one-api/relay/relaymode"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Adaptor struct {
|
||||
@@ -140,8 +142,12 @@ func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) (*EmbeddingRequ
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Adaptor) GetRatio(meta *meta.Meta) *ratio.Ratio {
|
||||
return adaptor.GetRatioHelper(meta, RatioMap)
|
||||
}
|
||||
|
||||
func (a *Adaptor) GetModelList() []string {
|
||||
return ModelList
|
||||
return adaptor.GetModelListHelper(RatioMap)
|
||||
}
|
||||
|
||||
func (a *Adaptor) GetChannelName() string {
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
package zhipu
|
||||
|
||||
var ModelList = []string{
|
||||
"chatglm_turbo", "chatglm_pro", "chatglm_std", "chatglm_lite",
|
||||
"glm-4", "glm-4v", "glm-3-turbo", "embedding-2",
|
||||
"cogview-3",
|
||||
import "github.com/songquanpeng/one-api/relay/billing/ratio"
|
||||
|
||||
var RatioMap = map[string]ratio.Ratio{
|
||||
"glm-zero-preview": {Input: 0.01 * ratio.RMB, Output: 0.01 * ratio.RMB},
|
||||
"glm-4-plus": {Input: 0.05 * ratio.RMB, Output: 0.05 * ratio.RMB},
|
||||
"glm-4-0520": {Input: 0.1 * ratio.RMB, Output: 0.1 * ratio.RMB},
|
||||
"glm-4-airx": {Input: 0.01 * ratio.RMB, Output: 0.01 * ratio.RMB},
|
||||
"glm-4-air": {Input: 0.0005 * ratio.RMB, Output: 0.0005 * ratio.RMB},
|
||||
"glm-4-long": {Input: 0.001 * ratio.RMB, Output: 0.001 * ratio.RMB},
|
||||
"glm-4-flashx": {Input: 0.0001 * ratio.RMB, Output: 0.0001 * ratio.RMB},
|
||||
"glm-4v-plus": {Input: 0.004 * ratio.RMB, Output: 0.004 * ratio.RMB},
|
||||
"glm-4v": {Input: 0.05 * ratio.RMB, Output: 0},
|
||||
"cogview-3-plus": {Input: 0.06 * ratio.RMB, Output: 0},
|
||||
"cogview-3": {Input: 0.1 * ratio.RMB, Output: 0},
|
||||
"cogvideox": {Input: 0.5 * ratio.RMB, Output: 0},
|
||||
"embedding-3": {Input: 0.0005 * ratio.RMB, Output: 0},
|
||||
"embedding-2": {Input: 0.0005 * ratio.RMB, Output: 0},
|
||||
"glm-4-flash": {Input: 0, Output: 0}, // 免费
|
||||
"glm-4v-flash": {Input: 0, Output: 0}, // 免费
|
||||
"cogview-3-flash": {Input: 0, Output: 0}, // 免费
|
||||
"cogvideox-flash": {Input: 0, Output: 0}, // 免费
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package zhipu
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"github.com/songquanpeng/one-api/common/render"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/songquanpeng/one-api/common/render"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/songquanpeng/one-api/common"
|
||||
@@ -268,6 +269,9 @@ func EmbeddingsHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithSta
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
c.Writer.WriteHeader(resp.StatusCode)
|
||||
_, err = c.Writer.Write(jsonResponse)
|
||||
if err != nil {
|
||||
return openai.ErrorWrapper(err, "write_response_body_failed", http.StatusInternalServerError), nil
|
||||
}
|
||||
return nil, &fullTextResponse.Usage
|
||||
}
|
||||
|
||||
@@ -276,11 +280,7 @@ func embeddingResponseZhipu2OpenAI(response *EmbeddingResponse) *openai.Embeddin
|
||||
Object: "list",
|
||||
Data: make([]openai.EmbeddingResponseItem, 0, len(response.Embeddings)),
|
||||
Model: response.Model,
|
||||
Usage: model.Usage{
|
||||
PromptTokens: response.PromptTokens,
|
||||
CompletionTokens: response.CompletionTokens,
|
||||
TotalTokens: response.Usage.TotalTokens,
|
||||
},
|
||||
Usage: response.Usage,
|
||||
}
|
||||
|
||||
for _, item := range response.Embeddings {
|
||||
|
||||
Reference in New Issue
Block a user