Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
杨图强
ewaytek-deepseek
Commits
0487b6d5
Commit
0487b6d5
authored
Aug 28, 2025
by
何处是我家
Browse files
提交
parents
Changes
148
Hide whitespace changes
Inline
Side-by-side
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/config/WebConfig.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
/**
* @author yangtq
* @date 2025/2/26
*/
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/static/**"
)
.
addResourceLocations
(
"classpath:/static/"
);
}
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
// 允许所有路径的跨域请求
.
allowedOriginPatterns
(
"*"
)
// 使用 allowedOriginPatterns 替代 allowedOrigins
.
allowCredentials
(
true
)
// 允许发送 Cookie
.
allowedMethods
(
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
,
"OPTIONS"
)
// 允许的 HTTP 方法
.
allowedHeaders
(
"*"
)
// 允许的 HTTP 头部
.
maxAge
(
3600
);
// 预检请求的缓存时间(秒)
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/controller/AiChatController.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.controller
;
import
com.ewaytek.deepseek.common.bean.base.ApiResponse
;
import
com.ewaytek.deepseek.common.utils.StringUtils
;
import
com.ewaytek.deepseek.doadmin.dto.MessageDTO
;
import
com.ewaytek.deepseek.doadmin.dto.dify.DifyChatDTO
;
import
com.ewaytek.deepseek.doadmin.vo.MessageVO
;
import
com.ewaytek.deepseek.doadmin.vo.dify.DifyChatVO
;
import
com.ewaytek.deepseek.service.AiChatService
;
import
com.ewaytek.deepseek.service.dify.DifyChatService
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
;
import
reactor.core.publisher.Flux
;
import
reactor.core.scheduler.Schedulers
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.Valid
;
import
java.util.List
;
import
java.util.Map
;
@RestController
public
class
AiChatController
{
@Autowired
private
AiChatService
aiChatService
;
//流式模式
private
final
static
String
STREAMING_MODE
=
"streaming"
;
//阻塞模式
private
final
static
String
BLOCKING_MODE
=
"blocking"
;
@PostMapping
(
value
=
"/system/chat"
,
produces
=
"application/stream+json"
)
public
Flux
<
String
>
systemChat
(
@RequestBody
List
<
Map
<
String
,
String
>>
messages
)
{
Flux
<
String
>
responseFlux
=
aiChatService
.
chat
(
messages
);
return
Flux
.
create
(
sink
->
{
responseFlux
.
subscribeOn
(
Schedulers
.
boundedElastic
())
.
subscribe
(
sink:
:
next
,
// 返回流式字符串
sink:
:
error
,
// 返回错误,请在调用端完成错误处理
sink:
:
complete
// 返回完成事件
);
});
}
@PostMapping
(
value
=
"/chat"
)
public
ApiResponse
<
MessageVO
>
chat
(
@RequestBody
List
<
MessageDTO
>
messages
)
{
return
aiChatService
.
msgChat
(
messages
);
}
private
DifyChatVO
difyPojo
(
DifyChatDTO
dto
)
{
DifyChatVO
difyChatVO
=
new
DifyChatVO
();
difyChatVO
.
setResponseMode
(
STREAMING_MODE
);
difyChatVO
.
setQuery
(
dto
.
getQuery
());
difyChatVO
.
setUser
(
dto
.
getUserId
().
toString
());
if
(
StringUtils
.
isNotEmpty
(
dto
.
getConversationId
()))
{
difyChatVO
.
setConversationId
(
dto
.
getConversationId
());
}
return
difyChatVO
;
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/controller/DifyAudioChatController.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.controller
;
import
com.ewaytek.deepseek.common.config.DeepseekConfig
;
import
com.ewaytek.deepseek.service.dify.DifyAudioChatService
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
;
import
org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
* @author yangtq
* @date 2025/3/28
*/
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping
(
"/dify/audio"
)
public
class
DifyAudioChatController
{
@Resource
private
DifyAudioChatService
difyAudioChatService
;
@PostMapping
(
"/voice1"
)
public
StreamingResponseBody
systemChatAudio
(
@RequestParam
(
value
=
"audio"
,
required
=
false
)
MultipartFile
audio
,
@RequestParam
(
required
=
false
,
value
=
"context"
)
String
context
,
HttpServletResponse
response
)
{
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
// 设置响应类型为二进制流
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"Connection"
,
"keep-alive"
);
return
outputStream
->
{
try
{
if
(
audio
!=
null
)
{
difyAudioChatService
.
systemChatAudio
(
audio
.
getInputStream
(),
null
,
outputStream
);
}
else
if
(
context
!=
null
)
{
difyAudioChatService
.
systemChatAudio
(
null
,
context
,
outputStream
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
};
}
@PostMapping
(
"/voice"
)
@ResponseBody
public
ResponseBodyEmitter
systemChatAudioFlie
(
@RequestParam
(
value
=
"audio"
,
required
=
false
)
MultipartFile
audio
,
@RequestParam
(
required
=
false
,
value
=
"context"
)
String
context
,
HttpServletResponse
response
)
{
response
.
setContentType
(
MediaType
.
TEXT_EVENT_STREAM_VALUE
);
// 设置响应类型为二进制流
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"Connection"
,
"keep-alive"
);
ResponseBodyEmitter
emitter
=
new
ResponseBodyEmitter
(
0L
);
try
{
if
(
audio
!=
null
)
{
difyAudioChatService
.
systemChatAudioFlie
(
audio
.
getInputStream
(),
null
,
emitter
);
}
else
if
(
context
!=
null
)
{
difyAudioChatService
.
systemChatAudioFlie
(
null
,
context
,
emitter
);
}
}
catch
(
Exception
e
)
{
emitter
.
completeWithError
(
e
);
}
finally
{
emitter
.
complete
();
}
return
emitter
;
}
@GetMapping
(
"/{fileName}"
)
public
ResponseEntity
<
FileSystemResource
>
getAudioFile
(
@PathVariable
String
fileName
)
{
// 构建文件路径
String
filePath
=
DeepseekConfig
.
getDownloadPath
()
+
fileName
;
// 检查文件是否存在
File
file
=
new
File
(
filePath
);
if
(!
file
.
exists
())
{
return
ResponseEntity
.
notFound
().
build
();
}
// 返回文件作为流
return
ResponseEntity
.
ok
()
.
contentType
(
MediaType
.
parseMediaType
(
"audio/wav"
))
.
body
(
new
FileSystemResource
(
file
));
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/controller/DifyController.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.controller
;
import
com.ewaytek.deepseek.common.bean.base.ApiResponse
;
import
com.ewaytek.deepseek.common.utils.StringUtils
;
import
com.ewaytek.deepseek.common.utils.poi.ExcelUtil
;
import
com.ewaytek.deepseek.doadmin.dto.dify.DIfyImportVerifyDTO
;
import
com.ewaytek.deepseek.doadmin.dto.dify.DifyChatBlockIngDTO
;
import
com.ewaytek.deepseek.doadmin.dto.dify.DifyChatDTO
;
import
com.ewaytek.deepseek.doadmin.dto.doubao.DoubaoChatDTO
;
import
com.ewaytek.deepseek.doadmin.vo.dify.ConversationsVO
;
import
com.ewaytek.deepseek.doadmin.vo.dify.DifyChatVO
;
import
com.ewaytek.deepseek.service.dify.DifyChatService
;
import
com.ewaytek.deepseek.service.doubao.DoubaoService
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.http.MediaType
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
;
import
reactor.core.publisher.Flux
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.Valid
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutionException
;
import
java.util.stream.Collectors
;
/**
* @author yangtq
* @date 2025/2/25
*/
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping
(
"/dify"
)
public
class
DifyController
{
//流式模式
private
final
static
String
STREAMING_MODE
=
"streaming"
;
//阻塞模式
private
final
static
String
BLOCKING_MODE
=
"blocking"
;
@Resource
private
DifyChatService
difyChatService
;
@Resource
private
DoubaoService
doubaoService
;
/**
* diff 流
*
* @param ResponseBodyEmitter
* @return
*/
@PostMapping
(
value
=
"/stream/chat"
)
@ResponseBody
public
ResponseBodyEmitter
systemChat
(
@RequestBody
@Valid
DifyChatDTO
dto
,
HttpServletResponse
response
)
{
response
.
setContentType
(
MediaType
.
TEXT_EVENT_STREAM_VALUE
);
// 设置响应类型为 Server-Sent Events
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"Connection"
,
"keep-alive"
);
DifyChatVO
difyChatVO
=
new
DifyChatVO
();
difyChatVO
.
setResponseMode
(
STREAMING_MODE
);
difyChatVO
.
setQuery
(
dto
.
getQuery
());
difyChatVO
.
setUser
(
dto
.
getUserId
().
toString
());
if
(
StringUtils
.
isNotEmpty
(
dto
.
getConversationId
()))
{
difyChatVO
.
setConversationId
(
dto
.
getConversationId
());
}
return
difyChatService
.
sseChatPrompt
(
difyChatVO
);
}
/**
* 获取会话id
*
* @param dto
* @param response
* @return
*/
@GetMapping
(
value
=
"/id"
)
@ResponseBody
public
ApiResponse
<
List
<
ConversationsVO
.
ConversationInfoVO
>>
conversations
(
@RequestParam
(
required
=
false
)
Integer
limit
,
@RequestParam
(
required
=
false
)
Boolean
pinned
)
{
ApiResponse
<
List
<
ConversationsVO
.
ConversationInfoVO
>>
listApiResponse
=
difyChatService
.
conversations
(
limit
,
pinned
);
return
listApiResponse
;
}
/**
* 导入
* @param file
* @return
*/
@PostMapping
(
"/importVerify2"
)
public
void
importVerify2
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
value
=
"file"
)
MultipartFile
file
)
throws
IOException
,
InterruptedException
{
difyChatService
.
importVerify2
(
request
,
response
,
file
);
}
@PostMapping
(
"/processBatch"
)
public
ApiResponse
<
DIfyImportVerifyDTO
>
processBatch
(
@RequestBody
DIfyImportVerifyDTO
dto
)
throws
JsonProcessingException
{
DIfyImportVerifyDTO
dIfyImportVerifyDTO
=
difyChatService
.
processBatch
(
dto
);
return
ApiResponse
.
success
(
dIfyImportVerifyDTO
);
}
/**
* 导入
* @param file
* @return
*/
@PostMapping
(
"/importVerify"
)
public
ApiResponse
importVerify
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
value
=
"file"
)
MultipartFile
file
)
throws
IOException
,
InterruptedException
,
ExecutionException
{
return
difyChatService
.
importVerify
(
file
);
}
/**
* 导入
* @param file
* @return
*/
@PostMapping
(
value
=
"/doubao"
)
@ResponseBody
public
ResponseBodyEmitter
systemCha1t
(
@RequestBody
DoubaoChatDTO
doubaoChatDTO
,
HttpServletResponse
response
,
HttpServletRequest
request
)
throws
IOException
{
log
.
info
(
"参数名getModel:{},参数值:{}"
,
doubaoChatDTO
.
getModel
(),
doubaoChatDTO
.
getModel
());
log
.
info
(
"参数名getModel:{},参数值:{}"
,
doubaoChatDTO
.
getTemperature
(),
doubaoChatDTO
.
getTemperature
());
log
.
info
(
"参数名getModel:{},参数值:{}"
,
doubaoChatDTO
.
getMessages
(),
doubaoChatDTO
.
getMessages
());
log
.
info
(
"参数名getModel:{},参数值:{}"
,
doubaoChatDTO
.
getTop_p
(),
doubaoChatDTO
.
getTop_p
());
response
.
setContentType
(
MediaType
.
TEXT_EVENT_STREAM_VALUE
);
// 设置响应类型为 Server-Sent Events
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"Connection"
,
"keep-alive"
);
return
doubaoService
.
sseChatPrompt
(
doubaoChatDTO
);
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/controller/DifyDemoController.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.controller
;
import
cn.hutool.http.ContentType
;
import
com.alibaba.fastjson2.JSON
;
import
com.ewaytek.deepseek.common.bean.base.ApiResponse
;
import
com.ewaytek.deepseek.config.DifyConfig
;
import
com.ewaytek.deepseek.doadmin.dto.dify.DIfyImportVerifyDTO
;
import
com.ewaytek.deepseek.doadmin.dto.dify.demo.DIfyWorkflowsResultDTO
;
import
com.ewaytek.deepseek.doadmin.dto.dify.demo.DifyWorkflowsDTO
;
import
com.ewaytek.deepseek.task.DifyThread
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.*
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.ExecutionException
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @author yangtq
* @date 2025/3/6
*/
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping
(
"/dify/demo"
)
public
class
DifyDemoController
{
@Resource
private
OkHttpClient
httpClient
;
@PostMapping
(
value
=
"/stream"
)
@org
.
springframework
.
web
.
bind
.
annotation
.
ResponseBody
public
ApiResponse
<
List
<
String
>>
demo
(
@org
.
springframework
.
web
.
bind
.
annotation
.
RequestBody
DIfyImportVerifyDTO
dto
)
throws
ExecutionException
,
InterruptedException
,
JsonProcessingException
{
DifyConfig
difyConfig
=
new
DifyConfig
();
difyConfig
.
setApiHost
(
"http://192.168.103.69:9002/v1/"
);
difyConfig
.
setApiKey
(
"app-9D2IddTOvZDeBGLm1iNtQ0EF"
);
// 创建 CompletableFuture 来接收结果
CompletableFuture
<
DIfyImportVerifyDTO
>
future
=
new
CompletableFuture
<>();
// 创建 DifyThread 实例,并传入回调接口
DifyThread
task
=
new
DifyThread
(
dto
,
difyConfig
,
httpClient
,
future:
:
complete
);
// 启动线程
Thread
thread
=
new
Thread
(
task
);
thread
.
start
();
// 等待线程完成并获取结果
DIfyImportVerifyDTO
result
=
future
.
get
();
String
answer
=
cleanContent
(
result
.
getAnswer
())
;
return
ApiResponse
.
success
(
DifyWorkflows
(
answer
,
difyConfig
));
}
@PostMapping
(
value
=
"/workflows"
)
@org
.
springframework
.
web
.
bind
.
annotation
.
ResponseBody
public
ApiResponse
<
List
<
String
>>
demo2
(
@org
.
springframework
.
web
.
bind
.
annotation
.
RequestBody
DIfyImportVerifyDTO
dto
)
throws
ExecutionException
,
InterruptedException
,
JsonProcessingException
{
DifyConfig
difyConfig
=
new
DifyConfig
();
difyConfig
.
setApiHost
(
"http://192.168.103.69:9002/v1/"
);
difyConfig
.
setApiKey
(
"app-9D2IddTOvZDeBGLm1iNtQ0EF"
);
return
ApiResponse
.
success
(
DifyWorkflows
(
dto
.
getQuestion
(),
difyConfig
));
}
public
List
<
String
>
DifyWorkflows
(
String
answer
,
DifyConfig
difyConfig
)
throws
JsonProcessingException
{
DifyWorkflowsDTO
difyWorkflowsDTO
=
new
DifyWorkflowsDTO
();
difyWorkflowsDTO
.
setUser
(
"abc-123"
);
difyWorkflowsDTO
.
setResponseMode
(
"streaming"
);
Map
<
String
,
String
>
inputs
=
new
HashMap
<>();
inputs
.
put
(
"question"
,
answer
);
difyWorkflowsDTO
.
setInputs
(
inputs
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
requestBody
=
mapper
.
writeValueAsString
(
difyWorkflowsDTO
);
Headers
headers
=
new
Headers
.
Builder
().
add
(
"Authorization"
,
"Bearer "
+
"app-9RuAoErdMXkG4jVN0YNjXekp"
).
add
(
"Content-Type"
,
"application/json"
).
build
();
Request
request
=
new
Request
.
Builder
().
url
(
difyConfig
.
getApiHost
()
+
"workflows/run"
).
post
(
okhttp3
.
RequestBody
.
create
(
MediaType
.
parse
(
ContentType
.
JSON
.
getValue
()),
requestBody
))
.
headers
(
headers
).
build
();
List
<
String
>
retrieverResourcesList
=
new
ArrayList
<>();
try
(
Response
response
=
httpClient
.
newCall
(
request
).
execute
())
{
if
(!
response
.
isSuccessful
())
{
return
retrieverResourcesList
;
}
// 处理流式响应
ResponseBody
responseBody
=
response
.
body
();
if
(
responseBody
!=
null
)
{
while
(!
responseBody
.
source
().
exhausted
())
{
String
line
=
responseBody
.
source
().
readUtf8Line
();
if
(
line
!=
null
&&
!
line
.
isEmpty
())
{
if
(
line
.
startsWith
(
"data:"
))
{
// 处理 SSE 格式
log
.
info
(
"DifyWorkflows##"
+
line
);
String
eventData
=
line
.
substring
(
5
).
trim
();
// 去掉 "data:" 前缀
DIfyWorkflowsResultDTO
blockingVO
=
JSON
.
parseObject
(
eventData
,
DIfyWorkflowsResultDTO
.
class
);
if
(!
"workflow_finished"
.
equals
(
blockingVO
.
getEvent
())){
continue
;
}
DIfyWorkflowsResultDTO
.
Outputs
metadataVO
=
blockingVO
.
getData
().
getOutputs
();
if
(
metadataVO
!=
null
)
{
if
(!
CollectionUtils
.
isEmpty
(
metadataVO
.
getResult
()))
{
for
(
DIfyWorkflowsResultDTO
.
ResultItem
resultItem
:
metadataVO
.
getResult
())
{
retrieverResourcesList
.
add
(
resultItem
.
getContent
());
}
}
}
}
}
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
());
}
return
retrieverResourcesList
;
}
public
static
String
cleanContent
(
String
content
)
{
// 移除 <details> 标签及其内容
Pattern
detailsPattern
=
Pattern
.
compile
(
"<details.*?</details>"
,
Pattern
.
DOTALL
);
Matcher
detailsMatcher
=
detailsPattern
.
matcher
(
content
);
content
=
detailsMatcher
.
replaceAll
(
""
).
trim
();
// 移除尾部的 null
Pattern
nullPattern
=
Pattern
.
compile
(
"null$"
,
Pattern
.
DOTALL
);
Matcher
nullMatcher
=
nullPattern
.
matcher
(
content
);
content
=
nullMatcher
.
replaceAll
(
""
).
trim
();
// 移除多余的换行符和空格
Pattern
whitespacePattern
=
Pattern
.
compile
(
"\\s+\\n"
,
Pattern
.
DOTALL
);
Matcher
whitespaceMatcher
=
whitespacePattern
.
matcher
(
content
);
content
=
whitespaceMatcher
.
replaceAll
(
"\n"
).
trim
();
return
content
;
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/controller/DifyWorkflowsController.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.controller
;
import
com.ewaytek.deepseek.common.bean.base.ApiResponse
;
import
com.ewaytek.deepseek.service.dify.workflows.DifyWorkflowsService
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.concurrent.ExecutionException
;
/**
* @author yangtq
* @date 2025/3/6
*/
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping
(
"/dify/workflows"
)
public
class
DifyWorkflowsController
{
@Resource
private
DifyWorkflowsService
difyWorkflowsService
;
/**
* 导入
* @param file
* @return
*/
@PostMapping
(
"/importVerify"
)
public
ApiResponse
importVerify
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
value
=
"file"
)
MultipartFile
file
)
throws
IOException
,
InterruptedException
,
ExecutionException
{
return
difyWorkflowsService
.
importVerify
(
file
);
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/AiMessageDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
public
abstract
class
AiMessageDTO
{
public
abstract
String
getMessage
(
String
Message
)
throws
JsonProcessingException
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/DefaultAiMessageDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.List
;
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
public
class
DefaultAiMessageDTO
extends
AiMessageDTO
{
private
String
id
;
private
List
<
Choice
>
choices
;
private
long
created
;
private
String
model
;
private
String
system_fingerprint
;
private
String
object
;
private
Usage
usage
;
@Override
public
String
getMessage
(
String
Message
)
throws
JsonProcessingException
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
DefaultAiMessageDTO
aiMessageDto
=
objectMapper
.
readValue
(
Message
,
DefaultAiMessageDTO
.
class
);
return
aiMessageDto
.
getChoices
().
get
(
0
).
getMessage
().
getContent
();
}
@Data
public
static
class
Choice
{
private
String
finish_reason
;
private
int
index
;
private
Message
message
;
private
Logprobs
logprobs
;
}
@Data
public
static
class
Message
{
private
String
content
;
private
List
<
ToolCall
>
tool_calls
;
private
String
role
;
}
@Data
public
static
class
ToolCall
{
private
String
id
;
private
String
type
;
private
Function
function
;
}
@Data
public
static
class
Function
{
private
String
name
;
private
String
arguments
;
}
@Data
public
static
class
Logprobs
{
private
List
<
ContentLogprob
>
content
;
}
@Data
public
static
class
ContentLogprob
{
private
String
token
;
private
double
logprob
;
private
List
<
Integer
>
bytes
;
private
List
<
TopLogprob
>
top_logprobs
;
}
@Data
public
static
class
TopLogprob
{
private
String
token
;
private
double
logprob
;
private
List
<
Integer
>
bytes
;
}
@Data
public
static
class
Usage
{
private
int
completion_tokens
;
private
int
prompt_tokens
;
private
int
prompt_cache_hit_tokens
;
private
int
prompt_cache_miss_tokens
;
private
int
total_tokens
;
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/MessageChatDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author yangtq
* @date 2025/2/21
*/
@Data
public
class
MessageChatDTO
{
private
String
model
;
private
List
<
MessageDTO
>
messages
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/MessageDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto
;
import
lombok.Data
;
/**
* @author yangtq
* @date 2025/2/21
*/
@Data
public
class
MessageDTO
{
public
String
role
;
public
String
content
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/StreamingAiMessageDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.List
;
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@Slf4j
public
class
StreamingAiMessageDTO
extends
AiMessageDTO
{
private
String
id
;
private
List
<
Choice
>
choices
;
private
Long
created
;
private
String
model
;
private
String
system_fingerprint
;
private
String
object
;
private
Usage
usage
;
@Override
public
String
getMessage
(
String
Message
)
throws
JsonProcessingException
{
log
.
info
(
"StreamingAiMessageDTO"
+
Message
);
if
(
Message
.
startsWith
(
"data:"
))
{
Message
=
Message
.
substring
(
"data:"
.
length
());
}
Message
=
Message
.
trim
();
if
(
Message
.
equals
(
"[DONE]"
))
return
""
;
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
StreamingAiMessageDTO
aiMessageDto
=
objectMapper
.
readValue
(
Message
,
StreamingAiMessageDTO
.
class
);
return
aiMessageDto
.
getChoices
().
get
(
0
).
getDelta
().
getContent
();
}
// {"event": "message", "conversation_id": "eef9803c-ae28-4835-9550-3a0841dbc3de", "message_id": "20ffaba9-6337-4123-a645-b8d92f2e1044", "created_at": 1742193362, "task_id": "5e041c60-27fd-4212-b34c-990eec7a3e98", "id": "20ffaba9-6337-4123-a645-b8d92f2e1044", "answer": "\u53ea\u80fd", "from_variable_selector": null}
@Data
public
static
class
Choice
{
private
Integer
index
;
private
Delta
delta
;
private
String
finish_reason
;
private
Object
logprobs
;
}
@Data
public
static
class
Delta
{
private
String
content
;
private
String
role
;
}
@Data
public
static
class
Usage
{
private
Integer
prompt_tokens
;
private
Integer
completion_tokens
;
private
Integer
total_tokens
;
private
Integer
prompt_cache_hit_tokens
;
private
Integer
prompt_cache_miss_tokens
;
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/DIfyImportVerifyDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify
;
import
com.ewaytek.deepseek.common.annotation.Excel
;
import
com.ewaytek.deepseek.doadmin.vo.dify.RetrieverResources
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author yangtq
* @date 2025/2/26
*/
@Data
public
class
DIfyImportVerifyDTO
{
/**
* 相似问题
*/
@Excel
(
name
=
"问题"
)
private
String
question
;
/**
* 相似问题回复
*/
@Excel
(
name
=
"问题回复"
)
private
String
answer
;
@Excel
(
name
=
"标准答案"
)
private
String
standard
;
@Excel
(
name
=
"引用"
)
private
List
<
RetrieverResources
>
retrieverResources
;
private
String
time
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/DifyChatBlockIngDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify
;
import
com.ewaytek.deepseek.doadmin.vo.dify.DifyChatVO
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author yangtq
* @date 2025/2/26
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
DifyChatBlockIngDTO
{
/**
* 输入提问内容
*/
private
String
query
;
/**
* 回复模式:streaming流式模式,blocking阻塞模式
*/
@JsonProperty
(
"response_mode"
)
private
String
responseMode
;
/**
* (选填)会话id,需要基于之前的聊天记录继续对话,必须传之前消息的 conversation_id
* */
@JsonProperty
(
"conversation_id"
)
private
String
conversationId
;
/**
* 用户标识,用于定义终端用户的身份,方便检索、统计。 由开发者定义规则,需保证用户标识在应用内唯一。
* */
private
String
user
=
""
;
/**
* (选填)允许传入 App 定义的各变量值
*/
private
Map
<
String
,
String
>
inputs
=
new
HashMap
<>();
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/DifyChatDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* dify 流实体
* @author yangtq
* @date 2025/2/25
*/
@Data
public
class
DifyChatDTO
implements
Serializable
{
/**
* 用户id
*/
private
String
userId
;
/**
* 聊天内容
*/
private
String
query
;
/**
* (选填)会话id,若基于之前的聊天记录继续对话,必传之前消息的 conversation_id
*/
private
String
conversationId
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/DifyResponseDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
/**
* @author yangtq
* @date 2025/2/25
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
DifyResponseDTO
{
/**
* 消息id
*/
@JsonProperty
(
"message_id"
)
private
String
messageId
;
/**
* 事件
*/
private
String
event
;
/**
* 会话id
*/
@JsonProperty
(
"conversation_id"
)
private
String
conversationId
;
/**
* 创建时间戳
*/
@JsonProperty
(
"created_at"
)
private
int
createdAt
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/demo/DIfyWorkflowsResultDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify.demo
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.List
;
/**
* @author yangtq
* @date 2025/3/6
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
DIfyWorkflowsResultDTO
{
@JsonProperty
(
"event"
)
private
String
event
;
@JsonProperty
(
"workflow_run_id"
)
private
String
workflowRunId
;
@JsonProperty
(
"task_id"
)
private
String
taskId
;
@JsonProperty
(
"data"
)
private
Data
data
;
@lombok
.
Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Data
{
@JsonProperty
(
"id"
)
private
String
id
;
@JsonProperty
(
"workflow_id"
)
private
String
workflowId
;
@JsonProperty
(
"sequence_number"
)
private
int
sequenceNumber
;
@JsonProperty
(
"status"
)
private
String
status
;
@JsonProperty
(
"outputs"
)
private
Outputs
outputs
;
@JsonProperty
(
"error"
)
private
Object
error
;
// 根据实际需求调整类型
@JsonProperty
(
"elapsed_time"
)
private
double
elapsedTime
;
@JsonProperty
(
"total_tokens"
)
private
int
totalTokens
;
@JsonProperty
(
"total_steps"
)
private
int
totalSteps
;
@JsonProperty
(
"created_by"
)
private
CreatedBy
createdBy
;
@JsonProperty
(
"created_at"
)
private
long
createdAt
;
@JsonProperty
(
"finished_at"
)
private
long
finishedAt
;
@JsonProperty
(
"exceptions_count"
)
private
int
exceptionsCount
;
@JsonProperty
(
"files"
)
private
List
<
Object
>
files
;
// 根据实际需求调整类型
}
@lombok
.
Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Outputs
{
@JsonProperty
(
"result"
)
private
List
<
ResultItem
>
result
;
}
@lombok
.
Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
ResultItem
{
@JsonProperty
(
"metadata"
)
private
Metadata
metadata
;
@JsonProperty
(
"title"
)
private
String
title
;
@JsonProperty
(
"content"
)
private
String
content
;
}
@lombok
.
Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Metadata
{
@JsonProperty
(
"_source"
)
private
String
source
;
@JsonProperty
(
"dataset_id"
)
private
String
datasetId
;
@JsonProperty
(
"dataset_name"
)
private
String
datasetName
;
@JsonProperty
(
"document_id"
)
private
String
documentId
;
@JsonProperty
(
"document_name"
)
private
String
documentName
;
@JsonProperty
(
"document_data_source_type"
)
private
String
documentDataSourceType
;
@JsonProperty
(
"segment_id"
)
private
String
segmentId
;
@JsonProperty
(
"retriever_from"
)
private
String
retrieverFrom
;
@JsonProperty
(
"score"
)
private
double
score
;
@JsonProperty
(
"segment_hit_count"
)
private
int
segmentHitCount
;
@JsonProperty
(
"segment_word_count"
)
private
int
segmentWordCount
;
@JsonProperty
(
"segment_position"
)
private
int
segmentPosition
;
@JsonProperty
(
"segment_index_node_hash"
)
private
String
segmentIndexNodeHash
;
@JsonProperty
(
"position"
)
private
int
position
;
}
@lombok
.
Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
CreatedBy
{
@JsonProperty
(
"id"
)
private
String
id
;
@JsonProperty
(
"user"
)
private
String
user
;
}
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/demo/DifyEntityDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify.demo
;
import
lombok.Data
;
/**
* @author yangtq
* @date 2025/3/6
*/
@Data
public
class
DifyEntityDTO
{
private
String
context
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/demo/DifyWorkflowsDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify.demo
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.util.Map
;
/**
* @author yangtq
* @date 2025/3/6
*/
@Data
public
class
DifyWorkflowsDTO
{
/**
* 输入提问内容
*/
private
String
user
;
/**
* (选填)允许传入 App 定义的各变量值
*/
private
Map
<
String
,
String
>
inputs
;
/**
* 回复模式:streaming流式模式,blocking阻塞模式
*/
@JsonProperty
(
"response_mode"
)
private
String
responseMode
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/dify/demo/DifyWorkflowsExecDTO.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.dify.demo
;
import
com.ewaytek.deepseek.common.annotation.Excel
;
import
com.ewaytek.deepseek.doadmin.vo.dify.RetrieverResources
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author yangtq
* @date 2025/3/7
*/
@Data
public
class
DifyWorkflowsExecDTO
{
/**
* 相似问题
*/
@Excel
(
name
=
"问题"
)
private
String
question
;
/**
* 相似问题回复
*/
@Excel
(
name
=
"问题回复"
)
private
String
answer
;
@Excel
(
name
=
"引用"
)
private
List
<
RetrieverResources
>
retrieverResources
;
}
ewaytek-deepseek-web/src/main/java/com/ewaytek/deepseek/doadmin/dto/doubao/Choices.java
0 → 100644
View file @
0487b6d5
package
com.ewaytek.deepseek.doadmin.dto.doubao
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author yangtq
* @date 2025/4/18
*/
public
class
Choices
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
finish_reason
;
private
Integer
index
;
private
Delta
delta
;
public
String
getFinish_reason
()
{
return
finish_reason
;
}
public
void
setFinish_reason
(
String
finish_reason
)
{
this
.
finish_reason
=
finish_reason
;
}
public
Integer
getIndex
()
{
return
index
;
}
public
void
setIndex
(
Integer
index
)
{
this
.
index
=
index
;
}
public
Delta
getDelta
()
{
return
delta
;
}
public
void
setDelta
(
Delta
delta
)
{
this
.
delta
=
delta
;
}
}
Prev
1
2
3
4
5
6
7
8
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment