1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package ai
- import (
- "context"
- "data_ai/ul"
- "encoding/json"
- "github.com/baidubce/bce-qianfan-sdk/go/qianfan"
- log "github.com/donnie4w/go-logger/logger"
- "os"
- "strings"
- )
- // 百度千帆
- func PostBaiDuAI(content string) map[string]interface{} {
- // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
- os.Setenv("QIANFAN_ACCESS_KEY", "d60a9d42ca744a4a9d0e721666c8d3cc")
- os.Setenv("QIANFAN_SECRET_KEY", "2736bdc60aa14b3eaaf02597fc88a0e5")
- // 指定特定模型
- chat := qianfan.NewChatCompletion(
- qianfan.WithModel("ERNIE-Speed-128K"),
- )
- resp, err := chat.Do(
- context.TODO(),
- &qianfan.ChatCompletionRequest{
- Messages: []qianfan.ChatCompletionMessage{
- qianfan.ChatCompletionUserMessage(content),
- },
- },
- )
- if err != nil {
- log.Debug(err)
- return map[string]interface{}{}
- }
- res := make(map[string]interface{})
- result := strings.ReplaceAll(resp.Result, "\n", "")
- result = strings.ReplaceAll(result, "json", "")
- result = strings.ReplaceAll(result, "`", "")
- if new_result := ul.SaveResultReg.FindString(result); new_result != "" {
- result = new_result
- }
- json.Unmarshal([]byte(result), &res)
- return res
- }
- // 请求质谱数据外围字段...
- func PostZhiPuInfo(content string) map[string]interface{} {
- zp, ok := map[string]interface{}{}, 0
- for {
- ok++
- if zp = PostZhiPuAI(content); len(zp) > 0 {
- break
- }
- if ok >= 2 {
- break
- }
- }
- return zp
- }
- // 请求质谱数据-分类字段
- func PostZhiPuClassInfo(content string) (map[string]interface{}, bool) {
- zp := map[string]interface{}{}
- times := 0
- ok := false
- for {
- times++
- zp = PostClassZhiPuAI(content)
- if len(zp) > 0 {
- ok = true
- break
- }
- if times >= 2 {
- break
- }
- }
- return zp, ok
- }
|