package service import ( "encoding/json" "fmt" "go-admin/app/observe/service/dto" "go-admin/utils" ) type BigModel struct { // service.Service utils.OtService } func (b *BigModel) RequestAiPlatform(req *dto.AskAiModel, resp *dto.BigModelResp) error { token := "2029160c1fdae2de4a30d989080dc2ef.YsXIveZGpmeUhROe" url := "https://open.bigmodel.cn/api/paas/v4/chat/completions" tips := "是什么问题,请言简意赅解释“问题原因”以及“排查思路”,必须使用中文回答,只分析客观的技术问题,不需要加最后的简单总结或者其他帮助方法,不要加任何总结性文字。问题答案输出为标准且好看的html格式" fmt.Println("content:", req.Content) content := fmt.Sprintf( "“%s”%s", req.Content, tips, ) bpm := []dto.BigModelParamsMessage{ { Role: "user", Content: content, }, } ps := &dto.BigModelParams{ Model: "glm-4", Messages: bpm, } params, _ := json.Marshal(ps) header := map[string]string{ "Authorization": fmt.Sprintf("Bearer %s", token), } response, err := utils.Post(url, params, header) if err != nil { fmt.Sprintln("post error: ", err.Error()) return err } if err := json.Unmarshal(response, resp); err != nil { fmt.Sprintln("unmarshal error: ", err.Error()) return err } return nil }