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
c4b4ee9b
Commit
c4b4ee9b
authored
May 14, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:优化agent调用流程
parent
964a0b97
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
141 deletions
+127
-141
AgentApplicationServiceImpl.java
...plication/aggregate/impl/AgentApplicationServiceImpl.java
+52
-112
RequestData.java
...rce/demand/ai/function/extraction/entity/RequestData.java
+2
-0
PdfToMDFunction.java
...ce/demand/ai/function/text_in_pdf2md/PdfToMDFunction.java
+1
-2
TextInClient.java
...e/demand/ai/function/text_in_pdf2md/api/TextInClient.java
+69
-23
PdfToMdFunctionTest.java
...arty/resource/demand/ai/function/PdfToMdFunctionTest.java
+3
-4
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationServiceImpl.java
View file @
c4b4ee9b
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/extraction/entity/RequestData.java
View file @
c4b4ee9b
...
...
@@ -5,6 +5,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity;
* @date 2025/5/12
*/
public
class
RequestData
{
public
Integer
token_mode
;
public
String
creator
;
public
Config
config
;
public
String
filedata
;
...
...
@@ -12,6 +13,7 @@ public class RequestData {
public
KeyInfo
[]
key_info_list
;
public
RequestData
(
String
creator
,
Config
config
,
String
filedata
,
String
filename
,
KeyInfo
[]
key_info_list
)
{
token_mode
=
1
;
this
.
creator
=
creator
;
this
.
config
=
config
;
this
.
filedata
=
filedata
;
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/text_in_pdf2md/PdfToMDFunction.java
View file @
c4b4ee9b
...
...
@@ -63,9 +63,8 @@ public class PdfToMDFunction extends AbstractLargeModelFunction {
options
.
put
(
"paratext_mode"
,
"annotation"
);
options
.
put
(
"parse_mode"
,
"auto"
);
options
.
put
(
"table_flavor"
,
"md"
);
TextInClient
client
=
new
TextInClient
();
try
{
String
response
=
c
lient
.
recognize
(
fileContent
,
options
);
String
response
=
TextInC
lient
.
recognize
(
fileContent
,
options
);
ObjectMapper
mapper
=
new
ObjectMapper
();
JsonNode
jsonNode
=
mapper
.
readTree
(
response
);
if
(
jsonNode
.
has
(
"result"
)
&&
jsonNode
.
get
(
"result"
).
has
(
"markdown"
))
{
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/text_in_pdf2md/api/TextInClient.java
View file @
c4b4ee9b
...
...
@@ -6,12 +6,16 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api;
*/
import
cn.com.poc.common.utils.DocumentLoad
;
import
cn.com.poc.common.utils.http.LocalHttpClient
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.Config
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.KeyInfo
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.RequestData
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.jetbrains.annotations.NotNull
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.apache.http.client.methods.RequestBuilder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -21,8 +25,6 @@ import java.net.URL;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Base64
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -30,14 +32,20 @@ import java.util.Map;
public
class
TextInClient
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TextInClient
.
class
);
private
final
String
appId
=
"a595e68578ff9a853c3d60a879157547"
;
private
final
String
secretCode
=
"d723d69522c92ff59a3e48b37ac3df79"
;
final
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TextInClient
.
class
);
final
private
static
String
appId
=
"a595e68578ff9a853c3d60a879157547"
;
final
private
static
String
secretCode
=
"d723d69522c92ff59a3e48b37ac3df79"
;
public
TextInClient
()
{
}
public
String
recognize
(
byte
[]
fileContent
,
HashMap
<
String
,
Object
>
options
)
throws
IOException
{
/**
* @param fileContent
* @param options
* @return
* @throws IOException
*/
public
static
String
recognize
(
byte
[]
fileContent
,
HashMap
<
String
,
Object
>
options
)
throws
IOException
{
StringBuilder
queryParams
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
options
.
entrySet
())
{
if
(
queryParams
.
length
()
>
0
)
{
...
...
@@ -70,7 +78,31 @@ public class TextInClient {
}
}
public
String
extraction
(
String
fileUrl
,
List
<
KeyInfo
>
keyInfoList
)
{
private
static
HttpURLConnection
getRecoGinzeHttpURLConnection
(
StringBuilder
queryParams
)
throws
IOException
{
String
baseUrl
=
"https://api.textin.com/ai/service/v1/pdf_to_markdown"
;
String
fullUrl
=
baseUrl
+
(
queryParams
.
length
()
>
0
?
"?"
+
queryParams
:
""
);
URL
url
=
new
URL
(
fullUrl
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"POST"
);
connection
.
setRequestProperty
(
"x-ti-app-id"
,
appId
);
connection
.
setRequestProperty
(
"x-ti-secret-code"
,
secretCode
);
connection
.
setRequestProperty
(
"Content-Type"
,
"text/plain;charset=utf-8"
);
connection
.
setDoOutput
(
true
);
return
connection
;
}
/**
* 【合同抽取】-创建抽取
* https://www.textin.com/document/doc_extraction_create
*
* @param fileUrl
* @param keyInfoList
* @return
*/
public
static
String
extraction
(
String
fileUrl
,
List
<
KeyInfo
>
keyInfoList
)
{
try
{
// 读取文件并将其转换为Base64编码
File
file
=
DocumentLoad
.
downloadURLDocument
(
fileUrl
);
...
...
@@ -96,7 +128,7 @@ public class TextInClient {
connection
.
setRequestMethod
(
"POST"
);
connection
.
setRequestProperty
(
"x-ti-app-id"
,
appId
);
connection
.
setRequestProperty
(
"x-ti-secret-code"
,
secretCode
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json
;charset=utf-8
"
);
connection
.
setDoOutput
(
true
);
// 开启输出流
// 发送请求数据
...
...
@@ -117,26 +149,40 @@ public class TextInClient {
response
.
append
(
inputLine
);
}
// 输出响应内容
return
response
.
toString
();
logger
.
info
(
"Response: {}"
,
response
);
JSONObject
jsonResponse
=
JSONObject
.
parseObject
(
response
.
toString
());
String
taskId
=
jsonResponse
.
getJSONObject
(
"result"
).
getString
(
"task_id"
);
return
extractedResults
(
taskId
);
}
}
catch
(
IOException
e
)
{
throw
new
BusinessException
(
e
);
}
}
private
HttpURLConnection
getRecoGinzeHttpURLConnection
(
StringBuilder
queryParams
)
throws
IOException
{
String
baseUrl
=
"https://api.textin.com/ai/service/v1/pdf_to_markdown"
;
String
fullUrl
=
baseUrl
+
(
queryParams
.
length
()
>
0
?
"?"
+
queryParams
:
""
);
URL
url
=
new
URL
(
fullUrl
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"POST"
);
connection
.
setRequestProperty
(
"x-ti-app-id"
,
appId
);
connection
.
setRequestProperty
(
"x-ti-secret-code"
,
secretCode
);
connection
.
setRequestProperty
(
"Content-Type"
,
"text/plain;charset=utf-8"
);
connection
.
setDoOutput
(
true
);
return
connection
;
/**
* 【合同抽取】 -获取抽取结果
* https://www.textin.com/document/doc_extraction_result
*
* @param taskId
* @return
*/
private
static
String
extractedResults
(
String
taskId
)
{
String
baseUrl
=
"https://doc-compare.intsig.com/doc_extraction/keyinfo/extracted_results?format=json&task_id="
+
taskId
;
HttpUriRequest
httpUriRequest
=
RequestBuilder
.
post
()
.
setUri
(
baseUrl
)
.
addHeader
(
"x-ti-app-id"
,
appId
)
.
addHeader
(
"x-ti-secret-code"
,
secretCode
)
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
)
.
build
();
String
result
=
LocalHttpClient
.
executeJsonResult
(
httpUriRequest
,
String
.
class
);
JSONObject
resultJson
=
JSONObject
.
parseObject
(
result
);
Integer
code
=
resultJson
.
getInteger
(
"code"
);
if
(
code
.
equals
(
200
))
{
return
resultJson
.
getJSONObject
(
"result"
).
toJSONString
();
}
else
{
logger
.
error
(
"获取token失败,错误码:{}"
,
code
);
return
StringUtils
.
EMPTY
;
}
}
}
\ No newline at end of file
src/test/java/cn/com/poc/thirdparty/resource/demand/ai/function/PdfToMdFunctionTest.java
View file @
c4b4ee9b
...
...
@@ -43,19 +43,18 @@ public class PdfToMdFunctionTest {
options
.
put
(
"paratext_mode"
,
"annotation"
);
options
.
put
(
"parse_mode"
,
"auto"
);
options
.
put
(
"table_flavor"
,
"md"
);
TextInClient
client
=
new
TextInClient
();
try
{
String
response
=
c
lient
.
recognize
(
fileContent
,
options
);
String
response
=
TextInC
lient
.
recognize
(
fileContent
,
options
);
ObjectMapper
mapper
=
new
ObjectMapper
();
JsonNode
jsonNode
=
mapper
.
readTree
(
response
);
if
(
jsonNode
.
has
(
"result"
)
&&
jsonNode
.
get
(
"result"
).
has
(
"markdown"
))
{
String
markdown
=
jsonNode
.
get
(
"result"
).
get
(
"markdown"
).
asText
();
System
.
out
.
println
(
markdown
);
}
else
{
}
else
{
System
.
out
.
println
(
response
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"1111111"
);
e
.
printStackTrace
(
);
}
}
...
...
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