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
a52d8ff3
Commit
a52d8ff3
authored
Nov 28, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Agent应用-文档解析更换为文档理解function
parent
f6c732b9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
2 deletions
+149
-2
AgentApplicationTools.java
...om/poc/agent_application/utils/AgentApplicationTools.java
+2
-2
LargeModelFunctionEnum.java
...y/resource/demand/ai/function/LargeModelFunctionEnum.java
+4
-0
DocumentUnderstandIngFunction.java
...document_understanding/DocumentUnderstandIngFunction.java
+93
-0
DocumentUnderstandingFunctionTest.java
...demand/ai/function/DocumentUnderstandingFunctionTest.java
+50
-0
No files found.
src/main/java/cn/com/poc/agent_application/utils/AgentApplicationTools.java
View file @
a52d8ff3
...
@@ -60,9 +60,9 @@ public class AgentApplicationTools {
...
@@ -60,9 +60,9 @@ public class AgentApplicationTools {
tools
.
add
(
tool
);
tools
.
add
(
tool
);
}
}
//开启文档解析
//开启文档解析
-文档理解
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
isDocumentParsing
))
{
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
isDocumentParsing
))
{
String
functionName
=
LargeModelFunctionEnum
.
document_
reader
.
name
();
String
functionName
=
LargeModelFunctionEnum
.
document_
understanding
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getLLMConfig
().
get
(
0
);
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getLLMConfig
().
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
tools
.
add
(
tool
);
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/LargeModelFunctionEnum.java
View file @
a52d8ff3
...
@@ -2,6 +2,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function;
...
@@ -2,6 +2,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function;
import
cn.com.poc.common.utils.SpringUtils
;
import
cn.com.poc.common.utils.SpringUtils
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_reader.DocumentReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_reader.DocumentReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_understanding.DocumentUnderstandIngFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.html_reader.HtmlReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.html_reader.HtmlReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.SetLongMemoryFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.SetLongMemoryFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriterFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriterFunction
;
...
@@ -11,9 +12,12 @@ public enum LargeModelFunctionEnum {
...
@@ -11,9 +12,12 @@ public enum LargeModelFunctionEnum {
memory_variable_writer
(
MemoryVariableWriterFunction
.
class
),
memory_variable_writer
(
MemoryVariableWriterFunction
.
class
),
html_reader
(
HtmlReaderFunction
.
class
),
html_reader
(
HtmlReaderFunction
.
class
),
document_reader
(
DocumentReaderFunction
.
class
),
document_reader
(
DocumentReaderFunction
.
class
),
document_understanding
(
DocumentUnderstandIngFunction
.
class
),
bing_web_search
(
null
),
bing_web_search
(
null
),
;
;
private
Class
<?
extends
AbstractLargeModelFunction
>
function
;
private
Class
<?
extends
AbstractLargeModelFunction
>
function
;
LargeModelFunctionEnum
(
Class
<?
extends
AbstractLargeModelFunction
>
function
)
{
LargeModelFunctionEnum
(
Class
<?
extends
AbstractLargeModelFunction
>
function
)
{
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/document_understanding/DocumentUnderstandIngFunction.java
0 → 100644
View file @
a52d8ff3
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
document_understanding
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.common.utils.DocumentLoad
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Message
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.FunctionLLMConfig
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.Parameters
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.Properties
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.hutool.core.collection.ListUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.util.List
;
@Component
public
class
DocumentUnderstandIngFunction
extends
AbstractLargeModelFunction
{
@Resource
private
LLMService
llmService
;
private
final
String
MODEL
=
"Doubao-pro-128k"
;
private
final
String
TEMPLATE
=
"## 任务\n"
+
"你的任务是根据用户提出的问题,并且对于当前长文档内容理解,支持信息检索、摘要总结、文本分析能力。提取或者总结文档中与内容相关的内容。\n"
+
"\n"
+
"## 文档内容\n"
+
"${document_content}"
+
"\n"
+
"## 用户问题\n"
+
"${question}"
;
private
final
String
DESC
=
"长文档内容理解,支持信息检索、摘要总结、文本分析能力。"
;
private
final
FunctionLLMConfig
functionLLMConfig
=
new
FunctionLLMConfig
.
FunctionLLMConfigBuilder
()
.
name
(
"document_understanding"
)
.
description
(
DESC
)
.
parameters
(
new
Parameters
(
"object"
)
.
addProperties
(
"question"
,
new
Properties
(
"string"
,
"提炼用户的问题"
))
.
addProperties
(
"file_url"
,
new
Properties
(
"string"
,
"doc、docx、pdf、txt、md文件地址"
))
).
build
();
@Override
public
String
doFunction
(
String
content
,
String
identifier
)
{
if
(
StringUtils
.
isBlank
(
content
))
{
return
StringUtils
.
EMPTY
;
}
JSONObject
jsonObject
=
JSON
.
parseObject
(
content
);
String
question
=
jsonObject
.
getString
(
"question"
);
String
fileUrl
=
jsonObject
.
getString
(
"file_url"
);
File
file
=
DocumentLoad
.
downloadURLDocument
(
fileUrl
);
String
documentContent
=
DocumentLoad
.
documentToText
(
file
);
Message
message
=
new
Message
();
message
.
setRole
(
"user"
);
message
.
setContent
(
TEMPLATE
.
replace
(
"${document_content}"
,
documentContent
).
replace
(
"${question}"
,
question
));
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
MODEL
);
largeModelResponse
.
setMessages
(
new
Message
[]{
message
});
largeModelResponse
.
setStream
(
false
);
largeModelResponse
.
setUser
(
"Document_Understanding"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
return
largeModelDemandResult
.
getMessage
();
}
@Override
public
String
getDesc
()
{
return
DESC
;
}
@Override
public
List
<
String
>
getLLMConfig
()
{
return
ListUtil
.
toList
(
JsonUtils
.
serialize
(
this
.
functionLLMConfig
));
}
@Override
public
List
<
String
>
getLLMConfig
(
List
<
Variable
>
variableStructure
)
{
return
this
.
getLLMConfig
();
}
}
src/test/java/cn/com/poc/thirdparty/resource/demand/ai/function/DocumentUnderstandingFunctionTest.java
0 → 100644
View file @
a52d8ff3
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_understanding.DocumentUnderstandIngFunction
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.UUID
;
import
static
org
.
apache
.
poi
.
hslf
.
record
.
RecordTypes
.
List
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
initializers
=
SingleContextInitializer
.
class
)
@WebAppConfiguration
public
class
DocumentUnderstandingFunctionTest
{
@Resource
DocumentUnderstandIngFunction
documentUnderstandIngFunction
;
@Test
public
void
testDoFunction
()
{
String
content
=
"{\"file_url\": \"https://gsst-poe-sit.gz.bcebos.com/data/20241127/1732704249980.docx\",\"question\":\"駕駛執照上的二維碼內載有什麼資料?\"}"
;
String
identifier
=
UUID
.
randomUUID
().
toString
();
String
RESULT
=
documentUnderstandIngFunction
.
doFunction
(
content
,
identifier
);
System
.
out
.
println
(
RESULT
);
}
@Test
public
void
testGetDesc
()
{
System
.
out
.
println
(
documentUnderstandIngFunction
.
getDesc
());
}
@Test
public
void
testGetLLMConfig
()
{
System
.
out
.
println
(
documentUnderstandIngFunction
.
getLLMConfig
());
}
@Test
public
void
testGetLLMConfigToVariableStructure
()
{
List
<
Variable
>
variableStructure
=
Mockito
.
mock
(
List
.
class
);
System
.
out
.
println
(
documentUnderstandIngFunction
.
getLLMConfig
(
variableStructure
));
}
}
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