Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sl-ai
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
zhouwei
sl-ai
Commits
12eca765
Commit
12eca765
authored
May 06, 2025
by
zhouwei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
新增request id日志 See merge request
!12
parents
6d186fb3
be361a3e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
10 deletions
+12
-10
AIController.java
...java/com/nanyan/securitylink/controller/AIController.java
+7
-2
AIService.java
src/main/java/com/nanyan/securitylink/service/AIService.java
+1
-1
AIServiceImpl.java
...a/com/nanyan/securitylink/service/impl/AIServiceImpl.java
+3
-7
AIResponse.java
src/main/java/com/nanyan/securitylink/vo/AIResponse.java
+1
-0
No files found.
src/main/java/com/nanyan/securitylink/controller/AIController.java
View file @
12eca765
package
com
.
nanyan
.
securitylink
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.nanyan.securitylink.dto.AIRequestDTO
;
import
com.nanyan.securitylink.service.AIService
;
import
com.nanyan.securitylink.vo.AIResponse
;
import
com.nanyan.securitylink.vo.CodeVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nanyan.securitylink.vo.Response
;
@Slf4j
@RestController
public
class
AIController
{
@Autowired
AIService
aiService
;
@PostMapping
(
"/translate"
)
public
Response
<
AIResponse
<
String
>>
translate
(
@RequestBody
AIRequestDTO
AIRequestDTO
)
{
return
Response
.
SUCCESS
(
aiService
.
translate
(
AIRequestDTO
));
public
Response
<
AIResponse
<
String
>>
translate
(
@RequestBody
AIRequestDTO
AIRequestDTO
,
@RequestHeader
(
"request_id"
)
String
requestId
)
{
log
.
info
(
"requestId:{}, body:{}"
,
requestId
,
JSONObject
.
toJSONString
(
AIRequestDTO
));
return
Response
.
SUCCESS
(
aiService
.
translate
(
AIRequestDTO
,
requestId
));
}
@PostMapping
(
"/news/tag"
)
public
Response
<
AIResponse
<
CodeVO
>>
newsTag
(
@RequestBody
AIRequestDTO
AIRequestDTO
)
{
...
...
src/main/java/com/nanyan/securitylink/service/AIService.java
View file @
12eca765
...
...
@@ -6,7 +6,7 @@ import com.nanyan.securitylink.vo.AIResponse;
import
com.nanyan.securitylink.vo.CodeVO
;
public
interface
AIService
{
AIResponse
<
String
>
translate
(
AIRequestDTO
AIRequestDTO
);
AIResponse
<
String
>
translate
(
AIRequestDTO
AIRequestDTO
,
String
requestId
);
AIResponse
<
CodeVO
>
newsTags
(
AIRequestDTO
AIRequestDTO
);
AIResponse
<
CodeVO
>
naturalDisasterTag
(
AIRequestDTO
aiRequestDTO
);
...
...
src/main/java/com/nanyan/securitylink/service/impl/AIServiceImpl.java
View file @
12eca765
...
...
@@ -149,12 +149,13 @@ public class AIServiceImpl implements AIService {
private
final
static
String
DEEP_SEEK_URL
=
"https://ark.cn-beijing.volces.com/api/v3/chat/completions"
;
@Override
public
AIResponse
<
String
>
translate
(
AIRequestDTO
AIRequestDTO
)
{
public
AIResponse
<
String
>
translate
(
AIRequestDTO
AIRequestDTO
,
String
requestId
)
{
ChatInputData
chatInputData
=
new
ChatInputData
();
buildTranslate
(
chatInputData
,
AIRequestDTO
);
String
apiKey
=
getModelApiKey
();
ChatCompletionResponse
chatCompletionResponse
=
aiRequest
(
chatInputData
,
apiKey
);
log
.
info
(
"requestId:{} translate response:{}"
,
requestId
,
JSONObject
.
toJSONString
(
chatCompletionResponse
));
if
(
CollectionUtils
.
isNotEmpty
(
chatCompletionResponse
.
getChoices
()))
{
AIResponse
<
String
>
aiResponse
=
new
AIResponse
<>();
...
...
@@ -561,12 +562,7 @@ public class AIServiceImpl implements AIService {
HttpEntity
<
String
>
entity
=
new
HttpEntity
<>(
writeValueAsString
,
header
.
getHeaders
());
ResponseEntity
<
ChatCompletionResponse
>
response
=
restTemplate
.
postForEntity
(
DEEP_SEEK_URL
,
entity
,
ChatCompletionResponse
.
class
);
if
(
response
.
getStatusCode
().
is2xxSuccessful
())
{
if
(
response
.
getHeaders
().
containsKey
(
REQUEST_ID
)){
log
.
info
(
"request id:{},translate response:{}"
,
response
.
getHeaders
().
get
(
REQUEST_ID
),
JSONObject
.
toJSONString
(
response
.
getBody
()));
}
else
{
log
.
info
(
"translate response:{}"
,
JSONObject
.
toJSONString
(
response
.
getBody
()));
}
log
.
info
(
"ai response:{}"
,
JSONObject
.
toJSONString
(
response
.
getBody
()));
return
response
.
getBody
();
}
throw
new
BaseException
(
MsgCode
.
TRANSLATE_ERROR
);
...
...
src/main/java/com/nanyan/securitylink/vo/AIResponse.java
View file @
12eca765
...
...
@@ -8,6 +8,7 @@ public class AIResponse<T> {
private
String
task_id
;
private
String
id
;
private
String
message_id
;
private
String
requestId
;
private
String
mode
;
private
String
answer
;
private
ResultVO
<
T
>
outputs
;
...
...
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