send72B.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import json
  2. import os
  3. import requests
  4. def process_json_files(input_file, output_folder, batch_size=20):
  5. # 确保输出文件夹存在,如果不存在则创建
  6. if not os.path.exists(output_folder):
  7. os.makedirs(output_folder)
  8. # 遍历输入文件夹中的JSON文件
  9. # for root, dirs, files in os.walk(input_folder):
  10. # for i, file_name in enumerate(files, 1):
  11. # if file_name.endswith('.json'):
  12. # input_file = os.path.join(root, file_name)
  13. # output_file = os.path.join(output_folder, file_name)
  14. file_name = os.path.basename(input_file)
  15. output_file = os.path.join(output_folder, file_name)
  16. process_single_json_file(input_file, output_file, batch_size)
  17. def process_single_json_file(input_file, output_file, batch_size):
  18. # 计算文件的总行数
  19. with open(input_file, 'r', encoding='utf-8') as f_in:
  20. total_lines = sum(1 for line in f_in if line.strip())
  21. # 打开输入文件和输出文件
  22. with open(input_file, 'r', encoding='utf-8') as f_in, open(output_file, 'a', encoding='utf-8') as f_out:
  23. # 逐批处理输入文件中的JSON对象
  24. batch_data = []
  25. line_number = 0
  26. for line in f_in:
  27. line_number += 1
  28. # if line_number < 19319:
  29. # continue
  30. # 加载JSON对象
  31. # data = json.loads(line)
  32. if not line.strip():
  33. continue
  34. batch_data.append(str(line))
  35. # 如果累积了足够的数据,就发送一次请求
  36. if len(batch_data) == batch_size:
  37. process_batch(batch_data, f_out)
  38. batch_data = []
  39. print(f"Processed {line_number} out of {total_lines} lines.") # 打印进度
  40. # 处理最后一个不足一批的数据
  41. if batch_data:
  42. process_batch(batch_data, f_out)
  43. print(f"Processed {line_number} out of {total_lines} lines.") # 打印进度
  44. def process_batch(batch_data, f_out):
  45. # 构建请求数据
  46. request_data = {
  47. "max_tokens": 4096,
  48. "top_p": 1,
  49. "temperature": 0.6,
  50. "system_prompt": '''作为一位经验丰富的内容优化助手,根据输入的问答内容,你来丰富扩充答案内容,并分段或对重要内容加粗显示。
  51. ''',
  52. "querys":batch_data
  53. }
  54. # 发送请求
  55. response = requests.post("http://10.0.0.24:6000/v1/chat/completions", json=request_data)
  56. # 获取响应内容
  57. response_content = response.json()
  58. # 将响应内容写入输出文件
  59. for item in response_content['prediction']:
  60. # 获取当前问题
  61. question = batch_data.pop(0).strip() # 移除并获取列表中的第一个问题
  62. json_obj = json.loads(question)
  63. # 构建问答格式的数据
  64. qa_pair = [json_obj[0], "答:" + item.strip()]
  65. # 将问答数据写入输出文件
  66. json.dump(qa_pair, f_out, ensure_ascii=False)
  67. f_out.write('\n') # 写入换行符,以便下一组数据
  68. def getQwen72():
  69. # 指定输入文件夹和输出文件夹
  70. input_folder = '/Users/yushanghui/hongshantianping/ai训练/data/shuiwuBook/jsonOut/2024.5.13/short.json'
  71. output_folder = '/Users/yushanghui/hongshantianping/ai训练/data/shuiwuBook/jsonOut/to72B-result/short5.13.json'
  72. # 处理JSON文件,设置每批次大小为20行
  73. process_json_files(input_folder, output_folder, batch_size=50)
  74. def ceshi():
  75. rows = [{"ID":929652,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 20","TEST_TIME":"2024/03/02 20:00","COD_in":871.394653,"COD_in_name":630,"COD_off":15.017361,"COD_off_name":40,"COD_off_con":32,"TP_in":7.356771,"TP_in_name":7.1,"TP_off":0.065972,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":64.322914,"TN_in_name":65,"TN_off":8.090279,"TN_off_name":15,"TN_off_con":12,"andan_in":50.520832,"andan_in_name":58,"andan_off":0.729167,"andan_off_name":4,"andan_off_con":3.2,"SS_in":268.75,"SS_in_name":315,"SS_off":1.591435,"SS_off_name":10,"SS_off_con":8,"TDS_in":622.106506,"TDS_in_name":600,"T":"","pH":7.429398,"Q_in":2311,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3796.875000,3303.819336]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.907813]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929592,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 19","TEST_TIME":"2024/03/02 19:00","COD_in":871.394653,"COD_in_name":630,"COD_off":14.612267,"COD_off_name":40,"COD_off_con":32,"TP_in":7.356771,"TP_in_name":7.1,"TP_off":0.07581,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":64.322914,"TN_in_name":65,"TN_off":9.0625,"TN_off_name":15,"TN_off_con":12,"andan_in":52.118057,"andan_in_name":58,"andan_off":1.342592,"andan_off_name":4,"andan_off_con":3.2,"SS_in":271.527771,"SS_in_name":315,"SS_off":1.50463,"SS_off_name":10,"SS_off_con":8,"TDS_in":694.444458,"TDS_in_name":600,"T":"","pH":7.405093,"Q_in":2394,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3734.375000,3287.905029]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.916406]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929532,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 18","TEST_TIME":"2024/03/02 18:00","COD_in":871.394653,"COD_in_name":630,"COD_off":13.435184,"COD_off_name":40,"COD_off_con":32,"TP_in":7.581018,"TP_in_name":7.1,"TP_off":0.084201,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":68.923615,"TN_in_name":65,"TN_off":9.418403,"TN_off_name":15,"TN_off_con":12,"andan_in":56.875,"andan_in_name":58,"andan_off":0.619213,"andan_off_name":4,"andan_off_con":3.2,"SS_in":260.648132,"SS_in_name":315,"SS_off":2.517361,"SS_off_name":10,"SS_off_con":8,"TDS_in":494.791687,"TDS_in_name":600,"T":"","pH":7.441551,"Q_in":2350,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3822.916504,3173.321777]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.925000]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929472,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 17","TEST_TIME":"2024/03/02 17:00","COD_in":871.394653,"COD_in_name":630,"COD_off":12.824074,"COD_off_name":40,"COD_off_con":32,"TP_in":7.581018,"TP_in_name":7.1,"TP_off":0.083044,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":68.923615,"TN_in_name":65,"TN_off":9.175347,"TN_off_name":15,"TN_off_con":12,"andan_in":54.652779,"andan_in_name":58,"andan_off":1.064815,"andan_off_name":4,"andan_off_con":3.2,"SS_in":316.898163,"SS_in_name":315,"SS_off":1.880787,"SS_off_name":10,"SS_off_con":8,"TDS_in":494.791687,"TDS_in_name":600,"T":"","pH":7.510417,"Q_in":2522,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3739.583252,3170.138916]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.928125]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929412,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 16","TEST_TIME":"2024/03/02 16:00","COD_in":345.098389,"COD_in_name":630,"COD_off":11.525463,"COD_off_name":40,"COD_off_con":32,"TP_in":7.125289,"TP_in_name":7.1,"TP_off":0.069155,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":56.293404,"TN_in_name":65,"TN_off":9.53993,"TN_off_name":15,"TN_off_con":12,"andan_in":52.708332,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":535.648193,"SS_in_name":315,"SS_off":2.40162,"SS_off_name":10,"SS_off_con":8,"TDS_in":454.28244,"TDS_in_name":600,"T":"","pH":7.502315,"Q_in":3242,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3807.291748,3345.196777]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.903125]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929352,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 15","TEST_TIME":"2024/03/02 15:00","COD_in":345.381927,"COD_in_name":630,"COD_off":10.422453,"COD_off_name":40,"COD_off_con":32,"TP_in":7.125289,"TP_in_name":7.1,"TP_off":0.097512,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":56.293404,"TN_in_name":65,"TN_off":10.086805,"TN_off_name":15,"TN_off_con":12,"andan_in":48.333336,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":274.074097,"SS_in_name":315,"SS_off":2.083333,"SS_off_name":10,"SS_off_con":8,"TDS_in":497.685181,"TDS_in_name":600,"T":"","pH":7.486111,"Q_in":3314,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[3942.708252,3287.905029]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.878125]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929292,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 14","TEST_TIME":"2024/03/02 14:00","COD_in":269.953705,"COD_in_name":630,"COD_off":10.724074,"COD_off_name":40,"COD_off_con":32,"TP_in":5.454282,"TP_in_name":7.1,"TP_off":0.097512,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":52.777779,"TN_in_name":65,"TN_off":10.086805,"TN_off_name":15,"TN_off_con":12,"andan_in":46.076389,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":258.101868,"SS_in_name":315,"SS_off":2.199074,"SS_off_name":10,"SS_off_con":8,"TDS_in":457.175934,"TDS_in_name":600,"T":"","pH":7.490162,"Q_in":3408,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[4010.416748,3332.465332]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.880469]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929232,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 13","TEST_TIME":"2024/03/02 13:00","COD_in":269.953705,"COD_in_name":630,"COD_off":10.63426,"COD_off_name":40,"COD_off_con":32,"TP_in":5.454282,"TP_in_name":7.1,"TP_off":0.106481,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":52.777779,"TN_in_name":65,"TN_off":10.720487,"TN_off_name":15,"TN_off_con":12,"andan_in":42.881947,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":250,"SS_in_name":315,"SS_off":2.40162,"SS_off_name":10,"SS_off_con":8,"TDS_in":526.620361,"TDS_in_name":600,"T":"","pH":7.449653,"Q_in":3214,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[4010.416748,3459.780029]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.883594]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929172,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 12","TEST_TIME":"2024/03/02 12:00","COD_in":247.268509,"COD_in_name":630,"COD_off":10.512267,"COD_off_name":40,"COD_off_con":32,"TP_in":5.613426,"TP_in_name":7.1,"TP_off":0.10706,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":59.288197,"TN_in_name":65,"TN_off":10.47743,"TN_off_name":15,"TN_off_con":12,"andan_in":40.034721,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":244.675919,"SS_in_name":315,"SS_off":4.398148,"SS_off_name":10,"SS_off_con":8,"TDS_in":399.305573,"TDS_in_name":600,"T":"","pH":7.413195,"Q_in":3419,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[4135.416504,3536.168945]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.878125]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""},{"ID":929112,"TEST_DATE":"2024/03/02","TEST_HOUR":"2024/03/02 11","TEST_TIME":"2024/03/02 11:00","COD_in":246.98494,"COD_in_name":630,"COD_off":10.425,"COD_off_name":40,"COD_off_con":32,"TP_in":5.606192,"TP_in_name":7.1,"TP_off":0.115741,"TP_off_name":0.5,"TP_off_con":0.3,"TN_in":59.3316,"TN_in_name":65,"TN_off":11.215278,"TN_off_name":15,"TN_off_con":12,"andan_in":43.506943,"andan_in_name":58,"andan_off":1.006944,"andan_off_name":4,"andan_off_con":3.2,"SS_in":283.101868,"SS_in_name":315,"SS_off":5.584491,"SS_off_name":10,"SS_off_con":8,"TDS_in":358.796295,"TDS_in_name":600,"T":"","pH":7.445602,"Q_in":3314,"Q_in_name":4166.67,"continuity":"","check_rise":"","time_tips":"","cs_continuity":"","SVI":[187.852223,188.139059],"SVI_con":170,"SV":[90,92],"SV_con":80,"MLVSS":[1987,2064],"MLSS":"[4432.291504,3389.756836]","MLVSS_wentai":"","MLSS_wentai":"","DO_ana":[0.24,0.23],"DO_O":"[2.100000,2.893750]","DO_que":[0.22,0.2],"DO_que_wentai":"","DO_ana_wentai":"","DO_O_wentai":"","BOD_in":"","c":"","b":"","BTP_wending":"","JS_TN_wentai":"","CL_P04_YCZ":"","TP_LV":"","TP_LV_continuity":""}]
  76. rows = json.dumps(rows)
  77. feedback ={"2_2":"正常"}
  78. feedback = json.dumps(feedback)
  79. # 构建请求数据
  80. request_data = {
  81. "question": "什么是cod"
  82. }
  83. url = "http://10.0.0.28:8080/grpc/inferStreamRag"
  84. headers = {
  85. "Accept": "text/event-stream",
  86. "Content-Type": "application/json"
  87. }
  88. # 发送POST请求
  89. response = requests.post(url, headers=headers, json=request_data, stream=True)
  90. # 获取响应内容
  91. for line in response.iter_lines():
  92. if line:
  93. # 处理每一行事件数据
  94. print(line.decode('utf-8'))
  95. if __name__ == "__main__":
  96. ceshi()