From 23b6885df7294c276f5f3147f8d3c08b289bc949 Mon Sep 17 00:00:00 2001 From: liyp Date: Sat, 6 Jul 2024 21:57:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(workers/ai.go):=20=E4=BF=AE=E6=94=B9handle?= =?UTF-8?q?ModelRequest=E5=92=8ChandleChatRequest=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96,=20=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81=E8=BF=94=E5=9B=9E=20refactor(workers/pkg.go)?= =?UTF-8?q?:=20=E7=A7=BB=E9=99=A4Pkg=E4=B8=AD=E7=9A=84=E5=86=97=E4=BD=99?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E8=AF=AD=E5=8F=A5,=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workers/ai.go | 8 ++++---- workers/pkg.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/workers/ai.go b/workers/ai.go index 4f5c505..994a10f 100644 --- a/workers/ai.go +++ b/workers/ai.go @@ -92,10 +92,10 @@ func handleModelRequest(OPENAI_API_KEY, OPENAI_BaseURL string) string { choices := responseBody["data"].([]interface{}) // var models []interface{} if len(choices) > 0 { - msg := "支持的模型列表:\\n" + msg := "支持的模型列表:\n" for _, choice := range choices { model := choice.(map[string]interface{})["id"] - msg += fmt.Sprintf("%s\\n", model) + msg += fmt.Sprintf("%s\n", model) } return msg } else { @@ -138,7 +138,7 @@ func handleChatRequest(OPENAI_API_KEY, OPENAI_BaseURL, MODEL, rawMsg, UID string log.Println(errs) return "请求失败" } - + println(resp.StatusCode) if resp.StatusCode == 200 { var responseBody map[string]interface{} if err := json.Unmarshal([]byte(body), &responseBody); err != nil { @@ -155,6 +155,6 @@ func handleChatRequest(OPENAI_API_KEY, OPENAI_BaseURL, MODEL, rawMsg, UID string return "api解析失败" } } else { - return "请求失败" + return "请求失败: " + string(resp.StatusCode) } } diff --git a/workers/pkg.go b/workers/pkg.go index 01dd8fe..92d18a8 100644 --- a/workers/pkg.go +++ b/workers/pkg.go @@ -38,7 +38,7 @@ func (a *Pkg) GetMsg() string { url += "&repo=" + strings.ToUpper(parms[2][:1]) + parms[2][1:] } // 输出请求地址 - fmt.Println("pkg url:", url) + // fmt.Println("pkg url:", url) request := gorequest.New() _, body, errs := request.Get(url).End() if len(errs) > 0 { @@ -61,7 +61,7 @@ func (a *Pkg) GetMsg() string { fmt.Println(errs) } - fmt.Println("aur suggest url:", url) + // fmt.Println("aur suggest url:", url) // fmt.Println(string(re)) var suggestions []string @@ -98,7 +98,7 @@ func (a *Pkg) GetMsg() string { searchResult = resultMap } } - fmt.Println(len(searchResult)) + // fmt.Println(len(searchResult)) } else if len(searchResults) == 1 { searchResult = searchResults[0].(map[string]interface{}) } @@ -106,7 +106,7 @@ func (a *Pkg) GetMsg() string { if !ok { maintainer = "孤儿包" } - println("maintainer:", maintainer) + // println("maintainer:", maintainer) // last_update := '' last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05") @@ -123,7 +123,7 @@ func (a *Pkg) GetMsg() string { msg += "上游:" + upstream + "\n" msg += "更新时间:" + last_update - fmt.Println(msg) + // fmt.Println(msg) return msg }