版本:1.10.0 社区版,通过docker运行
问题描述:
SQLBot小助手高级应用设置中,我在获取高级应用 API 接口 的服务里,回调SQLBot的OpenAPI接口(/api/v1/datasource/get/{id} /api/v1/datasource/tableList/{id} /api/v1/datasource/fieldList/{id})获取数据源信息并拼接返回结果,会报读超时错误。
以下为请求路径图:
以下为界面效果图:
以下为java服务接口代码块
@RestController
@RequestMapping("/ai/faq")
@Slf4j
public class AIFAQController {
@Autowired
private SQLBotService sqlBotService;
/**
* @see "https://sqlbot.org/docs/v1/embedding_integration/#24-api"
*/
@GetMapping(value = "/sqlbot/datasource")
public ResponseEntity<RespEntity<JSONArray>> sqlbotDatasource( @RequestParam Map<String, Object> params ) {
return R.data( getExample() );
}
public JSONArray getExample() {
JSONObject requestBody = new JSONObject();
requestBody.put( "fieldName", "" );
JSONObject sqlbotDs = sqlBotService.post( "/api/v1/datasource/get/1", JSONObject.class );
JSONArray dataArray = new JSONArray();
// 数据源对象
JSONObject dataSource = new JSONObject();
// 数据库IP | 类型:string
dataSource.put( "name", sqlbotDs.getString( "name" ) );
// 数据库种类 | 类型:string
dataSource.put( "type", sqlbotDs.getString( "type" ) );
// 数据库IP | 类型:string
dataSource.put( "host", "127.0.0.1" );
// 数据库开放的端口 | 类型:integer(int32)
dataSource.put( "port", 3306 );
// 数据库用户名 | 类型:string
dataSource.put( "user", "root" );
// 数据库密码 | 类型:string
dataSource.put( "password", "root" );
// 数据库内的库名 | 类型:string
dataSource.put( "dataBase", "saa_data_agent_product" );
// 数据库模式,部分数据库会有 | 类型:string
dataSource.put( "schema", "schema" );
// 针对数据源的描述,可在数据源处查看编辑,详细的描述可以帮助 SQLBot 生成答案 | 类型:string
dataSource.put( "comment", sqlbotDs.getString( "description" ) );
JSONArray sqlbotTables = sqlBotService.post( "/api/v1/datasource/tableList/1", JSONArray.class );
// tables数组
JSONArray tablesArray = new JSONArray();
for ( int i = 0; i < sqlbotTables.size(); i++ ) {
JSONObject sqlbotTable = sqlbotTables.getJSONObject( i );
if ( sqlbotTable.getBoolean( "checked" ) ) {
JSONObject table = new JSONObject();
// 构建数据集的数据表名称 | 类型:string
table.put( "name", sqlbotTable.getString( "table_name" ) );
// 数据集的名字,详细的以及和问题相关的描述也能够帮助 SQLBot 生成答案 | 类型:string
table.put( "comment", sqlbotTable.getString( "custom_comment" ) );
// DataEase 无具体赋值 在 SQLBot 中该该字段会传值给 AiModelQuestion类,帮助 AI 以字段内容规定回答格式 | 类型:string
table.put( "rule", "" );
JSONArray sqlbotFields = sqlBotService.post( "/api/v1/datasource/fieldList/" + sqlbotTable.getString( "id" ),
JSONArray.class, requestBody );
JSONArray fields = new JSONArray();
for ( int j = 0; j < sqlbotFields.size(); j++ ) {
JSONObject sqlbotField = sqlbotFields.getJSONObject( j );
if ( sqlbotField.getBoolean( "checked" ) ) {
JSONObject field = new JSONObject();
// 字段名 | 类型:string
field.put( "name", sqlbotField.getString( "field_name" ) );
// 字段的数据类型 | 类型:string
field.put( "type", sqlbotField.getString( "field_type" ) );
// 字段描述 | 类型:string
field.put( "comment", sqlbotField.getString( "custom_comment" ) );
fields.add( field );
}
}
table.put( "fields", fields );
tablesArray.add( table );
}
}
dataSource.put( "tables", tablesArray );
dataArray.add( dataSource );
return dataArray;
}
}
以下是我个人初步原因分析:
1、sqlbot接口/api/v1/system/assistant/ds调用我的服务接口,而我的服务接口又调用SQLBot的数据源接口,由读超时判断SQLBot的API接口是单线程同步阻塞的,因为/api/v1/system/assistant/ds接口未执行完,导致我的接口服务调用SQLBot的接口就一直卡着
2、此问题是BUG还是因为社区版本的限制?
版本:1.10.0 社区版,通过docker运行
问题描述:
SQLBot小助手高级应用设置中,我在获取高级应用 API 接口 的服务里,回调SQLBot的OpenAPI接口(
/api/v1/datasource/get/{id}/api/v1/datasource/tableList/{id}/api/v1/datasource/fieldList/{id})获取数据源信息并拼接返回结果,会报读超时错误。以下为请求路径图:
以下为界面效果图:
以下为java服务接口代码块
以下是我个人初步原因分析:
1、sqlbot接口
/api/v1/system/assistant/ds调用我的服务接口,而我的服务接口又调用SQLBot的数据源接口,由读超时判断SQLBot的API接口是单线程同步阻塞的,因为/api/v1/system/assistant/ds接口未执行完,导致我的接口服务调用SQLBot的接口就一直卡着2、此问题是BUG还是因为社区版本的限制?