Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
deep-ask
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
deepseek
deep-ask
Commits
78c55c1d
Commit
78c55c1d
authored
Mar 17, 2025
by
luojun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deepseek优化
parent
7d7aaeef
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
174 additions
and
30 deletions
+174
-30
DeepSeekAiListener.java
src/main/java/admin/listener/DeepSeekAiListener.java
+67
-29
PythonApiReq.java
src/main/java/admin/model/python/PythonApiReq.java
+14
-0
OpenApiController.java
src/main/java/admin/rest/OpenApiController.java
+10
-0
VoiceWebSocketServer.java
src/main/java/admin/server/VoiceWebSocketServer.java
+27
-0
PythonOpenApiClient.java
src/main/java/admin/service/PythonOpenApiClient.java
+12
-0
PythonOpenApiClientImpl.java
...main/java/admin/service/impl/PythonOpenApiClientImpl.java
+23
-0
HttpUtil.java
src/main/java/admin/util/HttpUtil.java
+19
-0
ResponseEnum.java
src/main/java/admin/util/ResponseEnum.java
+2
-1
No files found.
src/main/java/admin/listener/DeepSeekAiListener.java
View file @
78c55c1d
...
...
@@ -20,10 +20,8 @@ import okhttp3.sse.EventSourceListener;
import
javax.websocket.Session
;
import
java.io.IOException
;
import
java.net.SocketException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* @author lj
...
...
@@ -33,6 +31,7 @@ import java.util.Objects;
public
class
DeepSeekAiListener
extends
EventSourceListener
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
private
Set
<
String
>
set
=
new
HashSet
<>();
private
MaxKbChatReq
maxKbChatReq
;
private
ChatgptRoleRecordsService
chatgptRoleRecordsService
;
...
...
@@ -45,6 +44,11 @@ public class DeepSeekAiListener extends EventSourceListener {
public
void
onOpen
(
EventSource
eventSource
,
Response
response
)
{
super
.
onOpen
(
eventSource
,
response
);
//1.中科慧居简介直接发送
sendStartTranslate
(
maxKbChatReq
.
getSession
());
log
.
info
(
"DeepSeek建立sse连接...onOpen"
);
}
private
void
sendStartTranslate
(
Session
session
)
{
if
(
maxKbChatReq
.
getShowType
()!=
null
&&
maxKbChatReq
.
getShowType
().
equals
(
ResponseEnum
.
ZK_PROFILE
.
getDesc
())){
WebSocketModel
webSocketModel
=
new
WebSocketModel
();
webSocketModel
.
setAction
(
"start"
);
...
...
@@ -52,35 +56,44 @@ public class DeepSeekAiListener extends EventSourceListener {
webSocketModel
.
setShowType
(
maxKbChatReq
.
getShowType
());
webSocketModel
.
setContent
(
""
);
try
{
maxKbChatReq
.
getSession
().
getBasicRemote
().
sendText
(
JSON
.
toJSONString
(
webSocketModel
));
session
.
getBasicRemote
().
sendText
(
JSON
.
toJSONString
(
webSocketModel
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
if
(
maxKbChatReq
.
getShowType
()!=
null
&&
maxKbChatReq
.
getShowType
().
equals
(
ResponseEnum
.
ZK_PRODUCT
.
getDesc
())){
WebSocketModel
webSocketModel
=
new
WebSocketModel
();
webSocketModel
.
setAction
(
"start"
);
webSocketModel
.
setType
(
"text"
);
webSocketModel
.
setShowType
(
maxKbChatReq
.
getShowType
());
webSocketModel
.
setContent
(
""
);
try
{
session
.
getBasicRemote
().
sendText
(
JSON
.
toJSONString
(
webSocketModel
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
if
(
maxKbChatReq
.
getShowType
()!=
null
&&
maxKbChatReq
.
getShowType
().
equals
(
ResponseEnum
.
ZK_USER
.
getDesc
())){
WebSocketModel
webSocketModel
=
new
WebSocketModel
();
webSocketModel
.
setAction
(
"start"
);
webSocketModel
.
setType
(
"text"
);
webSocketModel
.
setShowType
(
maxKbChatReq
.
getShowType
());
webSocketModel
.
setContent
(
""
);
try
{
session
.
getBasicRemote
().
sendText
(
JSON
.
toJSONString
(
webSocketModel
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
if
(
maxKbChatReq
.
getShowType
()!=
null
&&
maxKbChatReq
.
getShowType
().
equals
(
ResponseEnum
.
ZK_SOFTWARE
.
getDesc
())){
WebSocketModel
webSocketModel
=
new
WebSocketModel
();
webSocketModel
.
setAction
(
"start"
);
webSocketModel
.
setType
(
"text"
);
webSocketModel
.
setShowType
(
maxKbChatReq
.
getShowType
());
webSocketModel
.
setContent
(
""
);
try
{
session
.
getBasicRemote
().
sendText
(
JSON
.
toJSONString
(
webSocketModel
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
// else if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_PRODUCT.getDesc())){
// WebSocketModel webSocketModel = new WebSocketModel();
// webSocketModel.setAction("start");
// webSocketModel.setType("text");
// webSocketModel.setShowType(maxKbChatReq.getShowType());
// webSocketModel.setContent("");
// try {
// maxKbChatReq.getSession().getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }else if (maxKbChatReq.getShowType().equals(ResponseEnum.ZK_USER.getDesc())){
// WebSocketModel webSocketModel = new WebSocketModel();
// webSocketModel.setAction("start");
// webSocketModel.setType("text");
// webSocketModel.setShowType(maxKbChatReq.getShowType());
// webSocketModel.setContent("");
// try {
// maxKbChatReq.getSession().getBasicRemote().sendText(JSON.toJSONString(webSocketModel));
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
log
.
info
(
"DeepSeek建立sse连接...onOpen"
);
}
...
...
@@ -100,6 +113,19 @@ public class DeepSeekAiListener extends EventSourceListener {
map
.
put
(
"content"
,
completionResponse
.
getContent
());
String
msg
=
JSON
.
toJSONString
(
map
);
maxKbChatReq
.
getSession
().
getBasicRemote
().
sendText
(
msg
);
if
(
maxKbChatReq
.
getClient
().
equals
(
WebSocketUtil
.
H5
)){
List
<
Session
>
webMap
=
WebConnectUtil
.
getWebMap
(
maxKbChatReq
.
getUserName
());
if
(!
webMap
.
isEmpty
()){
webMap
.
forEach
(
i
->{
try
{
i
.
getBasicRemote
().
sendText
(
msg
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
});
}
}
// introduce();
//存储聊天记录
ChatgptRoleRecords
chatgptRoleRecords
=
new
ChatgptRoleRecords
();
...
...
@@ -123,6 +149,8 @@ public class DeepSeekAiListener extends EventSourceListener {
maxKbChatReq
.
getSession
().
getBasicRemote
().
sendText
(
msg
);
if
(
maxKbChatReq
.
getClient
().
equals
(
WebSocketUtil
.
H5
)){
List
<
Session
>
webMap
=
WebConnectUtil
.
getWebMap
(
maxKbChatReq
.
getUserName
());
//发送到web端展示动画
sendWebShowAnimation
(
webMap
);
if
(!
webMap
.
isEmpty
()){
webMap
.
forEach
(
i
->{
try
{
...
...
@@ -146,6 +174,16 @@ public class DeepSeekAiListener extends EventSourceListener {
}
private
void
sendWebShowAnimation
(
List
<
Session
>
webMap
)
{
for
(
Session
session
:
webMap
)
{
if
(!
set
.
contains
(
session
.
getId
())){
set
.
add
(
session
.
getId
());
sendStartTranslate
(
session
);
}
}
}
/**
* 发送介绍信息(介绍产品信息 介绍人员信息)
*/
...
...
src/main/java/admin/model/python/PythonApiReq.java
0 → 100644
View file @
78c55c1d
package
admin
.
model
.
python
;
import
lombok.Data
;
/**
* @author lj
* @date 2025/3/13 15:30
*/
@Data
public
class
PythonApiReq
{
private
String
model
=
""
;
private
String
question
;
}
src/main/java/admin/rest/OpenApiController.java
View file @
78c55c1d
...
...
@@ -2,9 +2,11 @@ package admin.rest;
import
admin.model.MaxKbChatReq
;
import
admin.model.SendSseModel
;
import
admin.model.python.PythonApiReq
;
import
admin.resp.ApiResponse
;
import
admin.service.DeepSeekOpenApiService
;
import
admin.service.MaxkbOpenApiService
;
import
admin.service.PythonOpenApiClient
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -23,6 +25,7 @@ public class OpenApiController {
private
final
DeepSeekOpenApiService
deepSeekOpenApiService
;
private
final
MaxkbOpenApiService
maxkbOpenApiService
;
private
final
PythonOpenApiClient
pythonOpenApiClient
;
@PostMapping
(
value
=
"completions"
)
public
ApiResponse
<
Object
>
completions
(
@RequestParam
String
content
){
...
...
@@ -47,4 +50,11 @@ public class OpenApiController {
public
void
testcompletions
(
@RequestParam
SendSseModel
sendSseModel
){
maxkbOpenApiService
.
talk
(
sendSseModel
);
}
@GetMapping
(
"testAnalysis"
)
public
ApiResponse
<
Object
>
testAnalysis
(
PythonApiReq
pythonApiReq
){
String
analysisData
=
pythonOpenApiClient
.
getAnalysisData
(
pythonApiReq
);
return
ApiResponse
.
buildSuccess
(
analysisData
);
}
}
src/main/java/admin/server/VoiceWebSocketServer.java
View file @
78c55c1d
...
...
@@ -3,11 +3,13 @@ package admin.server;
import
admin.config.SpeechToTextConfig
;
import
admin.model.SendSseModel
;
import
admin.model.WebSocketModel
;
import
admin.model.python.PythonApiReq
;
import
admin.modules.chatgpt.domain.ChatgptRoleRecords
;
import
admin.modules.chatgpt.domain.ChatgptRoleSession
;
import
admin.modules.chatgpt.service.ChatgptRoleRecordsService
;
import
admin.modules.chatgpt.service.ChatgptRoleSessionService
;
import
admin.service.MaxkbOpenApiService
;
import
admin.service.PythonOpenApiClient
;
import
admin.util.*
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -32,6 +34,7 @@ import java.nio.charset.Charset;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Stream
;
/**
* @author lj
...
...
@@ -45,6 +48,7 @@ public class VoiceWebSocketServer {
private
static
MaxkbOpenApiService
maxkbOpenApiService
;
private
static
ChatgptRoleRecordsService
chatgptRoleRecordsService
;
private
static
ChatgptRoleSessionService
chatgptRoleSessionService
;
private
static
PythonOpenApiClient
pythonOpenApiClient
;
@Resource
public
void
setVoiceConfig
(
SpeechToTextConfig
speechToTextConfig
){
...
...
@@ -56,6 +60,11 @@ public class VoiceWebSocketServer {
this
.
chatgptRoleRecordsService
=
chatgptRoleRecordsService
;
}
@Resource
public
void
setPythonOpenApiClient
(
PythonOpenApiClient
pythonOpenApiClient
){
this
.
pythonOpenApiClient
=
pythonOpenApiClient
;
}
@Resource
public
void
setChatgptRoleSessionService
(
ChatgptRoleSessionService
chatgptRoleSessionService
){
this
.
chatgptRoleSessionService
=
chatgptRoleSessionService
;
...
...
@@ -201,6 +210,22 @@ public class VoiceWebSocketServer {
webSocketModel1
.
setContent
(
""
);
String
msg
=
JSON
.
toJSONString
(
webSocketModel1
);
sendMessage
(
session
,
msg
);
}
else
if
(
"startAnalysis"
.
equals
(
webSocketModel
.
getAction
())){
PythonApiReq
pythonApiReq
=
new
PythonApiReq
();
pythonApiReq
.
setQuestion
(
webSocketModel
.
getData
());
String
analysisData
=
pythonOpenApiClient
.
getAnalysisData
(
pythonApiReq
);
char
[]
charArray
=
analysisData
.
toCharArray
();
for
(
int
i
=
0
;
i
<
charArray
.
length
;
i
++){
WebSocketModel
webSocketModel1
=
new
WebSocketModel
();
webSocketModel1
.
setAction
(
"reply"
);
webSocketModel1
.
setType
(
"text"
);
webSocketModel1
.
setContent
(
String
.
valueOf
(
charArray
[
i
]));
sendMessage
(
session
,
JSONObject
.
toJSONString
(
webSocketModel1
));
}
WebSocketModel
endWebSocket
=
new
WebSocketModel
();
endWebSocket
.
setAction
(
"done"
);
endWebSocket
.
setType
(
"text"
);
sendMessage
(
session
,
JSONObject
.
toJSONString
(
endWebSocket
));
}
}
...
...
@@ -279,6 +304,8 @@ public class VoiceWebSocketServer {
return
ResponseEnum
.
ZK_PRODUCT
.
getDesc
();
}
else
if
(
msg
.
contains
(
"中科慧居"
)
&&
msg
.
contains
(
"人员介绍"
)){
return
ResponseEnum
.
ZK_USER
.
getDesc
();
}
else
if
(
msg
.
contains
(
"中科慧居"
)
&&
msg
.
contains
(
"软件介绍"
)){
return
ResponseEnum
.
ZK_SOFTWARE
.
getDesc
();
}
else
if
(
msg
.
contains
(
"中科慧居"
)
&&
msg
.
contains
(
"简介"
)){
return
ResponseEnum
.
ZK_PROFILE
.
getDesc
();
}
else
if
(
msg
.
contains
(
ResponseEnum
.
PIE_CHART
.
getDesc
())){
...
...
src/main/java/admin/service/PythonOpenApiClient.java
0 → 100644
View file @
78c55c1d
package
admin
.
service
;
import
admin.model.python.PythonApiReq
;
/**
* @author lj
* @date 2025/3/13 15:17
*/
public
interface
PythonOpenApiClient
{
String
getAnalysisData
(
PythonApiReq
pythonApiReq
);
}
src/main/java/admin/service/impl/PythonOpenApiClientImpl.java
0 → 100644
View file @
78c55c1d
package
admin
.
service
.
impl
;
import
admin.model.python.PythonApiReq
;
import
admin.service.PythonOpenApiClient
;
import
admin.util.HttpUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
/**
* @author lj
* @date 2025/3/13 15:17
*/
@Service
@RequiredArgsConstructor
@Slf4j
public
class
PythonOpenApiClientImpl
implements
PythonOpenApiClient
{
@Override
public
String
getAnalysisData
(
PythonApiReq
pythonApiReq
)
{
return
HttpUtil
.
post
(
"http://py.justh5.com/aiapi/sqlqa/"
,
pythonApiReq
);
}
}
src/main/java/admin/util/HttpUtil.java
View file @
78c55c1d
...
...
@@ -12,6 +12,7 @@ import org.springframework.context.ApplicationContext;
import
javax.websocket.Session
;
import
java.io.IOException
;
import
java.time.Duration
;
/**
* @author lj
...
...
@@ -37,6 +38,24 @@ public class HttpUtil {
}
public
static
String
post
(
String
url
,
Object
data
){
OkHttpClient
okHttpClient
=
new
OkHttpClient
().
newBuilder
().
connectTimeout
(
Duration
.
ofSeconds
(
30
)).
build
();
Request
request
=
null
;
try
{
request
=
new
Request
.
Builder
()
.
url
(
url
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
addHeader
(
"Accept"
,
"application/json"
)
.
post
(
RequestBody
.
create
(
MediaType
.
parse
(
"application/json"
),
new
ObjectMapper
().
writeValueAsString
(
data
)))
.
build
();
Response
execute
=
okHttpClient
.
newCall
(
request
).
execute
();
return
execute
.
body
().
string
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
void
postCallBackStream
(
String
url
,
Object
data
,
String
apiKey
,
MaxKbChatReq
maxKbChatReq
,
ChatgptRoleRecordsService
chatgptRoleRecordsService
){
OkHttpClient
okHttpClient
=
new
OkHttpClient
().
newBuilder
().
build
();
// RequestBody body = RequestBody.create(MediaType.parse("application/json"), data);
...
...
src/main/java/admin/util/ResponseEnum.java
View file @
78c55c1d
...
...
@@ -15,7 +15,8 @@ public enum ResponseEnum{
BAR_CHART
(
3
,
"柱状图"
),
TREND_CHART
(
4
,
"趋势图"
),
ZK_PRODUCT
(
5
,
"中科慧居产品介绍"
),
ZK_USER
(
6
,
"中科慧居人员介绍"
);
ZK_USER
(
6
,
"中科慧居人员介绍"
),
ZK_SOFTWARE
(
7
,
"中科慧居软件介绍"
);
int
type
;
String
desc
;
...
...
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