chatgpt大模型
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
11 KiB

  1. #coding:utf8
  2. import re
  3. from jsonpath_ng import parse
  4. import json
  5. import traceback
  6. def get_content(inputdata,logging):
  7. """
  8. 重新组装参数
  9. :param inputdata:原json数据
  10. :return: 组装的prompt及其他参数
  11. """
  12. res={}
  13. admin=inputdata["metadata"]["admin"]
  14. data=inputdata["data"]
  15. prompt=admin["prompt"]
  16. if_user=re.findall("{{(.*)}}",prompt)
  17. if_data=re.findall("@@(.*?)@@",prompt)
  18. if if_user != []:
  19. user_data=inputdata["metadata"]["user"]
  20. if if_user[0] in user_data.keys():
  21. tmp=user_data[if_user[0]]
  22. prompt=re.sub("{{(.*)}}",tmp,prompt)
  23. if if_data!=[] :
  24. for rule in if_data:
  25. try:
  26. if ':' in rule:
  27. s=rule.split(':')
  28. rule1=s[0]
  29. rule2=s[1]
  30. if rule1 in data.keys():
  31. tmp1 = data[rule1]
  32. #按照给定的规则解析字段
  33. json_obj = json.loads(tmp1)
  34. jsonpath_expr = parse(rule2)
  35. result = str([match.value for match in jsonpath_expr.find(json_obj)][0])
  36. rep="@@{}@@".format(rule)
  37. #增加转义字符
  38. rep_escaped = re.escape(rep)
  39. prompt=re.sub(rep_escaped,result,prompt)
  40. else:
  41. if rule in data.keys():
  42. tmp1=data[rule]
  43. rep = "@@{}@@".format(rule)
  44. prompt=re.sub(rep,tmp1,prompt)
  45. except:
  46. rep = "@@{}@@".format(rule)
  47. prompt = prompt.replace(rep,'')
  48. logging.info("动态字段获取数据失败。{}-{}".format(rule, traceback.format_exc()))
  49. logging.info("拼接后的问题:{}".format(prompt))
  50. res["prompt"]=prompt
  51. res["authorization"]=admin["authorization"]
  52. res["model"]=admin["model"]
  53. res["temperature"]=admin["temperature"]
  54. res["authorization"]=admin["authorization"]
  55. res["top_p"]=admin["top_p"]
  56. res["n"]=admin["n"]
  57. return res
  58. # def get_content(inputdata,logging):
  59. # """
  60. # 重新组装参数
  61. # :param inputdata:原json数据
  62. # :return: 组装的prompt及其他参数
  63. # """
  64. # res={}
  65. # admin=inputdata["metadata"]["admin"]
  66. # data=inputdata["data"]
  67. # prompt=admin["prompt"]
  68. # if_user=re.findall("{{(.*)}}",prompt)
  69. # if_data=re.findall("@@(.*)@@",prompt)
  70. # if if_user != []:
  71. # user_data=inputdata["metadata"]["user"]
  72. # if if_user[0] in user_data.keys():
  73. # tmp=user_data[if_user[0]]
  74. # prompt=re.sub("{{(.*)}}",tmp,prompt)
  75. # if if_data!=[] and if_data[0] in data.keys():
  76. # tmp1=data[if_data[0]]
  77. # prompt=re.sub("@@(.*)@@",tmp1,prompt)
  78. # res["prompt"]=prompt
  79. # res["authorization"]=admin["authorization"]
  80. # res["model"]=admin["model"]
  81. # res["temperature"]=admin["temperature"]
  82. # res["authorization"]=admin["authorization"]
  83. # res["top_p"]=admin["top_p"]
  84. # res["n"]=admin["n"]
  85. # return res
  86. if __name__=="__main__":
  87. prompt = "用@@11_任务拆分:$.lang@@,生成@@11_任务拆分:$.quantity@@条@@11_任务拆分:$.age@@的@@11_任务拆分:$.sex@@发布@@11_任务拆分:$.emotion@@的@@11_任务拆分:$.subject@@的@@11_任务拆分:$.content_type@@。以JSON数组泛型是String类型的格式进行输出,结构外层需要用“resultList”进行接收,不用多余的文字。"
  88. if_data = re.findall("@@(.*?)@@", prompt)
  89. print(if_data)
  90. # inputdata={
  91. # "metadata":{
  92. # "output":{
  93. # "output_type":"table",
  94. # "label_col":[
  95. # "相似内容抽取"
  96. # ]
  97. # },
  98. # "input":{
  99. # "input_type":"text",
  100. # "label":[
  101. # "3_相似内容过滤器"
  102. # ]
  103. # },
  104. # "address":"http://172.18.1.181:9011/chatGpt/",
  105. # "admin":{
  106. # "authorization":"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",
  107. # "top_p":"1",
  108. # "user_input":[
  109. # {
  110. # "keyname":"tag",
  111. # "keydesc":""
  112. # }
  113. # ],
  114. # "temperature":"1",
  115. # "model":"gpt-3.5-turbo-16k",
  116. # "prompt":"以JSON数组泛型是String类型的格式进行输出,不用多余的文字。参考”@@11_任务拆分:$.quantity@@不仅仅是一种工具,更是一种改变世界的力量“生成@@11_任务拆分:$.quantity@@条@@11_任务拆分:$.lang@@的@@11_任务拆分:$.content_type@@",
  117. # "n":"1"
  118. # },
  119. # "index":3,
  120. # "user":{
  121. # "tag":""
  122. # }
  123. # },
  124. # "data":{
  125. # "10_任务提取":"[{\"age\":\"18~24岁\",\"collection_element\":\"0,1\",\"collection_quantity\":1438,\"collection_task\":\"https://twitter.com/MFA_China\",\"collection_type\":0,\"content_type\":\"发帖内容\",\"create_user_id\":\"652468062228768915\",\"del\":0,\"emotion\":\"积极/乐观\",\"id\":178,\"lang\":\"英语\",\"model_status\":1,\"model_type\":1,\"name\":\"TW用户-发言办公室01-04~12-31\",\"quantity\":10,\"sex\":\"男性\",\"site_id\":181,\"status\":0,\"subject\":\"社会问题和时事主题\",\"tenant_id\":237,\"type\":1},{\"age\":\"18~24岁\",\"collection_element\":\"0,1\",\"collection_quantity\":444378,\"collection_task\":\"hongkong\",\"collection_type\":1,\"content_type\":\"发帖内容\",\"create_user_id\":\"652468062228768915\",\"del\":0,\"emotion\":\"积极/乐观\",\"id\":179,\"lang\":\"英语\",\"model_status\":1,\"model_type\":1,\"name\":\"TW关键词-hongkong01-04~12-31\",\"quantity\":10,\"sex\":\"女性\",\"site_id\":181,\"status\":0,\"subject\":\"旅行和探险主题\",\"tenant_id\":237,\"type\":1},{\"age\":\"18~24岁\",\"collection_element\":\"0,1\",\"collection_quantity\":256,\"collection_task\":\"https://www.facebook.com/tsaiingwen\",\"collection_type\":0,\"content_type\":\"发帖内容\",\"create_user_id\":\"652468062228768915\",\"del\":0,\"emotion\":\"积极/乐观\",\"id\":180,\"lang\":\"英语\",\"model_status\":1,\"model_type\":2,\"name\":\"FB用户-蔡英文-01-04~12-31\",\"quantity\":10,\"sex\":\"男性\",\"site_id\":182,\"status\":0,\"subject\":\"科技和创新主题\",\"tenant_id\":237,\"type\":1},{\"age\":\"18~24岁\",\"collection_element\":\"0,1\",\"collection_quantity\":1253,\"collection_task\":\"台湾新闻\",\"collection_type\":1,\"content_type\":\"发帖内容\",\"create_user_id\":\"652468062228768915\",\"del\":0,\"emotion\":\"积极/乐观\",\"id\":183,\"lang\":\"英语\",\"model_status\":1,\"model_type\":2,\"name\":\"FB关键词-台湾新闻-0110~12-13\",\"quantity\":10,\"sex\":\"女性\",\"site_id\":182,\"status\":0,\"subject\":\"健康和生活方式主题\",\"tenant_id\":237,\"type\":1}]",
  126. # "3_相似内容过滤器":"{\"age\":\"18~24岁\",\"collection_element\":\"0,1\",\"collection_quantity\":1253,\"collection_task\":\"台湾新闻\",\"collection_type\":1,\"content_type\":\"发帖内容\",\"create_user_id\":\"652468062228768915\",\"del\":0,\"emotion\":\"积极/乐观\",\"id\":183,\"lang\":\"英语\",\"model_status\":1,\"model_type\":2,\"name\":\"FB关键词-台湾新闻-0110~12-13\",\"quantity\":10,\"sex\":\"女性\",\"site_id\":182,\"size\":21,\"status\":0,\"subject\":\"健康和生活方式主题\",\"tenant_id\":237,\"type\":1}",
  127. # "11_任务拆分":"{\"tenant_id\":237,\"create_user_id\":\"652468062228768915\",\"collection_quantity\":1253,\"quantity\":10,\"subject\":\"健康和生活方式主题\",\"sex\":\"女性\",\"model_type\":2,\"del\":0,\"type\":1,\"collection_element\":\"0,1\",\"collection_type\":1,\"model_status\":1,\"collection_task\":\"台湾新闻\",\"emotion\":\"积极/乐观\",\"content_type\":\"发帖内容\",\"size\":21,\"name\":\"FB关键词-台湾新闻-0110~12-13\",\"site_id\":182,\"id\":183,\"lang\":\"英语\",\"age\":\"18~24岁\",\"status\":0}",
  128. # "1_mysql数据查询":"{\"resultList\": [{\"id\": 178, \"tenant_id\": 237, \"name\": \"TW用户-发言办公室01-04~12-31\", \"site_id\": 181, \"collection_type\": 0, \"collection_element\": \"0,1\", \"collection_task\": \"https://twitter.com/MFA_China\", \"status\": 0, \"collection_quantity\": 1438, \"create_user\": null, \"create_user_id\": \"652468062228768915\", \"update_user\": null, \"update_user_id\": null, \"del\": 0, \"type\": 1, \"model_type\": 1, \"quantity\": 10, \"content_type\": \"发帖内容\", \"model_status\": 1, \"lang\": \"英语\", \"age\": \"18~24岁\", \"sex\": \"男性\", \"emotion\": \"积极/乐观\", \"subject\": \"社会问题和时事主题\", \"similar_content\": null}, {\"id\": 179, \"tenant_id\": 237, \"name\": \"TW关键词-hongkong01-04~12-31\", \"site_id\": 181, \"collection_type\": 1, \"collection_element\": \"0,1\", \"collection_task\": \"hongkong\", \"status\": 0, \"collection_quantity\": 444378, \"create_user\": null, \"create_user_id\": \"652468062228768915\", \"update_user\": null, \"update_user_id\": null, \"del\": 0, \"type\": 1, \"model_type\": 1, \"quantity\": 10, \"content_type\": \"发帖内容\", \"model_status\": 1, \"lang\": \"英语\", \"age\": \"18~24岁\", \"sex\": \"女性\", \"emotion\": \"积极/乐观\", \"subject\": \"旅行和探险主题\", \"similar_content\": null}, {\"id\": 180, \"tenant_id\": 237, \"name\": \"FB用户-蔡英文-01-04~12-31\", \"site_id\": 182, \"collection_type\": 0, \"collection_element\": \"0,1\", \"collection_task\": \"https://www.facebook.com/tsaiingwen\", \"status\": 0, \"collection_quantity\": 256, \"create_user\": null, \"create_user_id\": \"652468062228768915\", \"update_user\": null, \"update_user_id\": null, \"del\": 0, \"type\": 1, \"model_type\": 2, \"quantity\": 10, \"content_type\": \"发帖内容\", \"model_status\": 1, \"lang\": \"英语\", \"age\": \"18~24岁\", \"sex\": \"男性\", \"emotion\": \"积极/乐观\", \"subject\": \"科技和创新主题\", \"similar_content\": null}, {\"id\": 183, \"tenant_id\": 237, \"name\": \"FB关键词-台湾新闻-0110~12-13\", \"site_id\": 182, \"collection_type\": 1, \"collection_element\": \"0,1\", \"collection_task\": \"台湾新闻\", \"status\": 0, \"collection_quantity\": 1253, \"create_user\": null, \"create_user_id\": \"652468062228768915\", \"update_user\": null, \"update_user_id\": null, \"del\": 0, \"type\": 1, \"model_type\": 2, \"quantity\": 10, \"content_type\": \"发帖内容\", \"model_status\": 1, \"lang\": \"英语\", \"age\": \"18~24岁\", \"sex\": \"女性\", \"emotion\": \"积极/乐观\", \"subject\": \"健康和生活方式主题\", \"similar_content\": null}]}"
  129. # },
  130. # "created":1691004265000,
  131. # "module":"ChatGPT",
  132. # "start_tag":"false",
  133. # "multi_branch":0,
  134. # "last_edit":1693932236000,
  135. # "next_app_id":[
  136. # {
  137. # "start_id":188,
  138. # "edge_id":92,
  139. # "end_id":190
  140. # }
  141. # ],
  142. # "transfer_id":5,
  143. # "version":1,
  144. # "blueprint_id":6,
  145. # "scenes_id":7,
  146. # "scenario":{
  147. # "dataloss":1,
  148. # "autoCommitTriggerLast":1,
  149. # "maxErrors":3,
  150. # "autoCommit":1,
  151. # "freshVariables":1
  152. # },
  153. # "wait_condition":[
  154. #
  155. # ],
  156. # "scheduling":{
  157. # "interval":-1,
  158. # "type":"single"
  159. # },
  160. # "name":"相似内容抽取",
  161. # "id":188,
  162. # "position":[
  163. # 100,
  164. # 200
  165. # ],
  166. # "describe":"相似内容抽取"
  167. # }
  168. # a=get_content(inputdata,"")
  169. # print(a)