123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package main
- import (
- "encoding/json"
- "fmt"
- zhipu "github.com/itcwc/go-zhipu/model_api"
- util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "log"
- "strings"
- )
- // GetJyURLByID 获取剑鱼地址
- func GetJyURLByID(id string) string {
- var Url = "https://www.jianyu360.com/article/content/%s.html"
- url := fmt.Sprintf(Url, util.CommonEncodeArticle("content", id))
- return url
- }
- // GetIdByURL 解密url,获取bidding ID
- func GetIdByURL(url string) string {
- if strings.Contains(url, "work-bench") {
- return ""
- }
- if strings.Contains(url, "/article/content") {
- urls := strings.Split(url, "content/")
- res := strings.Split(urls[1], ".html")
- ids := util.CommonDecodeArticle("content", res[0])
- return ids[0]
- }
- if strings.HasSuffix(url, "appid") {
- urls := strings.Split(url, "entservice/")
- res := strings.Split(urls[1], ".html")
- se := util.SimpleEncrypt{Key: "entservice"}
- id := se.DecodeString(res[0])
- return id
- }
- return ""
- }
- // ZpAI 智普AI
- func ZpAI(apiKey, model, content string) (rest map[string]interface{}) {
- expireAtTime := int64(1719803252) // token 过期时间
- sys := "请根据我给出的公司名称,依据其单位性质、业务范围和单位职能,准确给出最符合的一个国标行业分类标签,分别给出大类、中类和小类。输出结果以JSON格式返回,格式如下:{\"label1\":\"大类\",\"label2\":\"中类\",\"label3\":\"小类\"}。我只要最匹配 的一个标签,不要返回多个字段;如果无法识别出类别,直接给我空字符串。按照以上要求输出,不要联想,不要无中生有,不要生成解释。单位名称是:"
- text := fmt.Sprintf(sys, content)
- mssage := zhipu.PostParams{
- Model: model,
- Messages: []zhipu.Message{
- {
- Role: "user", // 消息的角色信息 详见文档
- Content: text,
- },
- },
- }
- postResponse, err := zhipu.BeCommonModel(expireAtTime, mssage, apiKey)
- if err != nil {
- fmt.Println(err)
- return
- }
- if choices, ok := postResponse["choices"].([]interface{}); ok {
- if choice, ok2 := choices[0].(map[string]interface{}); ok2 {
- if message, ok3 := choice["message"].(map[string]interface{}); ok3 {
- if content, ok4 := message["content"].(string); ok4 {
- content = strings.ReplaceAll(content, "\n", "")
- content = strings.ReplaceAll(content, "json", "")
- content = strings.ReplaceAll(content, "`", "")
- err = json.Unmarshal([]byte(content), &rest)
- if err != nil {
- log.Println("Unmarshal err", err, "content:", content)
- }
- }
- }
- }
- }
- return
- }
- func checkString(s string) bool {
- for _, char := range s {
- if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || strings.ContainsAny(string(char), "12345678910") {
- return true
- }
- }
- return false
- }
- // ZpAI1 智普问答,附带业务范围
- func ZpAI1(apiKey, model, name string, businessScope string) (rest map[string]interface{}) {
- expireAtTime := int64(1719803252) // token 过期时间
- sys := "请根据我给出的公司名称,依据其单位性质、单位职能和业务范围,准确给出最符合的一个国标行业分类标签,分别给出大类、中类和小类。输出结果以JSON格式返回,格式如下:{\"label1\":\"大类\",\"label2\":\"中类\",\"label3\":\"小类\"}。我只要最匹配 的一个标签,不要返回多个字段;如果无法识别出类别,直接给我空字符串。按照以上要求输出,不要联想,不要无中生有,不要生成解释。单位名称是:"
- text := fmt.Sprintf(sys, name)
- if businessScope != "" {
- text = text + ";业务范围是:" + businessScope
- }
- mssage := zhipu.PostParams{
- Model: model,
- Messages: []zhipu.Message{
- {
- Role: "user", // 消息的角色信息 详见文档
- Content: text,
- },
- },
- }
- postResponse, err := zhipu.BeCommonModel(expireAtTime, mssage, apiKey)
- if err != nil {
- fmt.Println(err)
- return
- }
- if choices, ok := postResponse["choices"].([]interface{}); ok {
- if choice, ok2 := choices[0].(map[string]interface{}); ok2 {
- if message, ok3 := choice["message"].(map[string]interface{}); ok3 {
- if content, ok4 := message["content"].(string); ok4 {
- content = strings.ReplaceAll(content, "\n", "")
- content = strings.ReplaceAll(content, "json", "")
- content = strings.ReplaceAll(content, "`", "")
- err = json.Unmarshal([]byte(content), &rest)
- if err != nil {
- log.Println("Unmarshal err", err, "content:", content)
- }
- }
- }
- }
- }
- return
- }
|