Skip to content

Commit

Permalink
Merge pull request lobehub#2 from MartialBE/main
Browse files Browse the repository at this point in the history
merge main
  • Loading branch information
MartialBE authored Nov 5, 2023
2 parents 12499aa + bc7c910 commit ef18eb9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions common/model-ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var ModelRatio = map[string]float64{
"ERNIE-Bot-4": 8.572, // ¥0.12 / 1k tokens
"Embedding-V1": 0.1429, // ¥0.002 / 1k tokens
"PaLM-2": 1,
"chatglm_turbo": 0.3572, // ¥0.005 / 1k tokens
"chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
"chatglm_std": 0.3572, // ¥0.005 / 1k tokens
"chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
Expand Down
6 changes: 4 additions & 2 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"one-api/common"
"one-api/model"
"strconv"
"strings"
"sync"
"time"

"github.com/gin-gonic/gin"
)

func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) {
Expand Down Expand Up @@ -50,6 +50,8 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
}
requestURL += "/v1/chat/completions"
}
// for Cloudflare AI gateway: https://github.com/songquanpeng/one-api/pull/639
requestURL = strings.Replace(requestURL, "/v1/v1", "/v1", 1)

jsonData, err := json.Marshal(request)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions controller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func init() {
Id: "claude-instant-1",
Object: "model",
Created: 1677649963,
OwnedBy: "anturopic",
OwnedBy: "anthropic",
Permission: permission,
Root: "claude-instant-1",
Parent: nil,
Expand All @@ -283,7 +283,7 @@ func init() {
Id: "claude-2",
Object: "model",
Created: 1677649963,
OwnedBy: "anturopic",
OwnedBy: "anthropic",
Permission: permission,
Root: "claude-2",
Parent: nil,
Expand Down Expand Up @@ -333,6 +333,15 @@ func init() {
Root: "PaLM-2",
Parent: nil,
},
{
Id: "chatglm_turbo",
Object: "model",
Created: 1677649963,
OwnedBy: "zhipu",
Permission: permission,
Root: "chatglm_turbo",
Parent: nil,
},
{
Id: "chatglm_pro",
Object: "model",
Expand Down
5 changes: 2 additions & 3 deletions controller/relay-text.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net/http"
"one-api/common"
"one-api/model"
Expand Down Expand Up @@ -414,9 +415,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
completionRatio := common.GetCompletionRatio(textRequest.Model)
promptTokens = textResponse.Usage.PromptTokens
completionTokens = textResponse.Usage.CompletionTokens

quota = promptTokens + int(float64(completionTokens)*completionRatio)
quota = int(float64(quota) * ratio)
quota = int(math.Ceil((float64(promptTokens) + float64(completionTokens)*completionRatio) * ratio))
if ratio != 0 && quota <= 0 {
quota = 1
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/Channel/EditChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const EditChannel = () => {
localModels = ['qwen-turbo', 'qwen-plus', 'text-embedding-v1'];
break;
case 16:
localModels = ['chatglm_pro', 'chatglm_std', 'chatglm_lite'];
localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'];
break;
case 18:
localModels = ['SparkDesk'];
Expand Down

0 comments on commit ef18eb9

Please sign in to comment.