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

Commit e0c289f

Browse files
authored
Merge pull request #16 from LucienShui/fix/http_client_charset
Fix charset in httpClient, rename inference's param name
2 parents 157c903 + b138b66 commit e0c289f

7 files changed

Lines changed: 43 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ buildNumber.properties
2424

2525
# application.yml
2626
src/main/resources/application.yml
27+
src/test/resources/application.yml

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<version>1.0.3-SNAPSHOT</version>
1111
</parent>
1212
<artifactId>pasteme-algorithm</artifactId>
13-
<version>1.0.4</version>
13+
<version>1.0.5</version>
1414
<name>PasteMe Algorithm</name>
1515
<description>PasteMe Algorithm Collection</description>
1616

src/main/java/cn/pasteme/algorithm/http/impl/HttpClientImpl.java renamed to src/main/java/cn/pasteme/algorithm/http/HttpClientImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.pasteme.algorithm.http.impl;
1+
package cn.pasteme.algorithm.http;
22

33
import com.alibaba.fastjson.JSONObject;
44
import lombok.extern.slf4j.Slf4j;
@@ -46,7 +46,7 @@ public JSONObject post(String url, JSONObject json) throws IOException {
4646
@Override
4747
public JSONObject post(String url, String json) throws IOException {
4848
HttpPost request = new HttpPost(url);
49-
StringEntity params = new StringEntity(json);
49+
StringEntity params = new StringEntity(json, "UTF-8");
5050
request.addHeader("Content-Type", "application/json");
5151
request.setEntity(params);
5252
HttpResponse response = httpClient.execute(request);

src/main/java/cn/pasteme/algorithm/model/TextRiskClassification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public interface TextRiskClassification {
1313
/**
1414
* 调用模型
1515
*
16-
* @param jsonString 模型参数
16+
* @param content 文本内容
1717
* @return 模型的推理结果,0 代表 Normal,1 代表 Risk
1818
* @throws IOException HTTP 请求出错
1919
*/
20-
int inference(String jsonString) throws IOException;
20+
int inference(String content) throws IOException;
2121
}

src/main/java/cn/pasteme/algorithm/model/impl/TextRiskClassificationImpl.java renamed to src/main/java/cn/pasteme/algorithm/model/TextRiskClassificationImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package cn.pasteme.algorithm.model.impl;
1+
package cn.pasteme.algorithm.model;
22

33
import cn.pasteme.algorithm.http.HttpClient;
4-
import cn.pasteme.algorithm.http.impl.HttpClientImpl;
5-
import cn.pasteme.algorithm.model.TextRiskClassification;
64
import com.alibaba.fastjson.JSONObject;
75
import lombok.extern.slf4j.Slf4j;
86
import org.springframework.beans.factory.annotation.Autowired;

src/test/java/cn/pasteme/algorithm/http/impl/HttpClientImplTest.java renamed to src/test/java/cn/pasteme/algorithm/http/HttpClientImplTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package cn.pasteme.algorithm.http.impl;
1+
package cn.pasteme.algorithm.http;
22

33
import cn.pasteme.algorithm.http.HttpClient;
44
import com.alibaba.fastjson.JSONObject;
55
import lombok.extern.slf4j.Slf4j;
6+
import org.junit.Ignore;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
9+
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.test.context.SpringBootTest;
911
import org.springframework.test.context.junit4.SpringRunner;
1012

@@ -13,9 +15,12 @@
1315
@RunWith(SpringRunner.class)
1416
public class HttpClientImplTest {
1517

18+
@Autowired
19+
private HttpClient httpClient;
20+
1621
@Test
22+
@Ignore
1723
public void testPost() {
18-
HttpClient httpClient = new HttpClientImpl();
1924
try {
2025
JSONObject jsonResponse = httpClient.post(
2126
"http://predict.pasteme.lucien.ink/v1/models/PasteMeRIM:predict",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cn.pasteme.algorithm.model;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.Ignore;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
11+
@Slf4j
12+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
13+
@RunWith(SpringRunner.class)
14+
public class TextRiskClassificationImplTest {
15+
16+
@Autowired
17+
private TextRiskClassification textRiskClassification;
18+
19+
@Test
20+
@Ignore
21+
public void inference() {
22+
String content = "你好,世界!";
23+
try {
24+
int result = textRiskClassification.inference(content);
25+
} catch (Exception e) {
26+
e.printStackTrace();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)