TASK:mixi;

This commit is contained in:
shahaibo
2024-08-01 13:21:09 +08:00
parent ed578f5ace
commit cde9bbbb00
28 changed files with 1216 additions and 107 deletions

View File

@@ -13,6 +13,7 @@ import com.mixi.common.config.exception.BusinessException;
import com.mixi.common.utils.AccessLimitUtils;
import com.mixi.mapper.TProductMapper;
import com.mixi.mapper.entity.TProduct;
import com.mixi.model.dto.AIRecommendDTO;
import com.mixi.model.dto.GenerateCollocationDataBaseDTO;
import com.mixi.model.dto.GenerateCollocationQueryDTO;
import com.mixi.model.dto.GenerateCollocationQueryNewDTO;
@@ -566,4 +567,54 @@ public class PythonService {
}
return productList;
}
public JSONObject getAIRecommend(AIRecommendDTO aiRecommendDTO) {
//限流校验
AccessLimitUtils.validate("similarityMatch", 20);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(300, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(300, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
Map<String, Object> content = Maps.newHashMap();
content.put("input_message", "recommend an outfit");
content.put("user_id", "user123");
content.put("image_urls", "http://localhost:5001/chat");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
Request request = new Request.Builder()
// .url(accessPythonIp + ":9993/api/similar_matchsimilar_match")
.url("http://192.168.1.3:5001/chat")
.method("POST", body)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyStr = null;
try {
log.info("获取python获取相似商品请求入参content###{}", JSON.toJSONString(content));
response = client.newCall(request).execute();
bodyStr = response.body().string();
} catch (IOException ioException) {
log.error("PythonService##similarityMatch异常###{}", ExceptionUtil.getThrowableList(ioException));
}
log.info("识获取python获取相似商品请求结果###{}", bodyStr.trim());
//去除限流
AccessLimitUtils.validateOut("similarityMatch");
if (Objects.isNull(response)) {
log.error("PythonService##similarityMatch异常###{}", "response or body is empty!");
throw new BusinessException("SimilarityMatch exception.");
}
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
Boolean result = jsonObject.getBoolean("successful");
if (result) {
JSONObject parseObject = JSON.parseObject(bodyStr.trim());
return parseObject;
}
log.info("获取python获取相似商品请求异常###{}", jsonObject);
//生成失败
throw new BusinessException("SimilarityMatch exception.");
}
}