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
bfc5ed6c
Commit
bfc5ed6c
authored
Jan 14, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:Agent应用插件功能
parent
e24d793b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
10 deletions
+81
-10
DocumentLoad.java
src/main/java/cn/com/poc/common/utils/DocumentLoad.java
+1
-1
ImageOCRFunction.java
...source/demand/ai/function/image_ocr/ImageOCRFunction.java
+52
-0
WebSearchFunction.java
...ource/demand/ai/function/web_seach/WebSearchFunction.java
+15
-4
config-dev.properties
src/main/resources/framemax-config/config-dev.properties
+3
-1
config-prod.properties
src/main/resources/framemax-config/config-prod.properties
+3
-1
config-sit.properties
src/main/resources/framemax-config/config-sit.properties
+3
-1
config-uat.properties
src/main/resources/framemax-config/config-uat.properties
+3
-1
GoogleSearchFunctionTest.java
...resource/demand/ai/function/GoogleSearchFunctionTest.java
+1
-1
No files found.
src/main/java/cn/com/poc/common/utils/DocumentLoad.java
View file @
bfc5ed6c
...
...
@@ -48,7 +48,7 @@ public class DocumentLoad {
// 关闭资源
inputStream
.
close
();
isr
.
close
();
String
htmlStr
=
sb
.
toString
();
String
htmlStr
=
sb
.
toString
()
.
replaceAll
(
"<head>.*?</head>"
,
""
)
;
return
converter
.
convert
(
htmlStr
);
}
catch
(
IOException
e
)
{
return
""
;
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/image_ocr/ImageOCRFunction.java
0 → 100644
View file @
bfc5ed6c
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
image_ocr
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.common.utils.JsonUtils
;
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.hutool.core.collection.ListUtil
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* @author alex.yao
* @date 2025/1/14
*/
@Component
public
class
ImageOCRFunction
extends
AbstractLargeModelFunction
{
private
final
String
DESC
=
"该方法是通过OCR获取图片内容,并且根据用户提问对图片内容进行提取总结与分析。"
;
private
final
FunctionLLMConfig
functionLLMConfig
=
new
FunctionLLMConfig
.
FunctionLLMConfigBuilder
()
.
name
(
"image_ocr"
)
.
description
(
DESC
)
.
parameters
(
new
Parameters
(
"object"
)
.
addProperties
(
"query"
,
new
Properties
(
"string"
,
"用户提问问题"
))
.
addProperties
(
"image_url"
,
new
Properties
(
"string"
,
"图片地址"
)))
.
build
();
@Override
public
String
doFunction
(
String
content
,
String
identifier
)
{
//todo 对接豆包多模态大模型
return
null
;
}
@Override
public
String
getDesc
()
{
return
getDesc
();
}
@Override
public
List
<
String
>
getLLMConfig
()
{
return
ListUtil
.
toList
(
JsonUtils
.
serialize
(
functionLLMConfig
));
}
@Override
public
List
<
String
>
getLLMConfig
(
List
<
Variable
>
variableStructure
)
{
return
this
.
getLLMConfig
();
}
}
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/web_seach/WebSearchFunction.java
View file @
bfc5ed6c
...
...
@@ -8,9 +8,11 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunct
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.yict.framemax.core.config.Config
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.hutool.core.collection.ListUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baidubce.services.bec.model.vm.NetworkConfig
;
import
com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
;
import
com.google.api.client.http.HttpTransport
;
import
com.google.api.client.http.apache.v2.ApacheHttpTransport
;
...
...
@@ -20,6 +22,8 @@ import com.google.api.services.customsearch.v1.CustomSearchAPI;
import
com.google.api.services.customsearch.v1.CustomSearchAPIRequestInitializer
;
import
com.google.api.services.customsearch.v1.model.Result
;
import
com.google.api.services.customsearch.v1.model.Search
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
...
...
@@ -32,10 +36,15 @@ import java.util.List;
@Component
public
class
WebSearchFunction
extends
AbstractLargeModelFunction
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
WebSearchFunction
.
class
);
private
final
HttpTransport
transport
=
new
ApacheHttpTransport
();
private
final
JsonFactory
jsonFactory
=
new
GsonFactory
();
private
final
String
KEY
=
Config
.
get
(
"google.custom.search.key"
);
private
final
String
CX
=
Config
.
get
(
"google.custom.search.cx"
);
private
final
String
DESC
=
"该方法是通过Bing所有对用户给出的关键词进行网站、网页搜索检索获取网页内容"
;
private
final
FunctionLLMConfig
functionLLMConfig
=
new
FunctionLLMConfig
.
FunctionLLMConfigBuilder
()
...
...
@@ -52,7 +61,6 @@ public class WebSearchFunction extends AbstractLargeModelFunction {
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
content
);
String
query
=
jsonObject
.
getString
(
"query"
);
List
<
WebSearchFunctionResult
>
results
=
new
ArrayList
<>();
try
{
CustomSearchAPI
customSearchAPI
=
new
CustomSearchAPI
.
Builder
(
transport
,
jsonFactory
,
GoogleNetHttpTransport
.
newTrustedTransport
().
createRequestFactory
().
getInitializer
())
...
...
@@ -60,10 +68,9 @@ public class WebSearchFunction extends AbstractLargeModelFunction {
.
setCustomSearchAPIRequestInitializer
(
new
CustomSearchAPIRequestInitializer
(
"AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw"
))
.
build
();
Search
execute
=
customSearchAPI
.
cse
().
list
().
setCx
(
"049026ecb26e840ed"
)
.
setKey
(
"AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw"
)
.
cse
().
list
().
setCx
(
CX
)
.
setKey
(
KEY
)
.
setQ
(
query
)
.
setStart
(
1L
)
.
setNum
(
3
)
.
execute
();
List
<
Result
>
items
=
execute
.
getItems
();
...
...
@@ -72,6 +79,9 @@ public class WebSearchFunction extends AbstractLargeModelFunction {
String
htmlContent
=
DocumentLoad
.
htmlToMarkdown
(
link
);
if
(
StringUtils
.
isNotBlank
(
htmlContent
))
{
htmlContent
=
htmlContent
.
replaceAll
(
StringUtils
.
SPACE
,
StringUtils
.
EMPTY
);
if
(
htmlContent
.
length
()
>
10000
)
{
htmlContent
=
htmlContent
.
substring
(
0
,
10000
);
}
}
String
title
=
item
.
getTitle
();
String
snippet
=
item
.
getSnippet
();
...
...
@@ -84,6 +94,7 @@ public class WebSearchFunction extends AbstractLargeModelFunction {
}
return
JsonUtils
.
serialize
(
results
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"web search error:"
+
e
.
getMessage
());
return
JsonUtils
.
serialize
(
results
);
}
}
...
...
src/main/resources/framemax-config/config-dev.properties
View file @
bfc5ed6c
...
...
@@ -26,4 +26,6 @@ large-model.apikey=sk-bNzgFwFtw3k4jR7CE3575a19C3304a53Bb803cCeDeC154F2
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://poc-sit.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
google.custom.search.key
=
AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw
google.custom.search.cx
=
049026ecb26e840ed
\ No newline at end of file
src/main/resources/framemax-config/config-prod.properties
View file @
bfc5ed6c
...
...
@@ -26,4 +26,6 @@ large-model.apikey=sk-gQM7bpiRxaOl2emt0cBbF47481C5403885263eFeB95c7a8e
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://model-link.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
google.custom.search.key
=
AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw
google.custom.search.cx
=
049026ecb26e840ed
\ No newline at end of file
src/main/resources/framemax-config/config-sit.properties
View file @
bfc5ed6c
...
...
@@ -26,4 +26,6 @@ large-model.apikey=sk-bNzgFwFtw3k4jR7CE3575a19C3304a53Bb803cCeDeC154F2
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://poc-sit.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
google.custom.search.key
=
AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw
google.custom.search.cx
=
049026ecb26e840ed
\ No newline at end of file
src/main/resources/framemax-config/config-uat.properties
View file @
bfc5ed6c
...
...
@@ -26,4 +26,6 @@ large-model.apikey=sk-gQM7bpiRxaOl2emt0cBbF47481C5403885263eFeB95c7a8e
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://model-link.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
google.custom.search.key
=
AIzaSyCV8PTQ10rG5wo4E004dR3mcGD1RM_PrBw
google.custom.search.cx
=
049026ecb26e840ed
\ No newline at end of file
src/test/java/cn/com/poc/thirdparty/resource/demand/ai/function/GoogleSearchFunctionTest.java
View file @
bfc5ed6c
...
...
@@ -22,6 +22,6 @@ public class GoogleSearchFunctionTest {
@Test
public
void
testSearch
()
throws
IOException
,
GeneralSecurityException
{
WebSearchFunction
webSearchFunction
=
new
WebSearchFunction
();
System
.
out
.
println
(
webSearchFunction
.
doFunction
(
"{\"query\":\"
什么是区块链
\"}"
,
"1"
));
System
.
out
.
println
(
webSearchFunction
.
doFunction
(
"{\"query\":\"
今日广州天气
\"}"
,
"1"
));
}
}
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