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.
172 lines
14 KiB
172 lines
14 KiB
#coding:utf8
|
|
import re
|
|
from jsonpath_ng import parse
|
|
import json
|
|
import traceback
|
|
from log_util.set_logger import set_logger
|
|
def parse_data(data,para):
|
|
param_split = str(para).split(":")
|
|
datasourcestr = data[param_split[0]]
|
|
datasource = json.loads(datasourcestr)
|
|
# 创建 JsonPath 表达式对象
|
|
expr = parse(param_split[1])
|
|
# 使用表达式来选择 JSON 元素
|
|
match = [match.value for match in expr.find(datasource)]
|
|
val = match[0]
|
|
return val
|
|
|
|
def parse_gptResult(output,gptContent):
|
|
json_result = {}
|
|
try:
|
|
json_gpt=json.loads(str(gptContent).replace("```json","").replace("```",""))
|
|
for key in output.keys():
|
|
if key in json_gpt.keys():
|
|
json_result[key]=json_gpt[key]
|
|
|
|
return json_result
|
|
except Exception as e:
|
|
try:
|
|
# 直接解析失败,使用正则表达式匹配外层的 {}
|
|
pattern = r'\{(?:[^{}]*|(?R))*\}'
|
|
match = re.search(pattern, gptContent, re.DOTALL)
|
|
if match:
|
|
json_gpt = json.loads(match.group())
|
|
for key in output.keys():
|
|
if key in json_gpt.keys():
|
|
json_result[key]=json_gpt[key]
|
|
return json_result
|
|
else:
|
|
return None
|
|
except:
|
|
traceback.print_exc()
|
|
return None
|
|
|
|
|
|
def get_content(inputdata,logging):
|
|
"""
|
|
重新组装参数
|
|
:param inputdata:原json数据
|
|
:return: 组装的prompt及其他参数
|
|
"""
|
|
res={}
|
|
input=inputdata["input"]
|
|
data=inputdata["data"]
|
|
prompts=input["prompt"]
|
|
prompt_res=""
|
|
if prompts:
|
|
for prompt in prompts:
|
|
if str(prompt["type"])=="1":
|
|
prompt_res+=prompt["value"]
|
|
elif str(prompt["type"])=="2":
|
|
try:
|
|
tmp=parse_data(data,prompt["value"])
|
|
prompt_res +=tmp
|
|
except:
|
|
logging.info("动态字段获取数据失败。{}-{}".format(prompt, traceback.format_exc()))
|
|
|
|
# logging.info("拼接后的问题:{}".format(prompt_res))
|
|
res["prompt"]=prompt_res
|
|
# res["authorization"]=input["authorization"]
|
|
# res["model"]=input["model"]
|
|
res["temperature"]=input["temperature"]
|
|
res["top_p"]=input["top_p"]
|
|
res["n"]=input["n"]
|
|
return res
|
|
|
|
# def get_content(inputdata,logging):
|
|
# """
|
|
# 重新组装参数
|
|
# :param inputdata:原json数据
|
|
# :return: 组装的prompt及其他参数
|
|
# """
|
|
# res={}
|
|
# admin=inputdata["metadata"]["admin"]
|
|
# data=inputdata["data"]
|
|
# prompt=admin["prompt"]
|
|
# if_user=re.findall("{{(.*)}}",prompt)
|
|
# if_data=re.findall("@@(.*)@@",prompt)
|
|
# if if_user != []:
|
|
# user_data=inputdata["metadata"]["user"]
|
|
# if if_user[0] in user_data.keys():
|
|
# tmp=user_data[if_user[0]]
|
|
# prompt=re.sub("{{(.*)}}",tmp,prompt)
|
|
# if if_data!=[] and if_data[0] in data.keys():
|
|
# tmp1=data[if_data[0]]
|
|
# prompt=re.sub("@@(.*)@@",tmp1,prompt)
|
|
# res["prompt"]=prompt
|
|
# res["authorization"]=admin["authorization"]
|
|
# res["model"]=admin["model"]
|
|
# res["temperature"]=admin["temperature"]
|
|
# res["authorization"]=admin["authorization"]
|
|
# res["top_p"]=admin["top_p"]
|
|
# res["n"]=admin["n"]
|
|
# return res
|
|
|
|
if __name__=="__main__":
|
|
inputdata={
|
|
"output":{
|
|
"id":"id",
|
|
"content":"content"
|
|
},
|
|
"address":"http://172.18.1.181:9011/chatGpt/",
|
|
"input":{
|
|
"authorization":"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",
|
|
"top_p":"1",
|
|
"temperature":"1",
|
|
"model":"gpt-3.5-turbo-16k",
|
|
"prompt":[{"type":1,"value":"下面我给出一段文本,这段文本的内容是"},{"type":2,"value":"2_内容翻译:$['content']"},{"type":1,"value":"请总结上述内容"}],
|
|
"n":"1"
|
|
},
|
|
"data":{
|
|
"1_Youtube采集":"{\"isDownload\":\"true\",\"imageCount\":0,\"groupRules\":[],\"commentUrl\":\"\",\"channel\":\"网络视频\",\"readCount\":55,\"resolution\":\"best\",\"srcimagePath\":[],\"fileCount\":0,\"subjectId\":304864,\"forwardQuoteCount\":-1,\"province\":\"\",\"crawlDataFlagType\":\"0\",\"price\":0,\"quoteCount\":-1,\"translateContentLength\":\"\",\"forwardUserType\":0,\"brand\":\"\",\"createTimeStr\":\"2023-11-02 14:30:24\",\"ocrLength\":0,\"hasOCR\":0,\"authornickname\":\"\",\"contentSimHash\":\"a870a5b58416c163e2618400adf2ea0f\",\"dns\":\"https://www.youtube.com/\",\"crawlDay\":1698854400000,\"asrText\":\"\",\"nomorprice\":0,\"mentionAccountUrl\":[],\"titleSimHash\":\"fc47b579bbee866173216c05bf3a8dcd\",\"videoPath\":[\"/group16/default/20231102/14/25/6/sbbJSkJdgF4.mp4\"],\"brandId\":\"\",\"commentId\":\"\",\"impression\":\"\",\"originalPhrase\":\"[\\\"8473704592933378\\\",\\\"video\\\"]\",\"userTypeContent\":\"\",\"forwardContent\":\"\",\"hashTag\":[],\"primary\":1,\"poorrate\":-1,\"extension\":\"mp4\",\"translateContent\":\"\",\"imagePathSize\":[],\"mentionTopic\":[\"china\",\"bangladesh\",\"denguefever\",\"aid\",\"တရုတ်နိုင်ငံ\",\"ဘင်္ဂလားဒေ့ရှ်နိုင်ငံ\",\"သွေးလွန်တုပ်ကွေးရောဂါ\",\"အကူအညီ\"],\"finalPhrase\":\"[\\\"8473704592933378\\\",\\\"video\\\"]\",\"city\":\"\",\"availability\":1,\"mentionAccount\":[],\"dataCount\":0,\"forwardUserUrl\":\"\",\"videoCount\":1,\"pageType\":\"newscontent\",\"dataId\":\"ba42f41f2dabcf026fef45e14100452c\",\"fourListBrand\":\"\",\"titleLength\":96,\"videoUrl\":\"\",\"ocrText\":[],\"mentionTopicUrl\":[\"https://www.youtube.com/hashtag/china\",\"https://www.youtube.com/hashtag/bangladesh\",\"https://www.youtube.com/hashtag/denguefever\",\"https://www.youtube.com/hashtag/aid\",\"https://www.youtube.com/hashtag/%E1%80%90%E1%80%9B%E1%80%AF%E1%80%90%E1%80%BA%E1%80%94%E1%80%AD%E1%80%AF%E1%80%84%E1%80%BA%E1%80%84%E1%80%B6\",\"https://www.youtube.com/hashtag/%E1%80%98%E1%80%84%E1%80%BA%E1%80%B9%E1%80%82%E1%80%9C%E1%80%AC%E1%80%B8%E1%80%92%E1%80%B1%E1%80%B7%E1%80%9B%E1%80%BE%E1%80%BA%E1%80%94%E1%80%AD%E1%80%AF%E1%80%84%E1%80%BA%E1%80%84%E1%80%B6\",\"https://www.youtube.com/hashtag/%E1%80%9E%E1%80%BD%E1%80%B1%E1%80%B8%E1%80%9C%E1%80%BD%E1%80%94%E1%80%BA%E1%80%90%E1%80%AF%E1%80%95%E1%80%BA%E1%80%80%E1%80%BD%E1%80%B1%E1%80%B8%E1%80%9B%E1%80%B1%E1%80%AC%E1%80%82%E1%80%AB\",\"https://www.youtube.com/hashtag/%E1%80%A1%E1%80%80%E1%80%B0%E1%80%A1%E1%80%8A%E1%80%AE\"],\"forwardAuthor\":\"\",\"sysAbstract\":\"\",\"forwardUrl\":\"\",\"createDate\":\"2023-11-02T14:22:23.895+08:00\",\"cate\":\"\",\"forwardPostSource\":\"\",\"expression\":[],\"docType\":\"video\",\"sex\":\"\",\"threeListBrand\":\"\",\"collectCount\":-1,\"crawlDate\":\"2023-11-02T14:22:10.000+08:00\",\"channelNum\":\"4\",\"avatar\":\"https://yt3.ggpht.com/ytc/APkrFKYE3XbulRMrXptLUgTWBKoe5P3SScIwGiny-yVMdA=s48-c-k-c0x00ffffff-no-rj\",\"promotionInfo\":\"\",\"authorId\":\"UCY0w4lNDjC-tQtk8CtSB6rQ\",\"isVip\":0,\"url\":\"https://www.youtube.com/watch?v=sbbJSkJdgF4\",\"skuProperties\":\"\",\"places\":[],\"hlKeywords\":[],\"createTime\":1698906624167,\"contentLength\":1393,\"thumbnails\":\"https://i.ytimg.com/vi/sbbJSkJdgF4/hq720_2.jpg?sqp=-oaymwE2COgCEMoBSFXyq4qpAygIARUAAIhCGABwAcABBvABAfgBtgiAAoAPigIMCAAQARhlIFsoXDAP&rs=AOn4CLC6ks5eK_6RGVwiNG1XNGmE5i28vQ\",\"downCnt\":0,\"country\":\"\",\"forwardUserId\":\"\",\"hasASR\":0,\"imagePath\":[],\"pubTime\":1697155200000,\"sign\":\"\",\"asrLength\":0,\"fansCount\":\"42300\",\"language\":\"\",\"otherSourceJson\":\"\",\"source\":\"YouTube\",\"smallImgs\":\"\",\"forwardAvatar\":\"\",\"goodrate\":-1,\"pageCommentCount\":0,\"crawlDataFlag\":\"keyword:Bangladesh is anti-China\",\"viewCnt\":-1,\"members\":[],\"postCount\":\"\",\"videoTime\":\"0:11\",\"tag\":\"\",\"filePathSize\":[],\"enSource\":\"youtube\",\"pictureList\":\"\",\"userUrl\":\"https://www.youtube.com/channel/UCY0w4lNDjC-tQtk8CtSB6rQ\",\"area\":\"\",\"fiveListBrand\":\"\",\"srcvideoPath\":[],\"firstListBrand\":\"\",\"forwardCommentsCount\":-1,\"contentTag\":\"nomal\",\"author\":\"Xinhua Myanmar မြန်မာ\",\"sysSentiment\":0.0,\"generalrate\":-1,\"attitudesCount\":1,\"createDay\":1698854400000,\"postId\":\"sbbJSkJdgF4\",\"srcfilePath\":[],\"pubDate\":\"2023-10-13T08:00:00.000+08:00\",\"sysKeywords\":\"\",\"hasFile\":0,\"translateTitle\":\"\",\"translateTitleLength\":\"\",\"getSource\":\"\",\"crawlTime\":1698906130000,\"userType\":\"1\",\"projectName\":\"113ic\",\"lastModifiedTime\":1698906143895,\"productParameter\":\"\",\"docId\":\"bfd_video_1661e0739da1eced2fe778f9cf24fe56\",\"videoTimeLong\":11,\"commentScore\":0,\"urlHash\":\"11bf67ff279d17315282efd42e2dff13\",\"_id_\":\"7af6ded26c88a15ca6b264a23287707d\",\"hasImage\":0,\"videoPathSize\":[{\"size\":\"\",\"videoTime\":\"\",\"resolution\":\"\",\"url\":\"/group16/default/20231102/14/25/6/sbbJSkJdgF4.mp4\"}],\"title\":\"#China #Bangladesh #DengueFever #Aid #တရုတ်နိုင်ငံ #ဘင်္ဂလားဒေ့ရှ်နိုင်ငံ #သွေးလွန်တုပ်ကွေးရောဂါ\",\"pageTranspondCount\":-1,\"pageAttitudeCount\":\"1\",\"content\":\"တရုတ်နိုင်ငံက ဘင်္ဂလားဒေ့ရှ်နိုင်ငံသို့ သွေးလွန်တုပ်ကွေးရောဂါတိုက်ဖျက်ရေး အကူအညီများ ပေးအပ်မည် \\n\\nဒါကာ၊ အောက်တိုဘာ ၁၃ ရက် (ဆင်ဟွာ)\\n\\nတရုတ်နိုင်ငံက ဘင်္ဂလားဒေ့ရှ်နိုင်ငံသို့ သွေးလွန်တုပ်ကွေးရောဂါတိုက်ဖျက်ရေးအကူအညီများ ပေးအပ်သွားမည်ဟု ဘင်္ဂလားဒေရှ်နိုင်ငံဆိုင်ရာ တရုတ်နိုင်ငံသံအမတ် Yao Wen က အောက်တိုဘာ ၁၁ ရက်တွင် တရုတ်နိုင်ငံက ကူညီပေးသည့် သွေးလွန်တုပ်ကွေး ရောဂါဆိုင်ရာ ပစ္စည်းကိရိယာများအား Savar မြို့ရှိ ဆေးရုံကြီးတစ်ခုသို့ လှူဒါန်းပွဲအခမ်းအနား ပြောကြားသည့် မိန့်ခွန်း၌ ကြေညာခဲ့သည်။ \\n\\nယခုနှစ်အတွင်း ဘင်္ဂလားဒေ့ရှ်နိုင်ငံတစ်ဝန်း သွေးလွန်တုပ်ကွေးရောဂါဖြစ်ပွားမှုပေါင်း ၂၂၈,၇၇၉ မှုရှိသည့်အနက် သွေးလွန်တုပ်ကွေးရောဂါကြောင့် သေဆုံးသူပေါင်း ၁,၁၀၉ ဦး ရှိခဲ့ကြောင်း ဘင်္ဂလားဒေ့ရှ်နိုင်ငံ ကျန်းမာရေးဌာန၏ အချက်အလက်များတွင် ဖော်ပြထားသည်။ (Xinhua) \\n\\n#China #Bangladesh #DengueFever #Aid #တရုတ်နိုင်ငံ #ဘင်္ဂလားဒေ့ရှ်နိုင်ငံ #သွေးလွန်တုပ်ကွေးရောဂါ #အကူအညီ\\n.............................\\n(English Version)\\nChina to provide anti-dengue aid to Bangladesh\\nChina will provide anti-dengue aid to Bangladesh, Chinese Ambassador to Bangladesh Yao Wen announced Wednesday while addressing the donation ceremony of China-aided dengue kits to a major hospital in Savar on the outskirts of Dhaka.\\nA total of 1,109 people have died of dengue fever, out of 228,779 cases reported across Bangladesh so far this year, Bangladeshi health department figures showed.\\nXinhua News Agency correspondents reporting from Dhaka.(XHTV)\",\"authorLevel\":\"\",\"attr\":\"{\\\"crawlDataFlag\\\":\\\"keyword:Bangladesh is anti-China\\\",\\\"project_name\\\":\\\"113ic\\\",\\\"attachTag\\\":\\\"78278a5168e45304\\\",\\\"keyword\\\":\\\"Bangladesh is anti-China\\\",\\\"attachtag\\\":{\\\"attachTag\\\":\\\"78278a5168e45304\\\",\\\"crawlDataFlag\\\":\\\"keyword:Bangladesh is anti-China\\\",\\\"project_name\\\":\\\"113ic\\\",\\\"appId\\\":\\\"113ic\\\"},\\\"appId\\\":\\\"113ic\\\",\\\"tname\\\":\\\"YouTube\\\"}\",\"forumScore\":\"\",\"hasVideo\":1,\"forwardAttitudesCount\":-1,\"pubDay\":1697126400000,\"pubTimeStr\":\"2023-10-13 08:00:00\",\"filePath\":[],\"forwardPubTime\":0,\"postSource\":\"\",\"hasTrans\":0,\"avatarPath\":\"\",\"crawlTimeStr\":\"2023-11-02 14:22:10\",\"externalId\":\"caebd93b-0e7a-4886-87e7-bb53fab42fdc\",\"favorCnt\":-1,\"friendsCount\":\"\",\"secondListBrand\":\"\",\"forwardImgs\":\"\",\"commentsCount\":0,\"listBrand\":\"\",\"opinions\":[],\"siteId\":\"\",\"location\":\"\",\"otherInfoJson\":\"\",\"age\":\"\",\"taskId\":\"1039000\"}",
|
|
"2_内容翻译":"{\"content\":\"\\n\\n\\n\\no\\n\\n\\n\\n#中国#孟加拉国#登革热#援助#\\n……\\n(英文版)\\n中国向孟加拉国提供抗登革热援助\\n中国驻孟加拉国大使姚文周三在达卡郊区萨瓦尔的一家大医院捐赠中国援助的登革热工具包的仪式上宣布,中国将向孟加拉国提供抗登革热援助。\\n孟加拉卫生部的数据显示,今年到目前为止,在孟加拉国报告的228779例登革热病例中,共有1109人死于登革热。\\n新华社记者在达卡报道。(XHTV)\"}",
|
|
"businessKey":"78278a5168e45304"
|
|
},
|
|
"created":1691004265000,
|
|
"module":"ChatGPT",
|
|
"start_tag":"false",
|
|
"multi_branch":0,
|
|
"last_edit":1698927821000,
|
|
"next_app_id":[
|
|
{
|
|
"start_id":316,
|
|
"edge_id":200,
|
|
"end_id":317
|
|
}
|
|
],
|
|
"transfer_id":3,
|
|
"version":1,
|
|
"blueprint_id":12,
|
|
"scenes_id":12,
|
|
"scenario":{
|
|
"dataloss":1,
|
|
"autoCommitTriggerLast":1,
|
|
"maxErrors":3,
|
|
"autoCommit":1,
|
|
"freshVariables":1
|
|
},
|
|
"wait_condition":[
|
|
|
|
],
|
|
"scheduling":{
|
|
"interval":-1,
|
|
"type":"single"
|
|
},
|
|
"name":"正面引导",
|
|
"businessKey":"78278a5168e45304",
|
|
"id":316,
|
|
"position":[
|
|
100,
|
|
200
|
|
],
|
|
"describe":"正面引导"
|
|
}
|
|
a=get_content(inputdata,"")
|
|
print(a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|