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

Commit

Permalink
Merge pull request #16 from LucienShui/fix/http_client_charset
Browse files Browse the repository at this point in the history
Fix charset in httpClient, rename inference's param name
  • Loading branch information
LucienShui authored Jun 4, 2020
2 parents 157c903 + b138b66 commit e0c289f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ buildNumber.properties

# application.yml
src/main/resources/application.yml
src/test/resources/application.yml
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</version>
<version>1.0.5</version>
<name>PasteMe Algorithm</name>
<description>PasteMe Algorithm Collection</description>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.pasteme.algorithm.http.impl;
package cn.pasteme.algorithm.http;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -46,7 +46,7 @@ public JSONObject post(String url, JSONObject json) throws IOException {
@Override
public JSONObject post(String url, String json) throws IOException {
HttpPost request = new HttpPost(url);
StringEntity params = new StringEntity(json);
StringEntity params = new StringEntity(json, "UTF-8");
request.addHeader("Content-Type", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public interface TextRiskClassification {
/**
* 调用模型
*
* @param jsonString 模型参数
* @param content 文本内容
* @return 模型的推理结果,0 代表 Normal,1 代表 Risk
* @throws IOException HTTP 请求出错
*/
int inference(String jsonString) throws IOException;
int inference(String content) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cn.pasteme.algorithm.model.impl;
package cn.pasteme.algorithm.model;

import cn.pasteme.algorithm.http.HttpClient;
import cn.pasteme.algorithm.http.impl.HttpClientImpl;
import cn.pasteme.algorithm.model.TextRiskClassification;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cn.pasteme.algorithm.http.impl;
package cn.pasteme.algorithm.http;

import cn.pasteme.algorithm.http.HttpClient;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

Expand All @@ -13,9 +15,12 @@
@RunWith(SpringRunner.class)
public class HttpClientImplTest {

@Autowired
private HttpClient httpClient;

@Test
@Ignore
public void testPost() {
HttpClient httpClient = new HttpClientImpl();
try {
JSONObject jsonResponse = httpClient.post(
"http://predict.pasteme.lucien.ink/v1/models/PasteMeRIM:predict",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.pasteme.algorithm.model;

import lombok.extern.slf4j.Slf4j;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@RunWith(SpringRunner.class)
public class TextRiskClassificationImplTest {

@Autowired
private TextRiskClassification textRiskClassification;

@Test
@Ignore
public void inference() {
String content = "你好,世界!";
try {
int result = textRiskClassification.inference(content);
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit e0c289f

Please sign in to comment.