| | |
| | | {
|
| | | return "附加文件 : " + _fileName + "\n" + _fileText + "\n";
|
| | | }
|
| | | |
| | | public void addToJson(SMTJsonWriter jsonWr)
|
| | | {
|
| | | jsonWr.addKeyValue("file_id", _fileId);
|
| | | jsonWr.addKeyValue("file_name", _fileName);
|
| | | jsonWr.addKeyValue("file_content", _fileText);
|
| | | }
|
| | | }
|
| | |
|
| | | private static Logger _logger = LogManager.getLogger(SMTAIServerRequest.class);
|
| | |
| | | private List<SMTJsonWriter> _listJsonWrResult = null;
|
| | | private boolean _disableConclusion = false;
|
| | | private List<AIAttachFile> _listAttchFile = null;
|
| | | private Json _jsonAttachTables = null;
|
| | | private Json _jsonAttachMetrics = null;
|
| | | private long _lastSendChunkedStreamBlockTick = 0;
|
| | | private boolean _sendStarStream = false; // 将输出文字变成*
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public boolean setSendStarStream(boolean isSetStartStream)
|
| | | {
|
| | | boolean org = _sendStarStream;
|
| | | if("true".equals(System.getProperty("show_ai_stream")))
|
| | | isSetStartStream = false;
|
| | | _sendStarStream = isSetStartStream; |
| | | return org;
|
| | | }
|
| | | |
| | | public void setAttachTables(Json jsonTables)
|
| | | {
|
| | | _jsonAttachTables = jsonTables;
|
| | | }
|
| | |
|
| | | public void setJsonAttachMetrics(Json attachMetrics)
|
| | | {
|
| | | _jsonAttachMetrics = attachMetrics;
|
| | | }
|
| | | public String[] getAttachMessage()
|
| | | {
|
| | | List<String> list = new ArrayList<>();
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | if(_jsonAttachTables != null)
|
| | | {
|
| | | for(Json jsonAttachTable : _jsonAttachTables.asJsonList())
|
| | | {
|
| | | StringBuilder sbText = new StringBuilder();
|
| | | sbText.append("现有表格:" + jsonAttachTable.getJson("title").asString() + "\n");
|
| | | List<Json> jsonColumns = jsonAttachTable.getJson("columns").asJsonList();
|
| | | for(int i = 0; i < jsonColumns.size(); i ++)
|
| | | {
|
| | | if(i > 0)
|
| | | sbText.append(",");
|
| | | sbText.append(jsonColumns.get(i).asString());
|
| | | }
|
| | | sbText.append("\n");
|
| | | for(Json jsonRecord : jsonAttachTable.getJson("values").asJsonList())
|
| | | {
|
| | | List<Json> listRec = jsonRecord.asJsonList();
|
| | | for(int i = 0; i < listRec.size(); i ++)
|
| | | {
|
| | | if(i > 0)
|
| | | sbText.append(",");
|
| | | if(listRec.get(i).isNull())
|
| | | sbText.append("");
|
| | | else
|
| | | sbText.append(listRec.get(i).asString()); |
| | | }
|
| | | sbText.append("\n");
|
| | | }
|
| | | sbText.append("\n");
|
| | | list.add(sbText.toString());
|
| | | }
|
| | | }
|
| | | |
| | | if(_jsonAttachMetrics != null)
|
| | | {
|
| | | for(Json jsonAttachTable : _jsonAttachMetrics.asJsonList())
|
| | | {
|
| | | StringBuilder sbText = new StringBuilder();
|
| | | sbText.append("现有表格:" + jsonAttachTable.getJson("title").asString() + "\n");
|
| | | List<Json> jsonColumns = jsonAttachTable.getJson("columns").asJsonList();
|
| | | for(int i = 0; i < jsonColumns.size(); i ++)
|
| | | {
|
| | | if(i > 0)
|
| | | sbText.append(",");
|
| | | sbText.append(jsonColumns.get(i).asString());
|
| | | }
|
| | | sbText.append("\n");
|
| | | for(Json jsonRecord : jsonAttachTable.getJson("values").asJsonList())
|
| | | {
|
| | | List<Json> listRec = jsonRecord.asJsonList();
|
| | | for(int i = 0; i < listRec.size(); i ++)
|
| | | {
|
| | | if(i > 0)
|
| | | sbText.append(",");
|
| | | if(listRec.get(i).isNull())
|
| | | sbText.append("");
|
| | | else
|
| | | sbText.append(listRec.get(i).asString()); |
| | | }
|
| | | sbText.append("\n");
|
| | | }
|
| | | sbText.append("\n");
|
| | | list.add(sbText.toString());
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | return list.size() == 0 ? null : list.toArray(new String[list.size()]);
|
| | | }
|
| | | |
| | | public void addAttachMessageToJson(Json jsonResult)
|
| | | {
|
| | | if(_listAttchFile != null)
|
| | | {
|
| | | SMTJsonWriter jsonWr = new SMTJsonWriter(true);
|
| | | for(AIAttachFile file : _listAttchFile)
|
| | | {
|
| | | jsonWr.beginMap(null);
|
| | | file.addToJson(jsonWr);
|
| | | jsonWr.endMap();
|
| | | }
|
| | | |
| | | jsonResult.set("attach_files", jsonWr.getRootJson());
|
| | | }
|
| | | |
| | | if(_jsonAttachTables != null)
|
| | | {
|
| | | jsonResult.set("attach_tables", _jsonAttachTables);
|
| | | }
|
| | | if(_jsonAttachMetrics != null)
|
| | | {
|
| | | jsonResult.set("attach_metrics", _jsonAttachMetrics);
|
| | | }
|
| | | }
|
| | |
|
| | | public void addAttachFile(AIAttachFile attachFile)
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public void sendChunkedStreamBlock(String stream) throws Exception
|
| | | {
|
| | | if(_sendStarStream)
|
| | | {
|
| | | if((System.currentTimeMillis() - _lastSendChunkedStreamBlockTick) < 2000)
|
| | | return;
|
| | | |
| | | _lastSendChunkedStreamBlockTick = System.currentTimeMillis();
|
| | | |
| | | stream = "#";
|
| | | if(stream.indexOf("\n") >= 0)
|
| | | stream += "\n";
|
| | | }
|
| | | sendChunkedBlock("send_stream", stream);
|
| | | }
|
| | | |
| | | public void sendChunkedBlock(String mode, Object value) throws Exception
|
| | | {
|
| | | if(!_isChunked)
|
| | | return;
|
| | | |
| | | Json jsonResult;
|
| | |
|
| | | if(value == null)
|
| | |
| | | _listChatExecProcess = new ArrayList<>();
|
| | | _listChatExecProcess.add(jsonResult);
|
| | | }
|
| | | _logger.info("sendChunkedBlock:" + jsonResult.toString());
|
| | | String text = URLEncoder.encode(jsonResult.toString(), "UTF-8").replace("+", "%20") + "\n";
|
| | | |
| | | this.getResponse().getOutputStream().write(text.getBytes("UTF-8"));
|
| | |
|
| | | // this.getResponse().getWriter().print(String.format(
|
| | | // "%d\r\n%s\r\n", text.length(), text
|
| | | // ));
|
| | | this.getResponse().flushBuffer();
|
| | | if(!_isChunked)
|
| | | {
|
| | | _logger.info("NO sendChunkedBlock:" + jsonResult.toString());
|
| | | }
|
| | | else
|
| | | {
|
| | | _logger.info("sendChunkedBlock:" + jsonResult.toString());
|
| | | String text = URLEncoder.encode(jsonResult.toString(), "UTF-8").replace("+", "%20") + "\n";
|
| | | |
| | | this.getResponse().getOutputStream().write(text.getBytes("UTF-8"));
|
| | | |
| | | // this.getResponse().getWriter().print(String.format(
|
| | | // "%d\r\n%s\r\n", text.length(), text
|
| | | // ));
|
| | | this.getResponse().flushBuffer();
|
| | | }
|
| | | }
|
| | |
|
| | | public String getClientAddr()
|