Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15 from LucienShui/chore/add_log_and_revision
Browse files Browse the repository at this point in the history
Add logs and release the version
  • Loading branch information
LucienShui authored Jun 4, 2020
2 parents 0169ffb + 1ab87d7 commit 157c903
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version>1.0.3-SNAPSHOT</version>
</parent>
<artifactId>pasteme-algorithm</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.4</version>
<name>PasteMe Algorithm</name>
<description>PasteMe Algorithm Collection</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -18,6 +19,7 @@
* @version 1.0.0
*/
@Slf4j
@Component
public class HttpClientImpl implements cn.pasteme.algorithm.http.HttpClient {

private final HttpClient httpClient;
Expand Down Expand Up @@ -50,6 +52,7 @@ public JSONObject post(String url, String json) throws IOException {
HttpResponse response = httpClient.execute(request);
InputStream inputStream = response.getEntity().getContent();
String stringResponse = inputStreamToString(inputStream);
log.info("Get response = {} from {}", stringResponse, url);
return JSONObject.parseObject(stringResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.pasteme.algorithm.model.TextRiskClassification;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -30,11 +31,12 @@ public class TextRiskClassificationImpl implements TextRiskClassification {
private final String url;

public TextRiskClassificationImpl(
@Autowired HttpClient httpClient,
@Value("${pasteme.algorithm.model.TextRiskClassificationImpl.host}") String host,
@Value("${pasteme.algorithm.model.TextRiskClassificationImpl.modelName}") String modelName) {
this.host = host;
this.modelName = modelName;
this.httpClient = new HttpClientImpl();
this.httpClient = httpClient;
this.url = String.format("http://%s/v1/models/%s:predict", this.host, this.modelName);
}

Expand All @@ -43,6 +45,7 @@ public int inference(String content) throws IOException {
JSONObject jsonRequest = new JSONObject();
jsonRequest.put("content", content);
JSONObject jsonResponse = httpClient.post(this.url, jsonRequest);
log.info("TextRiskClassification get jsonResponse = {} from httpClient", jsonResponse);
List<Integer> resultList = jsonResponse.getJSONArray("predictions").toJavaList(Integer.class);
assert resultList.size() == 1;
return resultList.get(0);
Expand Down

0 comments on commit 157c903

Please sign in to comment.