Skip to content

Commit db0d60f

Browse files
committed
1.3.0
1 parent 126073a commit db0d60f

File tree

18 files changed

+688
-10
lines changed

18 files changed

+688
-10
lines changed

spring-boot2-examples/examples-dataset/src/test/java/io/github/guoshiqiufeng/dify/examples/dataset/DatasetTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public void test() throws InterruptedException, IOException {
8181
updateDocumentByFile(datasetId, multipartFile, oldDocumentId);
8282

8383

84-
DocumentDeleteResponse documentDeleteResponse = dataset.deleteDocument(datasetId, oldDocumentId);
85-
log.info("doc del:{}", JSON.toJSONString(documentDeleteResponse));
84+
dataset.deleteDocument(datasetId, oldDocumentId);
8685

8786
DocumentIndexingStatusRequest documentIndexingStatusRequest = new DocumentIndexingStatusRequest();
8887
documentIndexingStatusRequest.setDatasetId(datasetId);
@@ -101,8 +100,7 @@ public void test() throws InterruptedException, IOException {
101100

102101
updateSegment(datasetId, documentId, segmentId);
103102

104-
SegmentDeleteResponse segmentDeleteResponse = dataset.deleteSegment(datasetId, documentId, segmentId);
105-
log.info("segment delete:{}", JSON.toJSONString(segmentDeleteResponse));
103+
dataset.deleteSegment(datasetId, documentId, segmentId);
106104

107105
UploadFileInfoResponse uploadFileInfoResponse = dataset.uploadFileInfo(datasetId, documentId);
108106
log.info("upload file:{}", JSON.toJSONString(uploadFileInfoResponse));
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
## chat
2+
3+
### dataset page
4+
GET http://localhost:8080/v1/dataset/page
5+
6+
### dataset create
7+
POST http://localhost:8080/v1/dataset
8+
Content-Type: application/json
9+
10+
{
11+
"name": "api",
12+
"description": "api",
13+
"indexingTechnique": "HIGH_QUALITY",
14+
"permission": "ONLY_ME",
15+
"provider": "vendor",
16+
"externalKnowledgeApiId": "",
17+
"externalKnowledgeId": ""
18+
}
19+
20+
### dataset delete
21+
DELETE http://localhost:8080/v1/dataset/e32be42d-1154-4b61-a119-fd44ec7e801a
22+
23+
24+
### dataset document create text
25+
POST http://localhost:8080/v1/dataset/document/text
26+
Content-Type: application/json
27+
28+
{
29+
"datasetId": "47774718-824d-4dd9-8469-9c3196b0d021",
30+
"name": "api_test",
31+
"text": "api_test",
32+
"docType": "others",
33+
"docMetadata": {},
34+
"indexingTechnique": "high_quality",
35+
"docForm": "hierarchical_model",
36+
"docLanguage": "Chinese",
37+
"processRule": {
38+
"mode": "automatic"
39+
},
40+
"retrievalModel": {
41+
"searchMethod": "hybrid_search",
42+
"rerankingEnable": false,
43+
"rerankingMode": "weighted_score",
44+
"weights": {
45+
"weightType": "customized",
46+
"vectorSetting": {
47+
"vectorWeight": 0.2,
48+
"embeddingModelName": "bge-m3:latest",
49+
"embeddingProviderName": "langgenius/ollama/ollama"
50+
},
51+
"keywordSetting": {
52+
"keywordWeight": 0.8
53+
}
54+
},
55+
"topK": 2,
56+
"scoreThresholdEnabled": false,
57+
"scoreThreshold": 0.5
58+
},
59+
"embeddingModel": "bge-m3:latest",
60+
"embeddingModelProvider": "langgenius/ollama/ollama"
61+
}
62+
63+
### dataset document create file
64+
POST http://localhost:8080/v1/dataset/document/file
65+
Content-Type: multipart/form-data; boundary=BOUNDARY
66+
67+
--BOUNDARY
68+
Content-Disposition: form-data; name="file"; filename="test.txt"
69+
Content-Type: text/plain
70+
71+
< ./test.txt
72+
73+
--BOUNDARY
74+
Content-Disposition: form-data; name="data"
75+
Content-Type: application/json
76+
77+
{
78+
"datasetId": "47774718-824d-4dd9-8469-9c3196b0d021",
79+
"name": "file_api",
80+
"docType": "others",
81+
"docMetadata": {},
82+
"indexingTechnique": "high_quality",
83+
"docForm": "hierarchical_model",
84+
"docLanguage": "Chinese",
85+
"processRule": {
86+
"mode": "automatic"
87+
},
88+
"retrievalModel": {
89+
"searchMethod": "hybrid_search",
90+
"rerankingEnable": false,
91+
"weights": {
92+
"weightType": "customized",
93+
"vectorSetting": {
94+
"vectorWeight": 0.2,
95+
"embeddingModelName": "bge-m3:latest",
96+
"embeddingProviderName": "langgenius/ollama/ollama"
97+
},
98+
"keywordSetting": {
99+
"keywordWeight": 0.8
100+
}
101+
},
102+
"topK": 2,
103+
"scoreThresholdEnabled": false,
104+
"scoreThreshold": 0.5
105+
},
106+
"embeddingModel": "bge-m3:latest",
107+
"embeddingModelProvider": "langgenius/ollama/ollama"
108+
}
109+
--BOUNDARY--
110+
111+
112+
### dataset document update text
113+
PUT http://localhost:8080/v1/dataset/document/text
114+
Content-Type: application/json
115+
116+
{
117+
"datasetId": "47774718-824d-4dd9-8469-9c3196b0d021",
118+
"documentId": "365b07b8-78c6-4489-915a-b1370893447c",
119+
"name": "api_update",
120+
"text": "api_update",
121+
"docType": "others",
122+
"docMetadata": {},
123+
"indexingTechnique": "high_quality",
124+
"docForm": "hierarchical_model",
125+
"docLanguage": "Chinese",
126+
"processRule": {
127+
"mode": "automatic"
128+
}
129+
}
130+
131+
### dataset document update file
132+
PUT http://localhost:8080/v1/dataset/document/file
133+
Content-Type: multipart/form-data; boundary=BOUNDARY
134+
135+
--BOUNDARY
136+
Content-Disposition: form-data; name="file"; filename="test.txt"
137+
Content-Type: text/plain
138+
139+
< ./test.txt
140+
141+
--BOUNDARY
142+
Content-Disposition: form-data; name="data"
143+
Content-Type: application/json
144+
145+
{
146+
"datasetId": "47774718-824d-4dd9-8469-9c3196b0d021",
147+
"documentId": "6880e395-57d9-4f64-8b24-ab4f56f038c3",
148+
"name": "file_api_update",
149+
"docType": "others",
150+
"docMetadata": {},
151+
"indexingTechnique": "high_quality",
152+
"docForm": "hierarchical_model",
153+
"docLanguage": "Chinese",
154+
"processRule": {
155+
"mode": "automatic"
156+
},
157+
"retrievalModel": {
158+
"searchMethod": "hybrid_search",
159+
"rerankingEnable": false,
160+
"weights": {
161+
"weightType": "customized",
162+
"vectorSetting": {
163+
"vectorWeight": 0.5,
164+
"embeddingModelName": "bge-m3:latest",
165+
"embeddingProviderName": "langgenius/ollama/ollama"
166+
},
167+
"keywordSetting": {
168+
"keywordWeight": 0.6
169+
}
170+
},
171+
"topK": 2,
172+
"scoreThresholdEnabled": false,
173+
"scoreThreshold": 0.5
174+
},
175+
"embeddingModel": "bge-m3:latest",
176+
"embeddingModelProvider": "langgenius/ollama/ollama"
177+
}
178+
--BOUNDARY--
179+
180+
### dataset document page
181+
GET http://localhost:8080/v1/dataset/document/page?datasetId=47774718-824d-4dd9-8469-9c3196b0d021
182+
183+
### dataset document delete
184+
DELETE http://localhost:8080/v1/dataset/document/47774718-824d-4dd9-8469-9c3196b0d021/365b07b8-78c6-4489-915a-b1370893447c
185+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>io.github.guoshiqiufeng.dify.examples</groupId>
7+
<artifactId>spring-boot2-examples</artifactId>
8+
<version>0.8.0</version>
9+
</parent>
10+
<groupId>io.github.guoshiqiufeng.dify.examples</groupId>
11+
<artifactId>spring-boot2-examples-date</artifactId>
12+
<name>${project.artifactId}</name>
13+
<description>${project.artifactId}</description>
14+
<packaging>jar</packaging>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>io.github.guoshiqiufeng.dify</groupId>
24+
<artifactId>dify-spring-boot2-starter</artifactId>
25+
</dependency>
26+
27+
<!--不使用dify-server 可以用 redis-->
28+
<!-- <dependency>-->
29+
<!-- <groupId>org.springframework.boot</groupId>-->
30+
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
31+
<!-- </dependency>-->
32+
33+
<dependency>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>com.alibaba.fastjson2</groupId>
40+
<artifactId>fastjson2</artifactId>
41+
<version>2.0.53</version>
42+
</dependency>
43+
</dependencies>
44+
45+
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.github.guoshiqiufeng.dify.examples.date;
2+
3+
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
4+
import io.github.guoshiqiufeng.dify.dataset.DifyDataset;
5+
import io.github.guoshiqiufeng.dify.dataset.dto.request.*;
6+
import io.github.guoshiqiufeng.dify.dataset.dto.response.DatasetResponse;
7+
import io.github.guoshiqiufeng.dify.dataset.dto.response.DocumentCreateResponse;
8+
import io.github.guoshiqiufeng.dify.dataset.dto.response.DocumentIndexingStatusResponse;
9+
import io.github.guoshiqiufeng.dify.dataset.dto.response.DocumentInfo;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.springframework.stereotype.Service;
12+
13+
import javax.annotation.Resource;
14+
15+
/**
16+
* @author yanghq
17+
* @version 1.0
18+
* @since 2025/3/25 13:50
19+
*/
20+
@Slf4j
21+
@Service
22+
public class DifyDatasetService {
23+
24+
@Resource
25+
private DifyDataset difyDataset;
26+
27+
public DifyPageResult<DatasetResponse> page(DatasetPageRequest datasetPageRequest) {
28+
return difyDataset.page(datasetPageRequest);
29+
}
30+
31+
public DatasetResponse create(DatasetCreateRequest datasetCreateRequest) {
32+
return difyDataset.create(datasetCreateRequest);
33+
}
34+
35+
public void delete(String id) {
36+
difyDataset.delete(id);
37+
}
38+
39+
/************ document ************/
40+
public DocumentCreateResponse createDocumentByText(DocumentCreateByTextRequest documentCreateByTextRequest) {
41+
return difyDataset.createDocumentByText(documentCreateByTextRequest);
42+
}
43+
44+
public DocumentCreateResponse createDocumentByFile(DocumentCreateByFileRequest documentCreateByFileRequest) {
45+
return difyDataset.createDocumentByFile(documentCreateByFileRequest);
46+
}
47+
48+
public DocumentCreateResponse updateDocumentByText(DocumentUpdateByTextRequest documentUpdateByTextRequest) {
49+
return difyDataset.updateDocumentByText(documentUpdateByTextRequest);
50+
}
51+
52+
public DocumentCreateResponse updateDocumentByFile(DocumentUpdateByFileRequest documentCreateByFileRequest) {
53+
return difyDataset.updateDocumentByFile(documentCreateByFileRequest);
54+
}
55+
56+
public DifyPageResult<DocumentInfo> pageDocument(DatasetPageDocumentRequest datasetPageDocumentRequest) {
57+
return difyDataset.pageDocument(datasetPageDocumentRequest);
58+
}
59+
60+
public DocumentIndexingStatusResponse indexingStatus(DocumentIndexingStatusRequest documentIndexingStatusRequest) {
61+
return difyDataset.indexingStatus(documentIndexingStatusRequest);
62+
}
63+
64+
public void deleteDocument(String datasetId, String documentId) {
65+
difyDataset.deleteDocument(datasetId, documentId);
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.guoshiqiufeng.dify.examples.date;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* @author yanghq
8+
* @version 1.0
9+
* @since 2025/7/23 15:02
10+
*/
11+
@SpringBootApplication
12+
public class ExamplesDateApplication {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(ExamplesDateApplication.class, args);
16+
}
17+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.github.guoshiqiufeng.dify.examples.date;
2+
3+
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
4+
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
5+
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
6+
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
7+
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
8+
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
9+
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
10+
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.core.Ordered;
13+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
14+
15+
import java.math.BigInteger;
16+
import java.time.format.DateTimeFormatter;
17+
18+
@Configuration
19+
public class JacksonConfiguration implements Jackson2ObjectMapperBuilderCustomizer, Ordered {
20+
@Override
21+
public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
22+
jacksonObjectMapperBuilder
23+
.timeZone("Asia/Shanghai")
24+
.serializers(
25+
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATE)),
26+
new LocalDateSerializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATE)),
27+
new LocalTimeSerializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATETIME))
28+
)
29+
.deserializers(
30+
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATE)),
31+
new LocalDateDeserializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATE)),
32+
new LocalTimeDeserializer(DateTimeFormatter.ofPattern(PlatformJacksonConstant.PATTERN_DATETIME))
33+
)
34+
//Long 在前台超过 18 位 丢失精度 修改为只针对id
35+
.serializerByType(Long.TYPE, ToStringSerializer.instance)
36+
.serializerByType(Long.class, ToStringSerializer.instance)
37+
.serializerByType(BigInteger.class, ToStringSerializer.instance);
38+
}
39+
40+
@Override
41+
public int getOrder() {
42+
return 1;
43+
}
44+
}

0 commit comments

Comments
 (0)