Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions controller/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ func UpdateOption(c *gin.Context) {
})
return
}
case "CreateCacheRatio":
err = ratio_setting.UpdateCreateCacheRatioByJSONString(option.Value.(string))
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "缓存创建倍率设置失败: " + err.Error(),
})
return
}
case "ModelRequestRateLimitGroup":
err = setting.CheckModelRequestRateLimitGroup(option.Value.(string))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions model/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func InitOptionMap() {
common.OptionMap["ModelRatio"] = ratio_setting.ModelRatio2JSONString()
common.OptionMap["ModelPrice"] = ratio_setting.ModelPrice2JSONString()
common.OptionMap["CacheRatio"] = ratio_setting.CacheRatio2JSONString()
common.OptionMap["CreateCacheRatio"] = ratio_setting.CreateCacheRatio2JSONString()
common.OptionMap["GroupRatio"] = ratio_setting.GroupRatio2JSONString()
common.OptionMap["GroupGroupRatio"] = ratio_setting.GroupGroupRatio2JSONString()
common.OptionMap["UserUsableGroups"] = setting.UserUsableGroups2JSONString()
Expand Down Expand Up @@ -427,6 +428,8 @@ func updateOptionMap(key string, value string) (err error) {
err = ratio_setting.UpdateModelPriceByJSONString(value)
case "CacheRatio":
err = ratio_setting.UpdateCacheRatioByJSONString(value)
case "CreateCacheRatio":
err = ratio_setting.UpdateCreateCacheRatioByJSONString(value)
case "ImageRatio":
err = ratio_setting.UpdateImageRatioByJSONString(value)
case "AudioRatio":
Expand Down
40 changes: 39 additions & 1 deletion setting/ratio_setting/cache_ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ var defaultCreateCacheRatio = map[string]float64{
var cacheRatioMap map[string]float64
var cacheRatioMapMutex sync.RWMutex

var createCacheRatioMap map[string]float64
var createCacheRatioMapMutex sync.RWMutex

// GetCacheRatioMap returns the cache ratio map
func GetCacheRatioMap() map[string]float64 {
cacheRatioMapMutex.RLock()
Expand All @@ -119,6 +122,17 @@ func CacheRatio2JSONString() string {
return string(jsonBytes)
}

// CreateCacheRatio2JSONString converts the create cache ratio map to a JSON string
func CreateCacheRatio2JSONString() string {
createCacheRatioMapMutex.RLock()
defer createCacheRatioMapMutex.RUnlock()
jsonBytes, err := json.Marshal(createCacheRatioMap)
if err != nil {
common.SysLog("error marshalling create cache ratio: " + err.Error())
}
return string(jsonBytes)
}

// UpdateCacheRatioByJSONString updates the cache ratio map from a JSON string
func UpdateCacheRatioByJSONString(jsonStr string) error {
cacheRatioMapMutex.Lock()
Expand All @@ -131,6 +145,18 @@ func UpdateCacheRatioByJSONString(jsonStr string) error {
return err
}

// UpdateCreateCacheRatioByJSONString updates the create cache ratio map from a JSON string
func UpdateCreateCacheRatioByJSONString(jsonStr string) error {
createCacheRatioMapMutex.Lock()
defer createCacheRatioMapMutex.Unlock()
createCacheRatioMap = make(map[string]float64)
err := json.Unmarshal([]byte(jsonStr), &createCacheRatioMap)
if err == nil {
InvalidateExposedDataCache()
}
return err
}

// GetCacheRatio returns the cache ratio for a model
func GetCacheRatio(name string) (float64, bool) {
cacheRatioMapMutex.RLock()
Expand All @@ -143,7 +169,9 @@ func GetCacheRatio(name string) (float64, bool) {
}

func GetCreateCacheRatio(name string) (float64, bool) {
ratio, ok := defaultCreateCacheRatio[name]
createCacheRatioMapMutex.RLock()
defer createCacheRatioMapMutex.RUnlock()
ratio, ok := createCacheRatioMap[name]
if !ok {
return 1.25, false // Default to 1.25 if not found
}
Expand All @@ -159,3 +187,13 @@ func GetCacheRatioCopy() map[string]float64 {
}
return copyMap
}

func GetCreateCacheRatioCopy() map[string]float64 {
createCacheRatioMapMutex.RLock()
defer createCacheRatioMapMutex.RUnlock()
copyMap := make(map[string]float64, len(createCacheRatioMap))
for k, v := range createCacheRatioMap {
copyMap[k] = v
}
return copyMap
}
9 changes: 5 additions & 4 deletions setting/ratio_setting/exposed_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ func GetExposedData() gin.H {
return cloneGinH(c.data)
}
newData := gin.H{
"model_ratio": GetModelRatioCopy(),
"completion_ratio": GetCompletionRatioCopy(),
"cache_ratio": GetCacheRatioCopy(),
"model_price": GetModelPriceCopy(),
"model_ratio": GetModelRatioCopy(),
"completion_ratio": GetCompletionRatioCopy(),
"cache_ratio": GetCacheRatioCopy(),
"create_cache_ratio": GetCreateCacheRatioCopy(),
"model_price": GetModelPriceCopy(),
}
exposedData.Store(&exposedCache{
data: newData,
Expand Down
5 changes: 5 additions & 0 deletions setting/ratio_setting/model_ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ func InitRatioSettings() {
cacheRatioMap = defaultCacheRatio
cacheRatioMapMutex.Unlock()

// Initialize createCacheRatioMap (5m cache creation ratio)
createCacheRatioMapMutex.Lock()
createCacheRatioMap = defaultCreateCacheRatio
createCacheRatioMapMutex.Unlock()

// initialize imageRatioMap
imageRatioMapMutex.Lock()
imageRatioMap = defaultImageRatio
Expand Down
1 change: 1 addition & 0 deletions web/src/components/settings/RatioSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const RatioSetting = () => {
ModelPrice: '',
ModelRatio: '',
CacheRatio: '',
CreateCacheRatio: '',
CompletionRatio: '',
GroupRatio: '',
GroupGroupRatio: '',
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "Tip: {key} in the link will be replaced with the API key, {address} will be replaced with the server address",
"提示价格:{{symbol}}{{price}} / 1M tokens": "Prompt price: {{symbol}}{{price}} / 1M tokens",
"提示缓存倍率": "Prompt cache ratio",
"缓存创建倍率": "Cache creation ratio",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "Defaults to the 5m cache creation ratio; the 1h cache creation ratio is computed by fixed multiplication (currently 1.6x)",
"搜索供应商": "Search vendor",
"搜索关键字": "Search keywords",
"搜索失败": "Search failed",
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "Astuce : {key} dans le lien sera remplacé par la clé API, {address} sera remplacé par l'adresse du serveur",
"提示价格:{{symbol}}{{price}} / 1M tokens": "Prix d'invite : {{symbol}}{{price}} / 1M tokens",
"提示缓存倍率": "Ratio de cache d'invite",
"缓存创建倍率": "Ratio de création du cache",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "Par défaut, le ratio de création de cache 5m est utilisé ; le ratio de création de cache 1h est calculé via une multiplication fixe (actuellement 1.6x)",
"搜索供应商": "Rechercher un fournisseur",
"搜索关键字": "Rechercher des mots-clés",
"搜索失败": "Search failed",
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "ヒント:リンク内の{key}はAPIキーに、{address}はサーバーURLに置換されます",
"提示价格:{{symbol}}{{price}} / 1M tokens": "プロンプト料金:{{symbol}}{{price}} / 1M tokens",
"提示缓存倍率": "プロンプトキャッシュ倍率",
"缓存创建倍率": "キャッシュ作成倍率",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "デフォルトは5mのキャッシュ作成倍率です。1hのキャッシュ作成倍率は固定乗数で自動計算されます(現在は1.6倍)",
"搜索供应商": "プロバイダーで検索",
"搜索关键字": "検索キーワード",
"搜索失败": "Search failed",
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "Промпт: {key} в ссылке будет заменен на API-ключ, {address} будет заменен на адрес сервера",
"提示价格:{{symbol}}{{price}} / 1M tokens": "Цена промпта: {{symbol}}{{price}} / 1M токенов",
"提示缓存倍率": "Коэффициент кэша промптов",
"缓存创建倍率": "Коэффициент создания кэша",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "По умолчанию используется коэффициент создания кэша 5m; коэффициент создания кэша 1h автоматически вычисляется фиксированным умножением (сейчас 1.6x)",
"搜索供应商": "Поиск поставщиков",
"搜索关键字": "Поиск по ключевым словам",
"搜索失败": "Search failed",
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "Mẹo: {key} trong liên kết sẽ được thay thế bằng khóa API, {address} sẽ được thay thế bằng địa chỉ máy chủ",
"提示价格:{{symbol}}{{price}} / 1M tokens": "Giá gợi ý: {{symbol}}{{price}} / 1M tokens",
"提示缓存倍率": "Tỷ lệ bộ nhớ đệm gợi ý",
"缓存创建倍率": "Tỷ lệ tạo bộ nhớ đệm",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "Mặc định dùng tỷ lệ tạo bộ nhớ đệm 5m; tỷ lệ tạo bộ nhớ đệm 1h được tự động tính bằng phép nhân cố định (hiện là 1.6x)",
"搜索供应商": "Tìm kiếm nhà cung cấp",
"搜索关键字": "Từ khóa tìm kiếm",
"搜索失败": "Search failed",
Expand Down
2 changes: 2 additions & 0 deletions web/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@
"提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址": "提示:链接中的{key}将被替换为API密钥,{address}将被替换为服务器地址",
"提示价格:{{symbol}}{{price}} / 1M tokens": "提示价格:{{symbol}}{{price}} / 1M tokens",
"提示缓存倍率": "提示缓存倍率",
"缓存创建倍率": "缓存创建倍率",
"默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)": "默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)",
"搜索供应商": "搜索供应商",
"搜索关键字": "搜索关键字",
"搜索失败": "搜索失败",
Expand Down
25 changes: 25 additions & 0 deletions web/src/pages/Setting/Ratio/ModelRatioSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function ModelRatioSettings(props) {
ModelPrice: '',
ModelRatio: '',
CacheRatio: '',
CreateCacheRatio: '',
CompletionRatio: '',
ImageRatio: '',
AudioRatio: '',
Expand Down Expand Up @@ -200,6 +201,30 @@ export default function ModelRatioSettings(props) {
/>
</Col>
</Row>
<Row gutter={16}>
<Col xs={24} sm={16}>
<Form.TextArea
label={t('缓存创建倍率')}
extraText={t(
'默认为 5m 缓存创建倍率;1h 缓存创建倍率按固定乘法自动计算(当前为 1.6x)',
)}
placeholder={t('为一个 JSON 文本,键为模型名称,值为倍率')}
field={'CreateCacheRatio'}
autosize={{ minRows: 6, maxRows: 12 }}
trigger='blur'
stopValidateWithError
rules={[
{
validator: (rule, value) => verifyJSON(value),
message: '不是合法的 JSON 字符串',
},
]}
onChange={(value) =>
setInputs({ ...inputs, CreateCacheRatio: value })
}
/>
</Col>
</Row>
<Row gutter={16}>
<Col xs={24} sm={16}>
<Form.TextArea
Expand Down