prompt.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package prompt
  2. import (
  3. "data_ai/ai"
  4. "data_ai/clean"
  5. "data_ai/ul"
  6. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "strings"
  8. )
  9. // 获取分类信息...
  10. func AcquireClassInfo(detail string, title string) (string, string) {
  11. top_content := PromptToptypeFieldText(detail, title)
  12. top_zp, ok := PostZhiPuClassInfo(top_content)
  13. if !ok {
  14. return "", ""
  15. }
  16. //根据一级分类识别,获取toptype和subtype
  17. var toptype, subtype string //标准化的一级、二级分类
  18. toptype_ai, _ := top_zp["信息分类"].(string)
  19. tpInfo := ul.ToptypeDict[toptype_ai]
  20. if tpInfo != nil {
  21. toptype = tpInfo.Topetype
  22. subtype = tpInfo.Subtype
  23. } else { //匹配结果为非正规toptype,如:询价公告(66993a9d66cf0db42a5597af)
  24. for top, reg := range ul.ToptypeRegs {
  25. if reg.MatchString(toptype_ai) {
  26. if tpInfo = ul.ToptypeDict[top]; tpInfo != nil { //ToptypeRegs中预告公告、验收公告、合同公告直接获取subtype
  27. toptype = tpInfo.Topetype
  28. subtype = tpInfo.Subtype
  29. break
  30. }
  31. }
  32. }
  33. }
  34. if toptype == "" || tpInfo == nil {
  35. return "", ""
  36. }
  37. //获取二级分类
  38. sub_zp := map[string]interface{}{}
  39. if subtype == "" {
  40. sub_content := PromptSubtypeFieldText(detail, title, toptype, tpInfo)
  41. sub_zp, ok = PostZhiPuClassInfo(sub_content)
  42. if !ok {
  43. return "", ""
  44. }
  45. subtype_ai, _ := sub_zp["信息分类"].(string)
  46. subtype = tpInfo.SubtypeDict[subtype_ai]
  47. if subtype == "" && tpInfo.SubtypeRegs != nil { //二级分类校正
  48. for sub, reg := range tpInfo.SubtypeRegs {
  49. if reg.MatchString(subtype_ai) {
  50. subtype = sub
  51. break
  52. }
  53. }
  54. }
  55. }
  56. //subtype到此还可能为空,给默认值
  57. if subtype == "" {
  58. subtype = "其它"
  59. }
  60. return toptype, subtype
  61. }
  62. // 获取外围抽取字段
  63. func AcquireExtractFieldInfo(detail string) map[string]interface{} {
  64. content := PromptFieldText(detail)
  65. zp := PostZhiPuInfo(content)
  66. return zp
  67. }
  68. // 获取是否为分包信息
  69. func AcquireIsPackageInfo(detail string) bool {
  70. content := PromptIsPackageText(detail)
  71. zp := PostZhiPuInfo(content)
  72. if qu.ObjToString(zp["分包"]) == "是" {
  73. return true
  74. }
  75. return false
  76. }
  77. // 获取标讯多包信息
  78. func AcquireMultiplePackageInfo(detail string) map[string]interface{} {
  79. content := PromptMultiplePackageText(detail)
  80. zp := PostZhiPuInfo(content)
  81. return zp
  82. //后续在转格式...暂时先输出两个值
  83. pkg := map[string]interface{}{}
  84. s_winner, s_bidamount := "", 0.0
  85. win_arr, win_temp := []string{}, map[string]string{}
  86. if score := qu.Float64All(zp["分包信息score"]); score >= 90.0 {
  87. pkginfo := ul.IsMarkInterfaceMap(zp["分包信息"])
  88. for _, v := range pkginfo {
  89. winner := clean.CleanWinner(qu.ObjToString(v["中标单位"]))
  90. bidamount := clean.CleanMoney((v["中标金额"]))
  91. s_bidamount += bidamount
  92. if win_temp[winner] == "" && winner != "" {
  93. win_arr = append(win_arr, winner)
  94. win_temp[winner] = winner
  95. }
  96. }
  97. s_winner = strings.Join(win_arr, ",")
  98. pkg["s_winner"] = s_winner
  99. pkg["s_bidamount"] = s_bidamount
  100. }
  101. return pkg
  102. }
  103. // 请求质谱数据外围字段...
  104. func PostZhiPuInfo(content string) map[string]interface{} {
  105. zp, ok := map[string]interface{}{}, 0
  106. for {
  107. ok++
  108. if zp = ai.PostZhiPuAI(content); len(zp) > 0 {
  109. break
  110. }
  111. if ok >= 5 {
  112. break
  113. }
  114. }
  115. return zp
  116. }
  117. // 请求质谱数据-分类字段
  118. func PostZhiPuClassInfo(content string) (map[string]interface{}, bool) {
  119. zp := map[string]interface{}{}
  120. times := 0
  121. ok := false
  122. for {
  123. times++
  124. zp = ai.PostClassZhiPuAI(content)
  125. if len(zp) > 0 {
  126. ok = true
  127. break
  128. }
  129. if times >= 5 {
  130. break
  131. }
  132. }
  133. return zp, ok
  134. }