From 72ef3d2746ab6c35f9ac3d52cda1e956b2db98cd Mon Sep 17 00:00:00 2001 From: AlexT <60740185+Alex-TG001@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:01:32 +0800 Subject: [PATCH] =?UTF-8?q?Go=20=E6=9B=B4=E6=96=B0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A8=A1=E5=9E=8B=E5=88=97=E8=A1=A8=20(#822)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/qianfan/chat_completion.go | 220 +++++++++++++++++++--------------- 1 file changed, 122 insertions(+), 98 deletions(-) diff --git a/go/qianfan/chat_completion.go b/go/qianfan/chat_completion.go index 6b34cd89..bb1c320f 100644 --- a/go/qianfan/chat_completion.go +++ b/go/qianfan/chat_completion.go @@ -83,57 +83,65 @@ type ChatCompletionRequest struct { // 内置 chat 模型的 endpoint var ChatModelEndpoint = map[string]string{ - "ERNIE-4.0-Turbo-8K": "/chat/ernie-4.0-turbo-8k", - "ERNIE-4.0-8K-Latest": "/chat/ernie-4.0-8k-latest", - "ERNIE-4.0-8K-0613": "/chat/ernie-4.0-8k-0613", - "ERNIE-3.5-8K-0613": "/chat/ernie-3.5-8k-0613", - "ERNIE-Bot-turbo": "/chat/eb-instant", - "ERNIE-Lite-8K-0922": "/chat/eb-instant", - "ERNIE-Lite-8K": "/chat/ernie-lite-8k", - "ERNIE-Lite-8K-0308": "/chat/ernie-lite-8k", - "ERNIE-3.5-8K": "/chat/completions", - "ERNIE-Bot": "/chat/completions", - "ERNIE-4.0-8K": "/chat/completions_pro", - "ERNIE-4.0-8K-Preview": "/chat/ernie-4.0-8k-preview", - "ERNIE-4.0-8K-Preview-0518": "/chat/completions_adv_pro", - "ERNIE-4.0-8K-0329": "/chat/ernie-4.0-8k-0329", - "ERNIE-4.0-8K-0104": "/chat/ernie-4.0-8k-0104", - "ERNIE-Bot-4": "/chat/completions_pro", - "ERNIE-Bot-8k": "/chat/ernie_bot_8k", - "ERNIE-3.5-128K": "/chat/ernie-3.5-128k", - "ERNIE-3.5-8K-preview": "/chat/ernie-3.5-8k-preview", - "ERNIE-3.5-8K-0329": "/chat/ernie-3.5-8k-0329", - "ERNIE-3.5-4K-0205": "/chat/ernie-3.5-4k-0205", - "ERNIE-3.5-8K-0205": "/chat/ernie-3.5-8k-0205", - "ERNIE-3.5-8K-1222": "/chat/ernie-3.5-8k-1222", - "ERNIE Speed": "/chat/ernie_speed", - "ERNIE-Speed": "/chat/ernie_speed", - "ERNIE-Speed-8K": "/chat/ernie_speed", - "ERNIE-Speed-128K": "/chat/ernie-speed-128k", - "ERNIE Speed-AppBuilder": "/chat/ai_apaas", - "ERNIE-Tiny-8K": "/chat/ernie-tiny-8k", - "ERNIE-Function-8K": "/chat/ernie-func-8k", - "ERNIE-Character-8K": "/chat/ernie-char-8k", - "ERNIE-Character-Fiction-8K": "/chat/ernie-char-fiction-8k", - "ERNIE-Bot-turbo-AI": "/chat/ai_apaas", - "EB-turbo-AppBuilder": "/chat/ai_apaas", - "BLOOMZ-7B": "/chat/bloomz_7b1", - "Llama-2-7b-chat": "/chat/llama_2_7b", - "Llama-2-13b-chat": "/chat/llama_2_13b", - "Llama-2-70b-chat": "/chat/llama_2_70b", - "Qianfan-Chinese-Llama-2-7B": "/chat/qianfan_chinese_llama_2_7b", - "Qianfan-Chinese-Llama-2-13B": "/chat/qianfan_chinese_llama_2_13b", - "Qianfan-Chinese-Llama-2-70B": "/chat/qianfan_chinese_llama_2_70b", - "Meta-Llama-3-8B": "/chat/llama_3_8b", - "Meta-Llama-3-70B": "/chat/llama_3_70b", - "Qianfan-BLOOMZ-7B-compressed": "/chat/qianfan_bloomz_7b_compressed", - "ChatGLM2-6B-32K": "/chat/chatglm2_6b_32k", - "AquilaChat-7B": "/chat/aquilachat_7b", - "XuanYuan-70B-Chat-4bit": "/chat/xuanyuan_70b_chat", - "ChatLaw": "/chat/chatlaw", - "Yi-34B-Chat": "/chat/yi_34b_chat", - "Mixtral-8x7B-Instruct": "/chat/mixtral_8x7b_instruct", - "Gemma-7B-it": "/chat/gemma_7b_it", + "ERNIE-4.0-Turbo-8K": "/chat/ernie-4.0-turbo-8k", + "ERNIE-4.0-8K-Latest": "/chat/ernie-4.0-8k-latest", + "ERNIE-4.0-8K-0613": "/chat/ernie-4.0-8k-0613", + "ERNIE-3.5-8K-0613": "/chat/ernie-3.5-8k-0613", + "ERNIE-Bot-turbo": "/chat/eb-instant", + "ERNIE-Lite-8K-0922": "/chat/eb-instant", + "ERNIE-Lite-8K": "/chat/ernie-lite-8k", + "ERNIE-Lite-8K-0308": "/chat/ernie-lite-8k", + "ERNIE-Lite-AppBuilder-8K-0614": "/chat/ai_apaas_lite", + "ERNIE-Lite-Pro-8K": "/chat/ernie-lite-pro-8k", + "ERNIE-Lite-V": "/chat/ernie-lite-v", + "ERNIE-3.5-8K": "/chat/completions", + "ERNIE-Bot": "/chat/completions", + "ERNIE-4.0-8K": "/chat/completions_pro", + "ERNIE-4.0-8K-Preview": "/chat/ernie-4.0-8k-preview", + "ERNIE-4.0-8K-Preview-0518": "/chat/completions_adv_pro", + "ERNIE-4.0-8K-0329": "/chat/ernie-4.0-8k-0329", + "ERNIE-4.0-8K-0104": "/chat/ernie-4.0-8k-0104", + "ERNIE-Bot-4": "/chat/completions_pro", + "ERNIE-Bot-8k": "/chat/ernie_bot_8k", + "ERNIE-3.5-128K": "/chat/ernie-3.5-128k", + "ERNIE-3.5-8K-preview": "/chat/ernie-3.5-8k-preview", + "ERNIE-3.5-8K-0329": "/chat/ernie-3.5-8k-0329", + "ERNIE-3.5-4K-0205": "/chat/ernie-3.5-4k-0205", + "ERNIE-3.5-8K-0205": "/chat/ernie-3.5-8k-0205", + "ERNIE-3.5-8K-0701": "/chat/ernie-3.5-8k-0701", + "ERNIE-3.5-8K-1222": "/chat/ernie-3.5-8k-1222", + "ERNIE Speed": "/chat/ernie_speed", + "ERNIE-Speed": "/chat/ernie_speed", + "ERNIE-Speed-8K": "/chat/ernie_speed", + "ERNIE-Speed-128K": "/chat/ernie-speed-128k", + "ERNIE Speed-AppBuilder": "/chat/ai_apaas", + "ERNIE-Speed-Pro-8K": "/chat/ernie-speed-pro-8k", + "ERNIE-Speed-Pro-128K": "/chat/ernie-speed-pro-128k", + "ERNIE-Tiny-8K": "/chat/ernie-tiny-8k", + "ERNIE-Function-8K": "/chat/ernie-func-8k", + "ERNIE-Character-8K": "/chat/ernie-char-8k", + "ERNIE-Character-Fiction-8K": "/chat/ernie-char-fiction-8k", + "ERNIE-Bot-turbo-AI": "/chat/ai_apaas", + "ERNIE-Novel-8K": "/chat/ernie-novel-8k", + "EB-turbo-AppBuilder": "/chat/ai_apaas", + "BLOOMZ-7B": "/chat/bloomz_7b1", + "Llama-2-7B-Chat": "/chat/llama_2_7b", + "Llama-2-13B-Chat": "/chat/llama_2_13b", + "Llama-2-70B-chat": "/chat/llama_2_70b", + "Qianfan-Chinese-Llama-2-7B": "/chat/qianfan_chinese_llama_2_7b", + "Qianfan-Chinese-Llama-2-13B": "/chat/qianfan_chinese_llama_2_13b", + "Qianfan-Chinese-Llama-2-70B": "/chat/qianfan_chinese_llama_2_70b", + "Meta-Llama-3-8B": "/chat/llama_3_8b", + "Meta-Llama-3-70B": "/chat/llama_3_70b", + "Qianfan-BLOOMZ-7B-compressed": "/chat/qianfan_bloomz_7b_compressed", + "ChatGLM2-6B-32K": "/chat/chatglm2_6b_32k", + "AquilaChat-7B": "/chat/aquilachat_7b", + "XuanYuan-70B-Chat-4bit": "/chat/xuanyuan_70b_chat", + "ChatLaw": "/chat/chatlaw", + "Yi-34B-Chat": "/chat/yi_34b_chat", + "Mixtral-8x7B-Instruct": "/chat/mixtral_8x7b_instruct", + "Gemma-7B-it": "/chat/gemma_7b_it", + "Qianfan-Dynamic-8K": "/chat/qianfan-dynamic-8k", } // inputLimitInfo 结构体包含 maxInputChars 和 maxInputTokens @@ -144,53 +152,61 @@ type inputLimitInfo struct { // 定义包含所需信息的 map var limitMapInModelName = map[string]inputLimitInfo{ - "ERNIE-4.0-Turbo-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-Latest": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-0613": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-8K-0613": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-Lite-8K-0922": {MaxInputChars: 11200, MaxInputTokens: 7168}, - "ERNIE-Lite-8K": {MaxInputChars: 11200, MaxInputTokens: 7168}, - "ERNIE-Lite-8K-0308": {MaxInputChars: 11200, MaxInputTokens: 7168}, - "ERNIE-3.5-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-0329": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-0104": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-preemptible": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-Preview-0518": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-4.0-8K-preview": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-8K-preemptible": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-128K": {MaxInputChars: 516096, MaxInputTokens: 126976}, - "ERNIE-3.5-8K-preview": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-Bot-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-4K-0205": {MaxInputChars: 8000, MaxInputTokens: 2048}, - "ERNIE-3.5-8K-0205": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-8K-1222": {MaxInputChars: 20000, MaxInputTokens: 5120}, - "ERNIE-3.5-8K-0329": {MaxInputChars: 8000, MaxInputTokens: 2048}, - "ERNIE-Speed-8K": {MaxInputChars: 11200, MaxInputTokens: 7168}, - "ERNIE-Speed-128K": {MaxInputChars: 507904, MaxInputTokens: 126976}, - "ERNIE Speed-AppBuilder": {MaxInputChars: 11200, MaxInputTokens: 7168}, - "ERNIE-Tiny-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, - "ERNIE-Function-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, - "ERNIE-Character-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, - "ERNIE-Character-Fiction-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, - "BLOOMZ-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Llama-2-7B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Llama-2-13B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Llama-2-70B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Meta-Llama-3-8B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Meta-Llama-3-70B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Qianfan-BLOOMZ-7B-compressed": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Qianfan-Chinese-Llama-2-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "ChatGLM2-6B-32K": {MaxInputChars: 4800, MaxInputTokens: 0}, - "AquilaChat-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "XuanYuan-70B-Chat-4bit": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Qianfan-Chinese-Llama-2-13B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Qianfan-Chinese-Llama-2-70B": {MaxInputChars: 4800, MaxInputTokens: 0}, - "ChatLaw": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Yi-34B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Mixtral-8x7B-Instruct": {MaxInputChars: 4800, MaxInputTokens: 0}, - "Gemma-7B-it": {MaxInputChars: 4800, MaxInputTokens: 0}, - "UNSPECIFIED_MODEL": {MaxInputChars: 0, MaxInputTokens: 0}, + "ERNIE-4.0-Turbo-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-Latest": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-0613": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-8K-0613": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-Lite-8K-0922": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-Lite-8K": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-Lite-8K-0308": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-3.5-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-0329": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-0104": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-preemptible": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-Preview-0518": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-4.0-8K-preview": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-8K-preemptible": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-128K": {MaxInputChars: 516096, MaxInputTokens: 126976}, + "ERNIE-3.5-8K-preview": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-Bot-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-4K-0205": {MaxInputChars: 8000, MaxInputTokens: 2048}, + "ERNIE-3.5-8K-0205": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-8K-1222": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-3.5-8K-0329": {MaxInputChars: 8000, MaxInputTokens: 2048}, + "ERNIE-Speed-8K": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-Speed-128K": {MaxInputChars: 507904, MaxInputTokens: 126976}, + "ERNIE Speed-AppBuilder": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-Tiny-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "ERNIE-Function-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "ERNIE-Character-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "ERNIE-Character-Fiction-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "BLOOMZ-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Llama-2-7B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Llama-2-13B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Llama-2-70B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Meta-Llama-3-8B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Meta-Llama-3-70B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Qianfan-BLOOMZ-7B-compressed": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Qianfan-Chinese-Llama-2-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "ChatGLM2-6B-32K": {MaxInputChars: 4800, MaxInputTokens: 0}, + "AquilaChat-7B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "XuanYuan-70B-Chat-4bit": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Qianfan-Chinese-Llama-2-13B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Qianfan-Chinese-Llama-2-70B": {MaxInputChars: 4800, MaxInputTokens: 0}, + "ChatLaw": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Yi-34B-Chat": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Mixtral-8x7B-Instruct": {MaxInputChars: 4800, MaxInputTokens: 0}, + "Gemma-7B-it": {MaxInputChars: 4800, MaxInputTokens: 0}, + "UNSPECIFIED_MODEL": {MaxInputChars: 0, MaxInputTokens: 0}, + "ERNIE-Lite-AppBuilder-8K-0614": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "ERNIE-Lite-Pro-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "ERNIE-Lite-V": {MaxInputChars: 24000, MaxInputTokens: 7168}, + "ERNIE-3.5-8K-0701": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "ERNIE-Speed-Pro-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "ERNIE-Speed-Pro-128K": {MaxInputChars: 516096, MaxInputTokens: 126976}, + "ERNIE-Novel-8K": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "Qianfan-Dynamic-8K": {MaxInputChars: 20000, MaxInputTokens: 5120}, } var limitMapInEndpoint = map[string]inputLimitInfo{ @@ -239,6 +255,14 @@ var limitMapInEndpoint = map[string]inputLimitInfo{ "/chat/yi_34b_chat": {MaxInputChars: 4800, MaxInputTokens: 0}, "/chat/mixtral_8x7b_instruct": {MaxInputChars: 4800, MaxInputTokens: 0}, "/chat/gemma_7b_it": {MaxInputChars: 4800, MaxInputTokens: 0}, + "/chat/ai_apaas_lite": {MaxInputChars: 11200, MaxInputTokens: 7168}, + "/chat/ernie-lite-pro-8k": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "/chat/ernie-lite-v": {MaxInputChars: 24000, MaxInputTokens: 7168}, + "/chat/ernie-3.5-8k-0701": {MaxInputChars: 20000, MaxInputTokens: 5120}, + "/chat/ernie-speed-pro-8k": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "/chat/ernie-speed-pro-128k": {MaxInputChars: 516096, MaxInputTokens: 126976}, + "/chat/ernie-novel-8k": {MaxInputChars: 24000, MaxInputTokens: 6144}, + "/chat/qianfan_dynamic_8k": {MaxInputChars: 20000, MaxInputTokens: 5120}, } // 创建一个 User 的消息