Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
robot-trans-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
robot-trans-platform
Commits
3d254032
Commit
3d254032
authored
Mar 25, 2025
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加对接dify
parent
c34a0995
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
25 deletions
+106
-25
robot-trans-manager/pom.xml
robot-trans-manager/pom.xml
+1
-1
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
...com/mortals/xhx/webflux/service/impl/BaseChatService.java
+2
-1
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/ChatMsgServiceImpl.java
.../mortals/xhx/webflux/service/impl/ChatMsgServiceImpl.java
+0
-2
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/template/AbstractFlowChatTemplate.java
...ortals/xhx/webflux/template/AbstractFlowChatTemplate.java
+3
-2
robot-trans-manager/src/test/java/TestRot.java
robot-trans-manager/src/test/java/TestRot.java
+28
-19
robot-trans-manager/src/test/java/TestRotWebClient.java
robot-trans-manager/src/test/java/TestRotWebClient.java
+72
-0
No files found.
robot-trans-manager/pom.xml
View file @
3d254032
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
<profiles.datasource.password>
12345678
</profiles.datasource.password>
<profiles.datasource.password>
12345678
</profiles.datasource.password>
<profiles.publish.path>
E:\pic\publish\
</profiles.publish.path>
<profiles.publish.path>
E:\pic\publish\
</profiles.publish.path>
<profiles.filepath>
E:/mortals/app/data
</profiles.filepath>
<profiles.filepath>
E:/mortals/app/data
</profiles.filepath>
<profiles.chat.streamChatUrl>
https://agent.wx3.com.cn
:443
/v1/chat-messages
</profiles.chat.streamChatUrl>
<profiles.chat.streamChatUrl>
https://agent.wx3.com.cn/v1/chat-messages
</profiles.chat.streamChatUrl>
<profiles.chat.auth-head>
Authorization
</profiles.chat.auth-head>
<profiles.chat.auth-head>
Authorization
</profiles.chat.auth-head>
<profiles.chat.auth-value>
Bearer app-ritPdgkz8bsrfzpcJdSTkUF5
</profiles.chat.auth-value>
<profiles.chat.auth-value>
Bearer app-ritPdgkz8bsrfzpcJdSTkUF5
</profiles.chat.auth-value>
</properties>
</properties>
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
View file @
3d254032
...
@@ -207,8 +207,9 @@ public class BaseChatService extends AbstractFlowChatTemplate {
...
@@ -207,8 +207,9 @@ public class BaseChatService extends AbstractFlowChatTemplate {
Boolean
stream
=
robotTransReq
.
getStream
();
Boolean
stream
=
robotTransReq
.
getStream
();
params
.
put
(
"inputs"
,
new
JSONObject
());
params
.
put
(
"inputs"
,
new
JSONObject
());
params
.
put
(
"response_mode"
,
"streaming"
);
params
.
put
(
"response_mode"
,
"streaming"
);
params
.
put
(
"conversation_id"
,
robotTransReq
.
getId
()
);
params
.
put
(
"conversation_id"
,
""
);
params
.
put
(
"user"
,
robotTransReq
.
getDeviceId
());
params
.
put
(
"user"
,
robotTransReq
.
getDeviceId
());
params
.
put
(
"files"
,
new
JSONArray
());
List
<
MessagesItem
>
messages
=
robotTransReq
.
getMessages
();
List
<
MessagesItem
>
messages
=
robotTransReq
.
getMessages
();
for
(
MessagesItem
message
:
messages
)
{
for
(
MessagesItem
message
:
messages
)
{
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/ChatMsgServiceImpl.java
View file @
3d254032
...
@@ -41,8 +41,6 @@ public class ChatMsgServiceImpl implements IChatMsgService {
...
@@ -41,8 +41,6 @@ public class ChatMsgServiceImpl implements IChatMsgService {
.
request
(
new
FlowChatContext
(
param
));
.
request
(
new
FlowChatContext
(
param
));
}
}
@Override
@Override
public
void
stopChat
(
SessionBaseParam
param
)
{
public
void
stopChat
(
SessionBaseParam
param
)
{
chatFactory
.
getInstance
(
FlowChatSceneEnum
.
BASE_CHAT
)
chatFactory
.
getInstance
(
FlowChatSceneEnum
.
BASE_CHAT
)
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/template/AbstractFlowChatTemplate.java
View file @
3d254032
...
@@ -37,7 +37,6 @@ public abstract class AbstractFlowChatTemplate implements IFlowChat, FlowChatCal
...
@@ -37,7 +37,6 @@ public abstract class AbstractFlowChatTemplate implements IFlowChat, FlowChatCal
private
void
init
()
{
private
void
init
()
{
webClient
=
WebClient
webClient
=
WebClient
.
builder
()
.
builder
()
.
baseUrl
(
"https://agent.wx3.com.cn"
)
.
defaultHeader
(
HttpHeaders
.
CONTENT_TYPE
,
"application/json"
).
build
();
.
defaultHeader
(
HttpHeaders
.
CONTENT_TYPE
,
"application/json"
).
build
();
}
}
...
@@ -111,12 +110,14 @@ public abstract class AbstractFlowChatTemplate implements IFlowChat, FlowChatCal
...
@@ -111,12 +110,14 @@ public abstract class AbstractFlowChatTemplate implements IFlowChat, FlowChatCal
*/
*/
private
Flux
<
String
>
doRequest
(
FlowChatContext
context
,
FLowChatRequest
request
,
HttpHeaders
headers
)
{
private
Flux
<
String
>
doRequest
(
FlowChatContext
context
,
FLowChatRequest
request
,
HttpHeaders
headers
)
{
log
.
info
(
"请求大模型开始,URL:{}, 参数:{}"
,
request
.
getUrl
(),
request
.
getJsonBody
());
log
.
info
(
"请求大模型开始,URL:{}, 参数:{}"
,
request
.
getUrl
(),
request
.
getJsonBody
());
Flux
<
String
>
flux
=
webClient
Flux
<
String
>
flux
=
webClient
.
post
()
.
post
()
.
uri
(
"/v1/chat-messages"
)
.
uri
(
request
.
getUrl
()
)
.
accept
(
MediaType
.
TEXT_EVENT_STREAM
)
.
accept
(
MediaType
.
TEXT_EVENT_STREAM
)
.
headers
(
httpHeaders
->
httpHeaders
.
addAll
(
headers
))
.
headers
(
httpHeaders
->
httpHeaders
.
addAll
(
headers
))
.
bodyValue
(
request
.
getJsonBody
())
.
bodyValue
(
request
.
getJsonBody
())
//.bodyValue(bodyStr)
.
retrieve
()
.
retrieve
()
.
bodyToFlux
(
String
.
class
)
.
bodyToFlux
(
String
.
class
)
.
onErrorResume
(
WebClientResponseException
.
class
,
ex
->
{
.
onErrorResume
(
WebClientResponseException
.
class
,
ex
->
{
...
...
robot-trans-manager/src/test/java/TestRot.java
View file @
3d254032
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.*
;
import
okhttp3.*
;
import
okio.BufferedSource
;
import
okio.BufferedSource
;
...
@@ -12,13 +14,15 @@ import java.util.concurrent.TimeUnit;
...
@@ -12,13 +14,15 @@ import java.util.concurrent.TimeUnit;
public
class
TestRot
{
public
class
TestRot
{
public
static
void
testRobotRwq
()
{
public
static
void
testRobotRwq
()
throws
IOException
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
()
OkHttpClient
client
=
new
OkHttpClient
.
Builder
()
.
connectTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
connectTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
30
,
TimeUnit
.
SECONDS
)
.
followRedirects
(
true
)
// 允许自动重定向
.
followSslRedirects
(
true
)
.
build
();
.
build
();
...
@@ -26,36 +30,39 @@ public class TestRot {
...
@@ -26,36 +30,39 @@ public class TestRot {
params.put("question", question);*/
params.put("question", question);*/
String
requestStr
=
"{\n"
+
String
requestStr
=
"{\n"
+
" \"id\": \"683a65fd-8feb-4446-ad32-714c4785f667\",\n"
+
" \"inputs\": {},\n"
+
" \"enterprise_id\": \"orion.ovs.entprise.6687895631\",\n"
+
" \"query\": \"周杰伦是谁?\",\n"
+
" \"device_id\": \"M03SCN00030230362FFA\",\n"
+
" \"response_mode\": \"streaming\",\n"
+
" \"messages\": [\n"
+
" \"conversation_id\": \"\",\n"
+
" {\n"
+
" \"user\": \"abc-123\",\n"
+
" \"role\": \"user\",\n"
+
" \"files\": []\n"
+
" \"content\": \"你有什么能力?\"\n"
+
" }\n"
+
" ],\n"
+
" \"max_tokens\": 2048,\n"
+
" \"stream\": true\n"
+
"}"
;
"}"
;
RequestBody
requestBody
=
RequestBody
.
create
(
requestStr
,
MediaType
.
parse
(
"application/json; charset=utf-8"
));
RequestBody
requestBody
=
RequestBody
.
create
(
requestStr
,
MediaType
.
parse
(
"application/json; charset=utf-8"
));
// 封装请求头
// 封装请求头
Headers
headers
=
new
Headers
.
Builder
()
Headers
headers
=
new
Headers
.
Builder
()
.
set
(
"Content-Type"
,
"application/json"
)
.
set
(
"Content-Type"
,
"application/json"
)
.
set
(
"Accept"
,
"text/event-stream"
)
.
set
(
"Accept"
,
"*/*"
)
.
set
(
"Authorization"
,
"Bearer app-ritPdgkz8bsrfzpcJdSTkUF5"
)
.
build
();
.
build
();
Request
request
=
new
Request
.
Builder
()
Request
request
=
new
Request
.
Builder
()
.
url
(
"http://localhost:18006/chat/base"
)
//.url("http://localhost:18006/chat/base")
//.url("http://robot.scsmile.cn/chat/base")
// .url("http://robot.scsmile.cn/v1/chat-messages")
.
url
(
"https://agent.wx3.com.cn/v1/chat-messages"
)
//.url(".url("https://agent.wx3.com.cn/v1/chat-messages")")
.
headers
(
headers
)
.
headers
(
headers
)
.
post
(
requestBody
)
.
post
(
requestBody
)
.
build
();
.
build
();
/* Response response = client.newCall(request).execute();
log.info(response.code() + "");*/
Call
call
=
client
.
newCall
(
request
);
Call
call
=
client
.
newCall
(
request
);
// 4. 监听回调
// 4. 监听回调
call
.
enqueue
(
new
Callback
()
{
call
.
enqueue
(
new
Callback
()
{
...
@@ -67,6 +74,7 @@ public class TestRot {
...
@@ -67,6 +74,7 @@ public class TestRot {
@Override
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
log
.
info
(
JSON
.
toJSONString
(
response
));
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
String
chunkMessage
=
""
;
String
chunkMessage
=
""
;
BufferedSource
source
=
response
.
body
().
source
();
BufferedSource
source
=
response
.
body
().
source
();
...
@@ -75,12 +83,14 @@ public class TestRot {
...
@@ -75,12 +83,14 @@ public class TestRot {
if
(
StringUtils
.
isBlank
(
chunkMessage
))
{
if
(
StringUtils
.
isBlank
(
chunkMessage
))
{
continue
;
continue
;
}
}
/* JSONObject jsonObject = JSONObject.parseObject(chunkMessage);
/* JSONObject jsonObject = JSONObject.parseObject(chunkMessage);
if (null != jsonObject && null != jsonObject.getJSONObject("data")) {
if (null != jsonObject && null != jsonObject.getJSONObject("data")) {
String answer = jsonObject.getJSONObject("data").getString("answer");
String answer = jsonObject.getJSONObject("data").getString("answer");
// sseEmitter.send(answer);
// sseEmitter.send(answer);
}*/
}*/
log
.
info
(
"chunkMessage:{}"
,
chunkMessage
);
log
.
info
(
"chunkMessage:{}"
,
chunkMessage
);
}
}
...
@@ -92,11 +102,10 @@ public class TestRot {
...
@@ -92,11 +102,10 @@ public class TestRot {
}
}
});
});
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
testRobotRwq
();
testRobotRwq
();
...
...
robot-trans-manager/src/test/java/TestRotWebClient.java
0 → 100644
View file @
3d254032
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.*
;
import
okio.BufferedSource
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Flux
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
@Slf4j
public
class
TestRotWebClient
{
public
static
String
decodeUnicode
(
String
unicodeStr
)
{
Pattern
pattern
=
Pattern
.
compile
(
"\\\\u([0-9a-fA-F]{4})"
);
Matcher
matcher
=
pattern
.
matcher
(
unicodeStr
);
StringBuffer
decoded
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
int
charCode
=
Integer
.
parseInt
(
matcher
.
group
(
1
),
16
);
matcher
.
appendReplacement
(
decoded
,
Character
.
toString
((
char
)
charCode
));
}
matcher
.
appendTail
(
decoded
);
return
decoded
.
toString
();
}
public
static
void
testRobotRwq
()
throws
IOException
{
WebClient
client
=
WebClient
.
create
(
"https://agent.wx3.com.cn"
);
String
bodyStr
=
"{\n"
+
" \"inputs\": {},\n"
+
" \"query\": \"周杰伦是谁?\",\n"
+
" \"response_mode\": \"streaming\",\n"
+
" \"conversation_id\": \"\",\n"
+
" \"user\": \"abc-123\",\n"
+
" \"files\": []\n"
+
"}"
;
Flux
<
String
>
eventStream
=
client
.
post
()
.
uri
(
"/v1/chat-messages"
)
// 远程 SSE API
.
header
(
"Content-Type"
,
"application/json"
)
.
header
(
"Accept"
,
"*/*"
)
.
header
(
"Accept-Charset"
,
"UTF-8"
)
.
header
(
"Authorization"
,
"Bearer app-ritPdgkz8bsrfzpcJdSTkUF5"
)
.
bodyValue
(
bodyStr
)
// 发送 JSON 订阅请求
.
retrieve
()
.
bodyToFlux
(
String
.
class
);
// 处理流数据
// 订阅并打印收到的事件
eventStream
.
subscribe
(
event
->
System
.
out
.
println
(
"Received event: "
+
decodeUnicode
(
event
)),
error
->
System
.
err
.
println
(
"Error: "
+
error
),
()
->
System
.
out
.
println
(
"Stream completed"
));
// 保持主线程运行,否则程序可能会立即退出
while
(
true
)
{}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
testRobotRwq
();
}
}
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