Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-ai
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-ai
Commits
18044d65
Commit
18044d65
authored
Apr 23, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
9574bb8d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
yd-ai-api/src/main/java/com/yd/ai/api/service/impl/ApiAiStreamServiceImpl.java
+19
-0
No files found.
yd-ai-api/src/main/java/com/yd/ai/api/service/impl/ApiAiStreamServiceImpl.java
View file @
18044d65
...
@@ -28,12 +28,17 @@ import java.util.Arrays;
...
@@ -28,12 +28,17 @@ import java.util.Arrays;
@Service
@Service
public
class
ApiAiStreamServiceImpl
implements
ApiAiStreamService
{
public
class
ApiAiStreamServiceImpl
implements
ApiAiStreamService
{
public
static
final
String
RESET
=
"\u001B[0m"
;
public
static
final
String
CYAN
=
"\u001B[36m"
;
public
static
final
String
GREEN
=
"\u001B[32m"
;
@Autowired
@Autowired
private
ApiSensitiveWordDetailService
apiSensitiveWordDetailService
;
private
ApiSensitiveWordDetailService
apiSensitiveWordDetailService
;
@Autowired
@Autowired
private
ApiNotificationTaskFeignClient
apiNotificationTaskFeignClient
;
private
ApiNotificationTaskFeignClient
apiNotificationTaskFeignClient
;
/**
/**
* 流式对话(SSE),保留敏感词检测逻辑
* 流式对话(SSE),保留敏感词检测逻辑
*/
*/
...
@@ -98,6 +103,9 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
...
@@ -98,6 +103,9 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
flowable
.
subscribe
(
flowable
.
subscribe
(
result
->
{
result
->
{
String
delta
=
result
.
getOutput
().
getChoices
().
get
(
0
).
getMessage
().
getContent
();
String
delta
=
result
.
getOutput
().
getChoices
().
get
(
0
).
getMessage
().
getContent
();
// 实时着色并打印
printWithStyle
(
delta
);
System
.
out
.
flush
();
sink
.
next
(
delta
);
sink
.
next
(
delta
);
},
},
error
->
{
error
->
{
...
@@ -108,4 +116,14 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
...
@@ -108,4 +116,14 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
);
);
});
});
}
}
private
static
void
printWithStyle
(
String
text
)
{
for
(
char
ch
:
text
.
toCharArray
())
{
if
(
ch
==
'|'
||
ch
==
'-'
||
ch
==
'='
)
{
System
.
out
.
print
(
CYAN
+
ch
+
RESET
);
}
else
{
System
.
out
.
print
(
GREEN
+
ch
+
RESET
);
}
}
}
}
}
\ No newline at end of file
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