feat: refactor AwsClaude to Aws to support both llama3 and claude (#1601)

* feat: refactor AwsClaude to Aws to support both llama3 and claude

* fix: aws llama3 ratio
This commit is contained in:
Qiying Wang
2024-07-06 13:19:41 +08:00
committed by GitHub
parent e090e76c86
commit 720fe2dfeb
18 changed files with 598 additions and 91 deletions

View File

@@ -2,6 +2,7 @@ package ratio
import (
"encoding/json"
"fmt"
"strings"
"github.com/songquanpeng/one-api/common/logger"
@@ -169,6 +170,9 @@ var ModelRatio = map[string]float64{
"step-1v-32k": 0.024 * RMB,
"step-1-32k": 0.024 * RMB,
"step-1-200k": 0.15 * RMB,
// aws llama3 https://aws.amazon.com/cn/bedrock/pricing/
"llama3-8b-8192(33)": 0.0003 / 0.002, // $0.0003 / 1K tokens
"llama3-70b-8192(33)": 0.00265 / 0.002, // $0.00265 / 1K tokens
// https://cohere.com/pricing
"command": 0.5,
"command-nightly": 0.5,
@@ -185,7 +189,11 @@ var ModelRatio = map[string]float64{
"deepl-ja": 25.0 / 1000 * USD,
}
var CompletionRatio = map[string]float64{}
var CompletionRatio = map[string]float64{
// aws llama3
"llama3-8b-8192(33)": 0.0006 / 0.0003,
"llama3-70b-8192(33)": 0.0035 / 0.00265,
}
var DefaultModelRatio map[string]float64
var DefaultCompletionRatio map[string]float64
@@ -234,22 +242,28 @@ func UpdateModelRatioByJSONString(jsonStr string) error {
return json.Unmarshal([]byte(jsonStr), &ModelRatio)
}
func GetModelRatio(name string) float64 {
func GetModelRatio(name string, channelType int) float64 {
if strings.HasPrefix(name, "qwen-") && strings.HasSuffix(name, "-internet") {
name = strings.TrimSuffix(name, "-internet")
}
if strings.HasPrefix(name, "command-") && strings.HasSuffix(name, "-internet") {
name = strings.TrimSuffix(name, "-internet")
}
ratio, ok := ModelRatio[name]
if !ok {
ratio, ok = DefaultModelRatio[name]
model := fmt.Sprintf("%s(%d)", name, channelType)
if ratio, ok := ModelRatio[model]; ok {
return ratio
}
if !ok {
logger.SysError("model ratio not found: " + name)
return 30
if ratio, ok := DefaultModelRatio[model]; ok {
return ratio
}
return ratio
if ratio, ok := ModelRatio[name]; ok {
return ratio
}
if ratio, ok := DefaultModelRatio[name]; ok {
return ratio
}
logger.SysError("model ratio not found: " + name)
return 30
}
func CompletionRatio2JSONString() string {
@@ -265,7 +279,17 @@ func UpdateCompletionRatioByJSONString(jsonStr string) error {
return json.Unmarshal([]byte(jsonStr), &CompletionRatio)
}
func GetCompletionRatio(name string) float64 {
func GetCompletionRatio(name string, channelType int) float64 {
if strings.HasPrefix(name, "qwen-") && strings.HasSuffix(name, "-internet") {
name = strings.TrimSuffix(name, "-internet")
}
model := fmt.Sprintf("%s(%d)", name, channelType)
if ratio, ok := CompletionRatio[model]; ok {
return ratio
}
if ratio, ok := DefaultCompletionRatio[model]; ok {
return ratio
}
if ratio, ok := CompletionRatio[name]; ok {
return ratio
}