Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
a7de2561
Commit
a7de2561
authored
Nov 11, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: function call 角色匹配
parent
66ac59c1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+11
-3
LLMRoleEnum.java
.../thirdparty/resource/demand/ai/constants/LLMRoleEnum.java
+2
-0
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
a7de2561
...
@@ -626,6 +626,13 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -626,6 +626,13 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
throw
new
I18nMessageException
(
"exception/call.failure"
);
throw
new
I18nMessageException
(
"exception/call.failure"
);
}
}
if
(
StringUtils
.
isBlank
(
result
.
getMessage
())
&&
StringUtils
.
isBlank
(
result
.
getFunction
().
getName
())
&&
StringUtils
.
isBlank
(
result
.
getFunction
().
getArguments
())
&&
StringUtils
.
isBlank
(
result
.
getFinish_reason
()))
{
continue
;
}
if
(!(
result
.
getFunction
()
!=
null
&&
(
StringUtils
.
isNotBlank
(
result
.
getFunction
().
getName
())
||
StringUtils
.
isNotBlank
(
result
.
getFunction
().
getArguments
())))
&&
!
isFunctionCall
)
{
if
(!(
result
.
getFunction
()
!=
null
&&
(
StringUtils
.
isNotBlank
(
result
.
getFunction
().
getName
())
||
StringUtils
.
isNotBlank
(
result
.
getFunction
().
getArguments
())))
&&
!
isFunctionCall
)
{
bufferedReader
.
reset
();
bufferedReader
.
reset
();
break
;
break
;
...
@@ -654,7 +661,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -654,7 +661,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
if
(
functionResult
!=
null
)
{
if
(
functionResult
!=
null
)
{
// 处理function - 1,获取function_call 2. 调用对应function 3. 返回function_call并且调用LLM 4.获取bufferedReader 返回
// 处理function - 1,获取function_call 2. 调用对应function 3. 返回function_call并且调用LLM 4.获取bufferedReader 返回
Message
[]
sendMessage
=
buildFunctionMessage
(
messageArray
,
functionName
.
toString
(),
functionArguments
.
toString
(),
functionResult
);
String
functionRole
=
largeModelResponse
.
getModel
().
startsWith
(
"qwen"
)
?
LLMRoleEnum
.
FUNCTION
.
getRole
()
:
LLMRoleEnum
.
TOOL
.
getRole
();
Message
[]
sendMessage
=
buildFunctionMessage
(
messageArray
,
functionName
.
toString
(),
functionArguments
.
toString
(),
functionResult
,
functionRole
);
largeModelResponse
.
setMessages
(
sendMessage
);
largeModelResponse
.
setMessages
(
sendMessage
);
return
llmService
.
chatChunk
(
largeModelResponse
);
return
llmService
.
chatChunk
(
largeModelResponse
);
}
}
...
@@ -674,7 +682,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -674,7 +682,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param functionResult
* @param functionResult
* @return
* @return
*/
*/
private
Message
[]
buildFunctionMessage
(
Message
[]
messageArray
,
String
functionName
,
String
functionArguments
,
String
functionResult
)
{
private
Message
[]
buildFunctionMessage
(
Message
[]
messageArray
,
String
functionName
,
String
functionArguments
,
String
functionResult
,
String
functionRole
)
{
List
<
FunctionCall
>
functionCalls
=
new
ArrayList
<>();
List
<
FunctionCall
>
functionCalls
=
new
ArrayList
<>();
FunctionCall
functionCall
=
new
FunctionCall
();
FunctionCall
functionCall
=
new
FunctionCall
();
...
@@ -688,7 +696,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -688,7 +696,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
assistantMessage
.
setFunction_call
(
functionCalls
);
assistantMessage
.
setFunction_call
(
functionCalls
);
Message
functionMessage
=
new
Message
();
Message
functionMessage
=
new
Message
();
functionMessage
.
setRole
(
LLMRoleEnum
.
FUNCTION
.
getRole
()
);
functionMessage
.
setRole
(
functionRole
);
functionMessage
.
setName
(
functionName
);
functionMessage
.
setName
(
functionName
);
functionMessage
.
setContent
(
functionResult
);
functionMessage
.
setContent
(
functionResult
);
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/constants/LLMRoleEnum.java
View file @
a7de2561
...
@@ -13,6 +13,8 @@ public enum LLMRoleEnum {
...
@@ -13,6 +13,8 @@ public enum LLMRoleEnum {
FUNCTION
(
"function"
),
FUNCTION
(
"function"
),
TOOL
(
"tool"
),
;
;
private
String
role
;
private
String
role
;
...
...
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