| | |
| | | return tranReq.returnJsonState(true, null, null);
|
| | | }
|
| | |
|
| | |
|
| | | public ModelAndView updateOrder(SMTAIServerRequest tranReq) throws Exception {
|
| | | String title = tranReq.convParamToString("title", true);
|
| | | String orderId = tranReq.convParamToString("orderId", true);
|
| | | String wstypeid = tranReq.convParamToString("wstypeid", false);
|
| | | String wstypename = tranReq.convParamToString("wstypename", false);
|
| | | String urgencylevel = tranReq.convParamToString("urgencylevel", false);
|
| | | String shape = tranReq.convParamToString("shape", false);
|
| | | String deadline = tranReq.convParamToString("deadline", false);
|
| | | String stepstatus = tranReq.convParamToString("stepstatus", false);
|
| | | String originatetypetext = tranReq.convParamToString("originatetypetext", false);
|
| | | String content = tranReq.convParamToString("content", false);
|
| | | String address = tranReq.convParamToString("address", false);
|
| | | String stepid = tranReq.convParamToString("stepid", false);
|
| | | String org = tranReq.convParamToString("org", false);
|
| | | String deptname = tranReq.convParamToString("deptname", false);
|
| | | String dealtime = tranReq.convParamToString("dealtime", false);
|
| | | String username = tranReq.convParamToString("username", false);
|
| | | String contactname = tranReq.convParamToString("contactname", false);
|
| | | String contactphone = tranReq.convParamToString("contactphone", false);
|
| | | String acceptuserid = tranReq.convParamToString("acceptuserid", false);
|
| | | String acceptusername = tranReq.convParamToString("acceptusername", false);
|
| | | String acceptuseraccount = tranReq.convParamToString("acceptuseraccount", false);
|
| | | String dealuserid = tranReq.convParamToString("dealuserid", false);
|
| | | String dealusername = tranReq.convParamToString("dealusername", false);
|
| | | String dealuseraccount = tranReq.convParamToString("dealuseraccount", false);
|
| | | String flowstatus = tranReq.convParamToString("flowstatus", false);
|
| | | String attachment = tranReq.convParamToString("attachment", false);
|
| | | String creator = tranReq.convParamToString("creator", false);
|
| | | String isplan = tranReq.convParamToString("isplan", false);
|
| | | String originateid = tranReq.convParamToString("originateid", false);
|
| | | String appointstarttime = tranReq.convParamToString("appointstarttime", false);
|
| | | String appointendtime = tranReq.convParamToString("appointendtime", false);
|
| | | String parentid = tranReq.convParamToString("parentid", false);
|
| | | String relateids = tranReq.convParamToString("relateids", false);
|
| | | String oname = tranReq.convParamToString("oname", false);
|
| | | String otype = tranReq.convParamToString("otype", false);
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | | try {
|
| | |
|
| | | db.executeSQL(
|
| | | "UPDATE work_order_list SET "
|
| | | + "title = ?, "
|
| | | + "wstypeid = ?, "
|
| | | + "wstypename = ?, "
|
| | | + "urgencylevel = ?, "
|
| | | + "shape = ?, "
|
| | | + "deadline = ?, "
|
| | | + "stepstatus = ?, "
|
| | | + "originatetypetext = ?, "
|
| | | + "content = ?, "
|
| | | + "address = ?, "
|
| | | + "step_id = ?, "
|
| | | + "org = ?, "
|
| | | + "deptname = ?, "
|
| | | + "dealtime = ?, "
|
| | | + "username = ?, "
|
| | | + "contactname = ?, "
|
| | | + "contactphone = ?, "
|
| | | + "acceptuserid = ?, "
|
| | | + "acceptusername = ?, "
|
| | | + "acceptuseraccount = ?, "
|
| | | + "dealuserid = ?, "
|
| | | + "dealusername = ?, "
|
| | | + "dealuseraccount = ?, "
|
| | | + "flowstatus = ?, "
|
| | | + "attachment = ?, "
|
| | | + "creator = ?, "
|
| | | + "createtime = ?, "
|
| | | + "isplan = ?, "
|
| | | + "originateid = ?, "
|
| | | + "appointstarttime = ?, "
|
| | | + "appointendtime = ?, "
|
| | | + "parentid = ?, "
|
| | | + "relateids = ?, "
|
| | | + "is_notify = ?, "
|
| | | + "oname = ?, "
|
| | | + "otype = ? "
|
| | | + "WHERE order_id = ?",
|
| | | new Object[]{
|
| | | title,
|
| | | wstypeid,
|
| | | wstypename,
|
| | | urgencylevel,
|
| | | shape,
|
| | | deadline,
|
| | | stepstatus,
|
| | | originatetypetext,
|
| | | content,
|
| | | address,
|
| | | stepid,
|
| | | org,
|
| | | deptname,
|
| | | dealtime,
|
| | | username,
|
| | | contactname,
|
| | | contactphone,
|
| | | acceptuserid,
|
| | | acceptusername,
|
| | | acceptuseraccount,
|
| | | dealuserid,
|
| | | dealusername,
|
| | | dealuseraccount,
|
| | | flowstatus,
|
| | | attachment,
|
| | | creator,
|
| | | new Date(),
|
| | | isplan,
|
| | | originateid,
|
| | | appointstarttime,
|
| | | appointendtime,
|
| | | parentid,
|
| | | relateids,
|
| | | "N",
|
| | | oname,
|
| | | otype,
|
| | | orderId
|
| | | });
|
| | |
|
| | |
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | |
|
| | | return tranReq.returnJsonState(true, null, null);
|
| | | }
|
| | |
|
| | | /**
|
| | | * èç¹ç¶ææ´æ°
|
| | | *
|
| | |
| | | return tranReq.returnJsonState(true, null, null);
|
| | | }
|
| | |
|
| | | public ModelAndView getOrderList(SMTAIServerRequest tranReq) throws Exception {
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | | try {
|
| | | DBRecords recs = db.querySQL("SELECT * FROM work_order_list", null);
|
| | | if (recs.getRowCount() != 0) {
|
| | | jsonWr.beginArray("values"); // å¼å§ä¸ä¸ªæ°ç»ï¼key为 "values"
|
| | | public ModelAndView getOrderList(SMTAIServerRequest tranReq) throws Exception {
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | | try {
|
| | | DBRecords recs =
|
| | | db.querySQL(
|
| | | "SELECT *,ST_AsText(address_shape) as address_shape_str ,ST_AsText(shape) as shape_str FROM work_order_list",
|
| | | null);
|
| | | if (recs.getRowCount() != 0) {
|
| | | jsonWr.beginArray("values"); // å¼å§ä¸ä¸ªæ°ç»ï¼key为 "values"
|
| | |
|
| | | for (DBRecord rec : recs.getRecords()) {
|
| | | jsonWr.beginMap(null); // æ¯æ¡è®°å½æ¯ä¸ä¸ªå¯¹è±¡
|
| | | for (String colName : rec.getColNames()) {
|
| | | jsonWr.addKeyValue(colName, rec.getString(colName)); // æ·»å æ¯ä¸ªå段
|
| | | }
|
| | | jsonWr.endMap(); // ç»æä¸ä¸ªå¯¹è±¡
|
| | | }
|
| | | for (DBRecord rec : recs.getRecords()) {
|
| | | jsonWr.beginMap(null); // æ¯æ¡è®°å½æ¯ä¸ä¸ªå¯¹è±¡
|
| | | for (String colName : rec.getColNames()) {
|
| | | jsonWr.addKeyValue(colName, rec.getString(colName)); // æ·»å æ¯ä¸ªå段
|
| | | }
|
| | | jsonWr.endMap(); // ç»æä¸ä¸ªå¯¹è±¡
|
| | | }
|
| | |
|
| | | jsonWr.endArray(); // ç»ææ°ç»
|
| | | jsonWr.endArray(); // ç»ææ°ç»
|
| | |
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } else {
|
| | | return tranReq.returnJsonState(false, "æªæ¾å°å·¥å", null);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | throw new Exception("æ¥è¯¢å·¥å失败", e);
|
| | | }
|
| | | }
|
| | |
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } else {
|
| | | return tranReq.returnJsonState(false, "æªæ¾å°å·¥å", null);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | throw new Exception("æ¥è¯¢å·¥å失败", e);
|
| | | }
|
| | | }
|
| | |
|
| | | public ModelAndView disconnectBroadcastChat(SMTAIServerRequest tranReq) throws Exception
|
| | | {
|
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smtaiserver.smtaiserver.control; |
| | | |
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp; |
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase; |
| | | import com.smtservlet.core.SMTRequest; |
| | | import com.smtservlet.util.SMTJsonWriter; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** lightRag controller */ |
| | | public class SMTLightRAGController { |
| | | private static Logger _logger = LogManager.getLogger(SMTLightRAGController.class); |
| | | |
| | | /** |
| | | * è·ålightragæå¡çå¯å¨å表 |
| | | * |
| | | * @param tranReq |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ModelAndView getLightragServerList(SMTRequest tranReq) throws Exception { |
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); |
| | | try { |
| | | SMTDatabase.DBRecords records = db.querySQL("SELECT * FROM lightrag_server_list", null); |
| | | if (records.getRowCount() == 0) return tranReq.returnJsonState(true, null, null); |
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); |
| | | for (int i = 0; i < records.getRowCount(); i++) { |
| | | SMTDatabase.DBRecord record = records.getRecord(i); |
| | | jsonWr.addKeyValue("server_id", record.getValue("server_id")); |
| | | jsonWr.addKeyValue("server_title", record.getValue("server_title")); |
| | | jsonWr.addKeyValue("server_port", record.getValue("server_port")); |
| | | jsonWr.addKeyValue("is_enable", record.getValue("is_enable")); |
| | | } |
| | | return tranReq.returnJson(jsonWr); |
| | | } catch (Exception e) { |
| | | throw new Exception("getLightragServerList error" + e); |
| | | } finally { |
| | | db.close(); |
| | | } |
| | | } |
| | | |
| | | public ModelAndView updateLightragServerEnable(SMTRequest tranReq) throws Exception { |
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); |
| | | try { |
| | | // ä»è¯·æ±ä¸è·ååæ° |
| | | String serverId = tranReq.convParamToString("server_id", true); |
| | | String isEnable = tranReq.convParamToString("is_enable", true); |
| | | |
| | | // åæ°æ ¡éª |
| | | if (serverId == null || isEnable == null) { |
| | | return tranReq.returnJsonState(false, "åæ°ç¼ºå¤±: server_id æ is_enable ä¸è½ä¸ºç©º", null); |
| | | } |
| | | |
| | | // æ§è¡æ´æ° |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("server_id", serverId); |
| | | params.put("is_enable", isEnable); |
| | | |
| | | int affectedRows = |
| | | db.executeSQL( |
| | | "UPDATE lightrag_server_list SET is_enable = ? WHERE server_id = ?", |
| | | new Object[] {isEnable, serverId}); |
| | | |
| | | if (affectedRows == 0) { |
| | | return tranReq.returnJsonState(false, "æªæ¾å°å¯¹åºç server_idï¼æ´æ°å¤±è´¥", null); |
| | | } |
| | | |
| | | // æåè¿å |
| | | return tranReq.returnJsonState(true, null, null); |
| | | |
| | | } catch (Exception e) { |
| | | throw new Exception("updateLightragServerEnable error: " + e); |
| | | } finally { |
| | | db.close(); |
| | | } |
| | | } |
| | | |
| | | public ModelAndView addLightragServer(SMTRequest tranReq) throws Exception { |
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); |
| | | try { |
| | | // ä»è¯·æ±ä¸è·ååæ° |
| | | String serverId = tranReq.convParamToString("server_id", true); |
| | | String serverTitle = tranReq.convParamToString("server_title", true); |
| | | String serverPort = tranReq.convParamToString("server_port", true); |
| | | String isEnable = tranReq.convParamToString("is_enable", true); |
| | | |
| | | // åæ°æ ¡éª |
| | | if (serverId == null || serverTitle == null || serverPort == null || isEnable == null) { |
| | | return tranReq.returnJsonState( |
| | | false, "åæ°ç¼ºå¤±: server_idãserver_titleãserver_portãis_enable ä¸è½ä¸ºç©º", null); |
| | | } |
| | | |
| | | // å
æ¥è¯¢ server_id æ¯å¦å·²åå¨ |
| | | SMTDatabase.DBRecords existingRecords = |
| | | db.querySQL( |
| | | "SELECT server_id FROM lightrag_server_list WHERE server_id = ?", |
| | | new Object[] {serverId}); |
| | | |
| | | if (existingRecords.getRowCount() > 0) { |
| | | return tranReq.returnJsonState(false, "server_id å·²åå¨ï¼ä¸è½é夿°å¢", null); |
| | | } |
| | | |
| | | // æ§è¡æå
¥ |
| | | int affectedRows = |
| | | db.executeSQL( |
| | | "INSERT INTO lightrag_server_list (server_id, server_title, server_port, is_enable) VALUES (?, ?, ?, ?)", |
| | | new Object[] {serverId, serverTitle, serverPort, isEnable}); |
| | | |
| | | if (affectedRows == 0) { |
| | | return tranReq.returnJsonState(false, "æ°å¢å¤±è´¥", null); |
| | | } |
| | | |
| | | // æåè¿å |
| | | return tranReq.returnJsonState(true, null, null); |
| | | |
| | | } catch (Exception e) { |
| | | throw new Exception("addLightragServer error: " + e); |
| | | } finally { |
| | | db.close(); |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.util.LinkedHashMap;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | | import org.locationtech.proj4j.CRSFactory;
|
| | | import org.locationtech.proj4j.CoordinateReferenceSystem;
|
| | | import org.locationtech.proj4j.CoordinateTransform;
|
| | |
| | | import com.smtaiserver.smtaiserver.javaai.metrics.base.SMTMetricsDef;
|
| | | import com.smtaiserver.smtaiserver.javaai.querydetail.SMTAIQueryDetail;
|
| | | import com.smtaiserver.smtaiserver.javaai.qwen.SMTQwenAgentManager;
|
| | | import com.smtaiserver.smtaiserver.javaai.qwen.SMTQwenApp;
|
| | | import com.smtaiserver.smtaiserver.javaai.qwen.agent.SMTQwenAgent;
|
| | | import com.smtaiserver.smtaiserver.javaai.qwen.agent.SMTQwenAgentKnowlgFile;
|
| | | import com.smtservlet.util.Json;
|
| | |
| | | {
|
| | | @Value("${hswater.tables.global_config}")
|
| | | protected String _tableGlobalConfig;
|
| | | |
| | | private static Logger _logger = LogManager.getLogger(SMTQwenApp.class);
|
| | |
|
| | | public static String makeQueryStringAllRegExp(String str)
|
| | | {
|
| | |
| | | @Override
|
| | | public boolean onNextRecord(DBRecord rec) throws Exception
|
| | | {
|
| | | SMTQwenAgent agent = (SMTQwenAgent)Class.forName(rec.getString("clz_name")).newInstance();
|
| | | agent.initInstance(rec);
|
| | | manager.addAgent(agent);
|
| | | try
|
| | | {
|
| | | SMTQwenAgent agent = (SMTQwenAgent)Class.forName(rec.getString("clz_name")).newInstance();
|
| | | agent.initInstance(rec);
|
| | | manager.addAgent(agent);
|
| | | }
|
| | | catch(Exception ex)
|
| | | {
|
| | | _logger.fatal("load agent error and skip it : " + rec.getString("agent_id"), ex);
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | SMTAIServerApp.convJSToJsonWriter(nativeObject, jsonWr);
|
| | | SMTAIServerApp.getApp().webSocketApp(jsonWr.getFullJson());
|
| | | }
|
| | | |
| | | public Object llmAnswerToJson(String sJson)
|
| | | {
|
| | | Object object = SMTAIServerApp.convJsonToJS(SMTStatic.convLLMAnswerToJson(sJson, false));
|
| | | return object;
|
| | | }
|
| | |
|
| | | public Object getArg(String key)
|
| | | {
|
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smtaiserver.smtaiserver.javaai.qwen.agent; |
| | | |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp; |
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerRequest; |
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase; |
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord; |
| | | import com.smtaiserver.smtaiserver.javaai.SMTJavaAIError; |
| | | import com.smtaiserver.smtaiserver.javaai.llm.core.SMTLLMConnect; |
| | | import com.smtservlet.util.Json; |
| | | import com.smtservlet.util.SMTJsonWriter; |
| | | import com.smtservlet.util.SMTStatic; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import okhttp3.MediaType; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.RequestBody; |
| | | import okhttp3.Response; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.Element; |
| | | import org.dom4j.Node; |
| | | |
| | | public class SMTQwenAgentLightRAG extends SMTQwenAgent |
| | | { |
| | | |
| | | public String port; |
| | | public static class SMTQueryServerInfo { |
| | | public String _serverId; |
| | | public String _alias; |
| | | public String _querySql; |
| | | |
| | | public SMTQueryServerInfo(Element element) { |
| | | _serverId = element.attributeValue("server_id"); |
| | | _alias = element.attributeValue("alias"); |
| | | |
| | | Element queryElement = element.element("QUERY_NAME"); |
| | | _querySql = queryElement.getText().trim(); |
| | | } |
| | | |
| | | public DBRecord queryServer(SMTDatabase db) throws Exception { |
| | | SMTDatabase.DBRecords recs = db.querySQL(_querySql, null); |
| | | if (recs.getRowCount() > 0) { |
| | | return recs.getRecord(0); |
| | | } else { |
| | | throw new Exception("æªæ¾å° server_id=" + _serverId + " çè®°å½"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void initInstance(DBRecord rec) throws Exception |
| | | { |
| | | super.initInstance(rec); |
| | | try { |
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); |
| | | try { |
| | | // 1. å è½½ XML |
| | | Document doc = SMTStatic.convStrToXmlDoc("<ROOT>" + rec.getString("clz_arguments") + "</ROOT>"); |
| | | |
| | | // 2. è§£æ SERVER_LIST |
| | | for (Node node : doc.selectNodes("ROOT/SERVER_LIST/SERVER_SQL")) { |
| | | SMTQueryServerInfo server = new SMTQueryServerInfo((Element) node); |
| | | DBRecord serverRec = server.queryServer(db); |
| | | port= serverRec.getString("server_port"); |
| | | System.out.println("Server æ¥è¯¢ç»æ: " + serverRec); |
| | | } |
| | | } finally { |
| | | db.close(); |
| | | } |
| | | } catch (Exception ex) { |
| | | throw new Exception("init server info error : " + this._agentId, ex); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public SMTJavaAIError callAgents(String jsonPath, Json jsonArgs, SMTLLMConnect llm, String question, SMTAIServerRequest tranReq) throws Exception |
| | | { |
| | | SMTJsonWriter jsonWrResult = tranReq.getResultJsonWr(); |
| | | |
| | | StringBuilder sbAnswer = new StringBuilder(); |
| | | SMTJavaAIError error = callRAGServer(question, tranReq, sbAnswer); |
| | | if(error != null) |
| | | return error; |
| | | jsonWrResult.addKeyValue("json_ok", true); |
| | | jsonWrResult.addKeyValue("answer_type", "knowledge"); |
| | | jsonWrResult.beginArray("knowledge"); |
| | | { |
| | | jsonWrResult.beginMap(null); |
| | | jsonWrResult.addKeyValue("answer", sbAnswer.toString()); |
| | | jsonWrResult.endMap(); |
| | | } |
| | | jsonWrResult.endArray(); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | private SMTJavaAIError callRAGServer(String question, SMTAIServerRequest tranReq, StringBuilder sbAnswer) throws Exception { |
| | | System.out.println("è¿å
¥äºlight"); |
| | | OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| | | .readTimeout(0, TimeUnit.SECONDS) // ä¸è¶
æ¶ï¼æ¯ææµ |
| | | .build(); |
| | | HttpServletResponse response = tranReq.getResponse(); |
| | | response.setContentType("application/json"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | |
| | | SMTJsonWriter jsonWriter = new SMTJsonWriter(false); |
| | | jsonWriter.addKeyValue("query",question); |
| | | jsonWriter.addKeyValue("mode","global"); |
| | | jsonWriter.addKeyValue("response_type","Multiple Paragraphs"); |
| | | jsonWriter.addKeyValue("top_k",10); |
| | | jsonWriter.addKeyValue("max_token_for_text_unit",4000); |
| | | jsonWriter.addKeyValue("max_token_for_global_context",4000); |
| | | jsonWriter.addKeyValue("max_token_for_local_context",4000); |
| | | jsonWriter.addKeyValue("only_need_context",false); |
| | | jsonWriter.addKeyValue("only_need_prompt",false); |
| | | jsonWriter.addKeyValue("stream",true); |
| | | jsonWriter.addKeyValue("history_turns",3); |
| | | String json = jsonWriter.getRootJson().toString(); |
| | | |
| | | RequestBody body = RequestBody.create(MediaType.parse("application/json"), json); |
| | | |
| | | String streamHook ="http://localhost:"+port; |
| | | String lightragQueyStream = (String)SMTAIServerApp.getApp().getGlobalConfig("lightrag_quey_stream"); |
| | | Request request = new Request.Builder() |
| | | .url(streamHook+lightragQueyStream) |
| | | .post(body) |
| | | .build(); |
| | | tranReq.sendChunkedBlock("begin_stream", ""); |
| | | ObjectMapper objectMapper = new ObjectMapper(); // ç¨äºè§£æ JSON |
| | | try (Response lightRagResp = okHttpClient.newCall(request).execute()) { |
| | | if (lightRagResp.body() != null) { |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(lightRagResp.body().byteStream(), StandardCharsets.UTF_8)); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | try { |
| | | // æ¯è¡æ¯ {"response": "xxx"}ï¼æä»¬åªååº "xxx" |
| | | JsonNode node = objectMapper.readTree(line); |
| | | String content = node.get("response").asText(); // èªå¨å¤çç¼ç é®é¢ï¼è¿åçæ¯ä¸æ |
| | | |
| | | // éå符æ¨é |
| | | for (char ch : content.toCharArray()) { |
| | | tranReq.sendChunkedStreamBlock(com.smtservlet.util.SMTStatic.toString(ch)); |
| | | sbAnswer.append(ch); |
| | | Thread.sleep(50); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | System.err.println("è§£æå¤±è´¥ï¼" + line); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | String errMsg = "è°ç¨ LightRAG 失败: " + e.getMessage(); |
| | | for (char ch : errMsg.toCharArray()) { |
| | | tranReq.sendChunkedStreamBlock(com.smtservlet.util.SMTStatic.toString(ch)); |
| | | sbAnswer.append(ch); |
| | | } |
| | | } finally { |
| | | tranReq.sendChunkedBlock("end_stream", ""); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.smtaiserver.smtaiserver.lightrag;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
|
| | | import com.smtservlet.util.Json;
|
| | | import com.smtservlet.util.SMTStatic;
|
| | | import java.io.BufferedReader;
|
| | | import java.io.File;
|
| | |
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.net.BindException;
|
| | |
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
|
| | | import com.smtservlet.util.Json;
|
| | | import com.smtservlet.util.SMTStatic;
|
| | |
|
| | |
|
| | | public class LightragServer
|
| | | {
|
| | |
| | |
|
| | | ProcessBuilder pbuilder=new ProcessBuilder(SMTStatic.convProcessArg(params));
|
| | | pbuilder.redirectErrorStream(true);
|
| | | // 设置 PYTHONIOENCODING ç¯å¢åé为 utf-8ï¼ç¡®ä¿ Python è¾åºä½¿ç¨ UTF-8 ç¼ç
|
| | |
|
| | |
|
| | | pbuilder.directory(new File(jsonConfig.getJson("path").asString()));
|
| | | Map<String, String> runEnv = pbuilder.environment();
|
| | | runEnv.put("PYTHONIOENCODING", "utf-8");
|
| | | SMTAIServerApp.getApp().setLightragServerDbEnv(runEnv);
|
| | | runEnv.put("POSTGRES_WORKSPACE", _id);
|
| | | runEnv.put("PORT", _port);
|
| | | runEnv.put("PYTHONIOENCODING", "utf-8");
|
| | | _process = pbuilder.start();
|
| | |
|
| | | _thread = new Thread()
|
| | |
| | | ]
|
| | | }
|
| | | ]
|
| | | },
|
| | | "sys/update_order":{
|
| | | "map":{"class":"#SMTJavaAIControl", "method":"updateOrder"}, "no_shrio":false,
|
| | | "swaggers":[
|
| | | {
|
| | | "tags" : ["ä¿®æ¹å·¥åå
容"],
|
| | | "title" : "ä¿®æ¹å·¥åå
容",
|
| | | "parameters" : [
|
| | | {"name": "title", "title": "æ é¢", "required": false},
|
| | | {"name": "wstypeid", "title": "ç±»åç¼å·", "required": false},
|
| | | {"name": "wstypename", "title": "ç±»ååç§°", "required": false},
|
| | | {"name": "urgencylevel", "title": "ç´§æ¥çº§å«", "required": false},
|
| | | {"name": "shape", "title": "æ´¾ååæ ", "required": false},
|
| | | {"name": "deadline", "title": "å¤çæ¶é", "required": false},
|
| | | {"name": "stepstatus", "title": "å·¥åè¿åº¦ç¶æ", "required": false},
|
| | | {"name": "originatetypetext", "title": "æ¥æºç±»å", "required": false},
|
| | | {"name": "content", "title": "å
容", "required": false},
|
| | | {"name": "address", "title": "å°å", "required": false},
|
| | | {"name": "stepid", "title": "å·¥åæ¥éª¤", "required": false},
|
| | | {"name": "org", "title": "æå±åå
¬å¸", "required": false},
|
| | | {"name": "deptname", "title": "å·¥åæå±é¨é¨åç§°", "required": false},
|
| | | {"name": "dealtime", "title": "å¤çæ¶é´", "required": false},
|
| | | {"name": "username", "title": "ç¨æ·åç§°", "required": false},
|
| | | {"name": "contactname", "title": "è系人", "required": false},
|
| | | {"name": "contactphone", "title": "èç³»çµè¯", "required": false},
|
| | | {"name": "acceptuserid", "title": "æ¥å人id", "required": false},
|
| | | {"name": "acceptusername", "title": "æ¥å人åç§°", "required": false},
|
| | | {"name": "acceptuseraccount", "title": "æ¥å人账å·", "required": false},
|
| | | {"name": "dealuserid", "title": "å¤ç人id", "required": false},
|
| | | {"name": "dealusername", "title": "å¤ç人åç§°", "required": false},
|
| | | {"name": "dealuseraccount", "title": "å¤ç人账å·", "required": false},
|
| | | {"name": "flowstatus", "title": "å·¥åç¶æ", "required": false},
|
| | | {"name": "attachment", "title": "éä»¶", "required": false},
|
| | | {"name": "creator", "title": "å建人", "required": false},
|
| | | {"name": "createtime", "title": "å建æ¶é´", "required": false},
|
| | | {"name": "isplan", "title": "æ¯å¦è®¡åå·¥å", "required": false},
|
| | | {"name": "originateid", "title": "æ¥æºç¼å·", "required": false},
|
| | | {"name": "appointstarttime", "title": "é¢çº¦å¼å§æ¶é´", "required": false},
|
| | | {"name": "appointendtime", "title": "é¢çº¦ç»ææ¶é´", "required": false},
|
| | | {"name": "parentid", "title": "ç¶çº§ç¼å·", "required": false},
|
| | | {"name": "relateids", "title": "å
³èç¼å·", "required": false},
|
| | | {"name": "orderId", "title": "å·¥åid", "required": true}
|
| | | ]
|
| | | }
|
| | | ]
|
| | | }
|
| | |
|
| | |
|
¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "lightrag/get_lightrag_server_list":{"map":{"class":"#SMTLightRAGController", "method":"getLightragServerList"}, |
| | | "swaggers":[ |
| | | { "tags" : ["è·ålightragæå¡çå¯å¨å表"], |
| | | "title" : "è·ålightragæå¡çå¯å¨å表", |
| | | "parameters" : [ |
| | | |
| | | ] |
| | | } |
| | | ] |
| | | }, |
| | | "lightrag/update_lightrag_server_enable":{"map":{"class":"#SMTLightRAGController", "method":"updateLightragServerEnable"}, |
| | | "swaggers":[ |
| | | { "tags" : ["ä¿®æ¹lightragæå¡æ¯å¦åå¸ç¶æ"], |
| | | "title" : "è·ålightragæå¡çå¯å¨å表", |
| | | "parameters" : [ |
| | | {"name":"server_id", "title":"æå¡id", "required":true}, |
| | | {"name":"is_enable", "title":"æ¯å¦åå¸", "required":true} |
| | | ] |
| | | } |
| | | ] |
| | | }, |
| | | "lightrag/add_lightrag_server": { |
| | | "map": { |
| | | "class": "#SMTLightRAGController", |
| | | "method": "addLightragServer" |
| | | }, |
| | | "swaggers": [ |
| | | { |
| | | "tags": ["æ°å¢lightragæå¡"], |
| | | "title": "æ°å¢lightragæå¡ä¿¡æ¯", |
| | | "parameters": [ |
| | | {"name": "server_id", "title": "æå¡idï¼å¯ä¸ï¼", "required": true}, |
| | | {"name": "server_title", "title": "æå¡åç§°", "required": true}, |
| | | {"name": "server_port", "title": "æå¡ç«¯å£", "required": true}, |
| | | {"name": "is_enable", "title": "æ¯å¦åå¸ï¼0-å¦ 1-æ¯ï¼", "required": true} |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | |
| | | } |
| | |
| | | <bean id="SMTSupervisorManagerControl" class="com.smtaiserver.smtaiserver.control.SMTSupervisorManagerControl"/>
|
| | | <bean id="SMTMetricsManagerControl" class="com.smtaiserver.smtaiserver.control.SMTMetricsManagerControl"/>
|
| | | <bean id="SMTSystemManagerControl" class="com.smtaiserver.smtaiserver.control.SMTSystemManagerControl"/>
|
| | | <bean id="SMTLightRAGController" class="com.smtaiserver.smtaiserver.control.SMTLightRAGController"/>
|
| | | <bean id="SMTWorkflowManagerControl" class="com.smtaiserver.smtaiserver.control.SMTWorkflowManagerControl"/>
|
| | | <bean id="SMTAIMapControl" class="com.smtaiserver.smtaiserver.control.SMTAIMapControl"/>
|
| | | <bean id="SMTAIWeixinControl" class="com.smtaiserver.smtaiserver.control.SMTAIWeixinControl"/>
|
| | |
| | | HttpServletRequest request,
|
| | | HttpServletResponse response) throws Exception {
|
| | |
|
| | | if(request.getMethod().equalsIgnoreCase("GET"))
|
| | | {
|
| | | response.setCharacterEncoding("UTF-8");
|
| | | response.setContentType("text/html;charset=UTF-8");
|
| | | response.getOutputStream().write(_msg.getBytes("UTF-8"));
|
| | | }
|
| | | else
|
| | | // if(request.getMethod().equalsIgnoreCase("GET"))
|
| | | // {
|
| | | // response.setCharacterEncoding("UTF-8");
|
| | | // response.setContentType("text/html;charset=UTF-8");
|
| | | // response.getOutputStream().write(_msg.getBytes("UTF-8"));
|
| | | // }
|
| | | // else
|
| | | {
|
| | | if(_url != null)
|
| | | {
|