add claude-2, claude-2-100k model

This commit is contained in:
Zhang Minghan 2023-09-24 12:53:51 +08:00
parent 1da27f6611
commit ca2f0c347b
5 changed files with 27 additions and 5 deletions

View File

@ -115,17 +115,20 @@ func StreamRequest(model string, enableReverse bool, messages []types.ChatGPTMes
if enableReverse {
NativeStreamRequest(viper.GetString("openai.reverse"), viper.GetString("openai.pro_endpoint"), viper.GetString("openai.pro"), messages, token, callback)
} else {
NativeStreamRequest(model, viper.GetString("openai.gpt4_endpoint"), viper.GetString("openai.gpt4"), messages, token, callback)
NativeStreamRequest(types.GPT40613, viper.GetString("openai.gpt4_endpoint"), viper.GetString("openai.gpt4"), messages, token, callback)
}
case types.GPT432k,
types.GPT432k0613,
types.GPT432k0314:
NativeStreamRequest(model, viper.GetString("openai.gpt4_endpoint"), viper.GetString("openai.gpt4"), messages, token, callback)
NativeStreamRequest(types.GPT432k0613, viper.GetString("openai.gpt4_endpoint"), viper.GetString("openai.gpt4"), messages, token, callback)
case types.GPT3Turbo16k,
types.GPT3Turbo16k0301,
types.GPT3Turbo16k0613:
NativeStreamRequest(types.GPT3Turbo16k, viper.GetString("openai.user_endpoint"), viper.GetString("openai.user"), messages, token, callback)
NativeStreamRequest(types.GPT3Turbo16k0613, viper.GetString("openai.user_endpoint"), viper.GetString("openai.user"), messages, token, callback)
case types.Claude2,
types.Claude2100k:
NativeStreamRequest(model, viper.GetString("claude.endpoint"), viper.GetString("claude.key"), messages, token, callback)
default:
NativeStreamRequest(types.GPT3Turbo, viper.GetString("openai.anonymous_endpoint"), viper.GetString("openai.anonymous"), messages, token, callback)
NativeStreamRequest(types.GPT3Turbo0613, viper.GetString("openai.anonymous_endpoint"), viper.GetString("openai.anonymous"), messages, token, callback)
}
}

View File

@ -1,7 +1,7 @@
import axios from "axios";
export const version: string = "2.8.0";
export const deploy: boolean = false;
export const deploy: boolean = true;
export let rest_api: string = "http://localhost:8094";
export let ws_api: string = "ws://localhost:8094";

View File

@ -37,6 +37,8 @@ func CountInputToken(model string, v []types.ChatGPTMessage) float32 {
return float32(utils.CountTokenPrice(v, model)) / 1000 * 2.1
case types.GPT432k:
return float32(utils.CountTokenPrice(v, model)) / 1000 * 2.1 * 2
case types.Claude2, types.Claude2100k:
return 0
default:
return 0
}
@ -52,6 +54,8 @@ func CountOutputToken(model string, t int) float32 {
return float32(t*utils.GetWeightByModel(model)) / 1000 * 4.3
case types.GPT432k:
return float32(t*utils.GetWeightByModel(model)) / 1000 * 8.6
case types.Claude2, types.Claude2100k:
return 0
default:
return 0
}

View File

@ -42,6 +42,11 @@ var GPT432kArray = []string{
GPT432k0613,
}
var ClaudeModelArray = []string{
Claude2,
Claude2100k,
}
func in(value string, slice []string) bool {
for _, item := range slice {
if item == value {
@ -58,3 +63,7 @@ func IsGPT4Model(model string) bool {
func IsGPT3TurboModel(model string) bool {
return in(model, GPT3TurboArray) || in(model, GPT3Turbo16kArray)
}
func IsClaudeModel(model string) bool {
return in(model, ClaudeModelArray)
}

View File

@ -13,6 +13,9 @@ import (
func GetWeightByModel(model string) int {
switch model {
case types.Claude2,
types.Claude2100k:
return 2
case types.GPT432k,
types.GPT432k0613,
types.GPT432k0314:
@ -36,6 +39,9 @@ func GetWeightByModel(model string) int {
} else if strings.Contains(model, types.GPT4) {
// warning: gpt-4 may update over time. Returning num tokens assuming gpt-4-0613.
return GetWeightByModel(types.GPT40613)
} else if strings.Contains(model, types.Claude2) {
// warning: claude-2 may update over time. Returning num tokens assuming claude-2-100k.
return GetWeightByModel(types.Claude2100k)
} else {
// not implemented: See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens
panic(fmt.Errorf("not implemented for model %s", model))