Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ask_data_ai_admin
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
linyangyang
ask_data_ai_admin
Commits
ad68abba
Commit
ad68abba
authored
Jul 21, 2025
by
林洋洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加调用工具 接口
parent
86989a4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
14 deletions
+67
-14
ChatController.java
...-biz/src/main/java/com/ask/controller/ChatController.java
+40
-5
ExcelTools.java
...k-data-ai-biz/src/main/java/com/ask/tools/ExcelTools.java
+19
-0
FluxUtils.java
...sk-data-ai-biz/src/main/java/com/ask/utils/FluxUtils.java
+7
-8
application.yml
...ta-ai/ask-data-ai-boot/src/main/resources/application.yml
+1
-1
No files found.
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/controller/ChatController.java
View file @
ad68abba
...
...
@@ -8,6 +8,7 @@ import com.ask.common.core.R;
import
com.ask.service.ChatConversationService
;
import
com.ask.service.impl.ChatService
;
import
com.ask.service.impl.RagPromptService
;
import
com.ask.tools.ExcelTools
;
import
com.ask.utils.FluxUtils
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
...
...
@@ -25,6 +26,8 @@ import org.springframework.ai.chat.model.ChatResponse;
import
org.springframework.ai.chat.prompt.Prompt
;
import
org.springframework.ai.deepseek.DeepSeekAssistantMessage
;
import
org.springframework.ai.document.Document
;
import
org.springframework.ai.model.tool.ToolCallingChatOptions
;
import
org.springframework.ai.model.tool.ToolExecutionResult
;
import
org.springframework.ai.openai.OpenAiChatModel
;
import
org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor
;
import
org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever
;
...
...
@@ -68,6 +71,8 @@ public class ChatController {
private
final
ChatMemory
chatMemory
;
private
final
OpenAiChatModel
openAiChatModel
;
private
final
ExcelTools
excelTools
;
/**
* 获取会话ID
*
...
...
@@ -104,9 +109,6 @@ public class ChatController {
Message
userMessage
=
new
UserMessage
(
"问题:"
+
message
+
"\n回答要求:请使用markdown格式输出"
);
Prompt
prompt
=
new
Prompt
(
List
.
of
(
systemMessage
,
userMessage
));
AtomicBoolean
reasoningStarted
=
new
AtomicBoolean
(
false
);
AtomicBoolean
answerStarted
=
new
AtomicBoolean
(
false
);
return
FluxUtils
.
wrapDeepSeekStream
(
deepseekChatClient
.
prompt
(
prompt
)
.
advisors
(
messageChatMemoryAdvisor
)
.
advisors
(
a
->
a
.
param
(
ChatMemory
.
CONVERSATION_ID
,
conversationId
))
...
...
@@ -114,6 +116,7 @@ public class ChatController {
.
chatResponse
());
}
/**
* 知识库对话
* <p>
...
...
@@ -145,9 +148,9 @@ public class ChatController {
return
FluxUtils
.
wrapDeepSeekStream
(
deepseekChatClient
.
prompt
()
.
user
(
userPrompt
)
.
system
(
"你是一个智能助手,基于以下上下文和历史对话回答问题,请用简洁的语言回答问题,并确保答案准确,要求"
+
"1.以 Markdown 格式输出"
)
"1.以 Markdown 格式输出"
)
.
stream
()
.
chatResponse
(),
contentBuilder
)
.
chatResponse
(),
contentBuilder
)
.
concatWith
(
Flux
.
just
(
reference
))
.
doOnComplete
(()
->
{
// 流结束时获取完整内容
...
...
@@ -156,4 +159,36 @@ public class ChatController {
chatService
.
saveHistoryMemory
(
conversationId
,
new
AssistantMessage
(
fullResponse
));
});
}
@Operation
(
summary
=
"智能数据报表对话"
,
description
=
"智能数据报表对话"
)
@GetMapping
(
value
=
"/chat/report"
)
public
String
reportChat
(
@RequestParam
String
message
,
@RequestParam
String
conversationId
)
{
Message
systemMessage
=
new
SystemMessage
(
"你是一个AI问答助手,请用回答用户问题,使用相关工具"
);
Message
userMessage
=
new
UserMessage
(
"问题:"
+
message
+
"\n回答要求:请使用markdown格式输出"
);
Prompt
prompt
=
new
Prompt
(
List
.
of
(
systemMessage
,
userMessage
));
// ChatResponse chatResponse = openAiChatClient.prompt(prompt)
// .advisors(messageChatMemoryAdvisor)
// .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
// .tools(new ExcelTools())
// // 关闭内部自动执行
// .options(
// ToolCallingChatOptions.builder()
// .internalToolExecutionEnabled(false) // ← 关键
// .build()
// )
// .call().chatResponse();
return
openAiChatClient
.
prompt
(
prompt
)
.
advisors
(
messageChatMemoryAdvisor
)
.
advisors
(
a
->
a
.
param
(
ChatMemory
.
CONVERSATION_ID
,
conversationId
))
.
tools
(
new
ExcelTools
())
.
call
()
.
content
();
}
}
\ No newline at end of file
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/tools/ExcelTools.java
0 → 100644
View file @
ad68abba
package
com
.
ask
.
tools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.ai.tool.annotation.Tool
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
@Component
@Slf4j
public
class
ExcelTools
{
@Tool
(
description
=
"Get the current date and time in the user's timezone"
)
String
getCurrentDateTime
()
{
log
.
info
(
"调用getCurrentDateTime"
);
return
LocalDateTime
.
now
().
atZone
(
LocaleContextHolder
.
getTimeZone
().
toZoneId
()).
toString
();
}
}
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/utils/FluxUtils.java
View file @
ad68abba
...
...
@@ -25,12 +25,12 @@ public class FluxUtils {
(
DeepSeekAssistantMessage
)
resp
.
getResult
().
getOutput
();
StringBuilder
sb
=
new
StringBuilder
();
if
(
reasoningStarted
.
compareAndSet
(
false
,
true
))
{
sb
.
append
(
"<think>"
);
}
// 推理阶段:第一次出现推理内容时输出 <think>
if
(
StringUtils
.
isNotBlank
(
msg
.
getReasoningContent
()))
{
if
(
reasoningStarted
.
compareAndSet
(
false
,
true
))
{
sb
.
append
(
"<think>"
);
}
sb
.
append
(
msg
.
getReasoningContent
());
}
...
...
@@ -58,12 +58,11 @@ public class FluxUtils {
(
DeepSeekAssistantMessage
)
resp
.
getResult
().
getOutput
();
StringBuilder
sb
=
new
StringBuilder
();
if
(
reasoningStarted
.
compareAndSet
(
false
,
true
))
{
sb
.
append
(
"<think>"
);
}
// 推理阶段:第一次出现推理内容时输出 <think>
if
(
StringUtils
.
isNotBlank
(
msg
.
getReasoningContent
()))
{
if
(
reasoningStarted
.
compareAndSet
(
false
,
true
))
{
sb
.
append
(
"<think>"
);
}
sb
.
append
(
msg
.
getReasoningContent
());
}
...
...
ask-data-ai/ask-data-ai-boot/src/main/resources/application.yml
View file @
ad68abba
...
...
@@ -37,7 +37,7 @@ spring:
api-key
:
sk-ae96ff281ff644c992843c64a711a950
chat
:
options
:
model
:
deepseek-r1
model
:
qwen-plus
embedding
:
base-url
:
https://dashscope.aliyuncs.com/compatible-mode
api-key
:
sk-ae96ff281ff644c992843c64a711a950
...
...
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