feat: update ali relay implementation (#830)
* 修改通译千问最新接口:1.删除history参数,改用官方推荐的messages参数 2.整理messages参数顺序,补充必要上下文信息 3.用autogen调试测试通过 * chore: update impl --------- Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
parent
7d6a169669
commit
0fe26cc4bd
@ -88,8 +88,10 @@ var ModelRatio = map[string]float64{
|
|||||||
"chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
|
"chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
|
||||||
"chatglm_std": 0.3572, // ¥0.005 / 1k tokens
|
"chatglm_std": 0.3572, // ¥0.005 / 1k tokens
|
||||||
"chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
|
"chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
|
||||||
"qwen-turbo": 0.8572, // ¥0.012 / 1k tokens
|
"qwen-turbo": 0.5715, // ¥0.008 / 1k tokens // https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing
|
||||||
"qwen-plus": 10, // ¥0.14 / 1k tokens
|
"qwen-plus": 1.4286, // ¥0.02 / 1k tokens
|
||||||
|
"qwen-max": 1.4286, // ¥0.02 / 1k tokens
|
||||||
|
"qwen-max-longcontext": 1.4286, // ¥0.02 / 1k tokens
|
||||||
"text-embedding-v1": 0.05, // ¥0.0007 / 1k tokens
|
"text-embedding-v1": 0.05, // ¥0.0007 / 1k tokens
|
||||||
"SparkDesk": 1.2858, // ¥0.018 / 1k tokens
|
"SparkDesk": 1.2858, // ¥0.018 / 1k tokens
|
||||||
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
||||||
|
@ -486,6 +486,24 @@ func init() {
|
|||||||
Root: "qwen-plus",
|
Root: "qwen-plus",
|
||||||
Parent: nil,
|
Parent: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: "qwen-max",
|
||||||
|
Object: "model",
|
||||||
|
Created: 1677649963,
|
||||||
|
OwnedBy: "ali",
|
||||||
|
Permission: permission,
|
||||||
|
Root: "qwen-max",
|
||||||
|
Parent: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "qwen-max-longcontext",
|
||||||
|
Object: "model",
|
||||||
|
Created: 1677649963,
|
||||||
|
OwnedBy: "ali",
|
||||||
|
Permission: permission,
|
||||||
|
Root: "qwen-max-longcontext",
|
||||||
|
Parent: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Id: "text-embedding-v1",
|
Id: "text-embedding-v1",
|
||||||
Object: "model",
|
Object: "model",
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
// https://help.aliyun.com/document_detail/613695.html?spm=a2c4g.2399480.0.0.1adb778fAdzP9w#341800c0f8w0r
|
// https://help.aliyun.com/document_detail/613695.html?spm=a2c4g.2399480.0.0.1adb778fAdzP9w#341800c0f8w0r
|
||||||
|
|
||||||
type AliMessage struct {
|
type AliMessage struct {
|
||||||
User string `json:"user"`
|
Content string `json:"content"`
|
||||||
Bot string `json:"bot"`
|
Role string `json:"role"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliInput struct {
|
type AliInput struct {
|
||||||
Prompt string `json:"prompt"`
|
//Prompt string `json:"prompt"`
|
||||||
History []AliMessage `json:"history"`
|
Messages []AliMessage `json:"messages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliParameters struct {
|
type AliParameters struct {
|
||||||
@ -83,32 +83,17 @@ type AliChatResponse struct {
|
|||||||
|
|
||||||
func requestOpenAI2Ali(request GeneralOpenAIRequest) *AliChatRequest {
|
func requestOpenAI2Ali(request GeneralOpenAIRequest) *AliChatRequest {
|
||||||
messages := make([]AliMessage, 0, len(request.Messages))
|
messages := make([]AliMessage, 0, len(request.Messages))
|
||||||
prompt := ""
|
|
||||||
for i := 0; i < len(request.Messages); i++ {
|
for i := 0; i < len(request.Messages); i++ {
|
||||||
message := request.Messages[i]
|
message := request.Messages[i]
|
||||||
if message.Role == "system" {
|
|
||||||
messages = append(messages, AliMessage{
|
messages = append(messages, AliMessage{
|
||||||
User: message.StringContent(),
|
Content: message.StringContent(),
|
||||||
Bot: "Okay",
|
Role: strings.ToLower(message.Role),
|
||||||
})
|
})
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
if i == len(request.Messages)-1 {
|
|
||||||
prompt = message.StringContent()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
messages = append(messages, AliMessage{
|
|
||||||
User: message.StringContent(),
|
|
||||||
Bot: request.Messages[i+1].StringContent(),
|
|
||||||
})
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &AliChatRequest{
|
return &AliChatRequest{
|
||||||
Model: request.Model,
|
Model: request.Model,
|
||||||
Input: AliInput{
|
Input: AliInput{
|
||||||
Prompt: prompt,
|
Messages: messages,
|
||||||
History: messages,
|
|
||||||
},
|
},
|
||||||
//Parameters: AliParameters{ // ChatGPT's parameters are not compatible with Ali's
|
//Parameters: AliParameters{ // ChatGPT's parameters are not compatible with Ali's
|
||||||
// TopP: request.TopP,
|
// TopP: request.TopP,
|
||||||
|
@ -69,7 +69,7 @@ const EditChannel = () => {
|
|||||||
localModels = ['ERNIE-Bot', 'ERNIE-Bot-turbo', 'ERNIE-Bot-4', 'Embedding-V1'];
|
localModels = ['ERNIE-Bot', 'ERNIE-Bot-turbo', 'ERNIE-Bot-4', 'Embedding-V1'];
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
localModels = ['qwen-turbo', 'qwen-plus', 'text-embedding-v1'];
|
localModels = ['qwen-turbo', 'qwen-plus', 'qwen-max', 'qwen-max-longcontext', 'text-embedding-v1'];
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'];
|
localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'];
|
||||||
|
Loading…
Reference in New Issue
Block a user