Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
21151fb8
提交
21151fb8
authored
3月 21, 2025
作者:
925993793@qq.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【fix】自定义专题创建时,关键词推荐功能换用LLM:glm-4-flash
上级
a6a40fad
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
83 行增加
和
5 行删除
+83
-5
SubjectManageController.java
...va/com/zzsn/event/controller/SubjectManageController.java
+13
-5
LLMUtil.java
src/main/java/com/zzsn/event/util/LLMUtil.java
+70
-0
没有找到文件。
src/main/java/com/zzsn/event/controller/SubjectManageController.java
浏览文件 @
21151fb8
...
@@ -253,7 +253,15 @@ public class SubjectManageController {
...
@@ -253,7 +253,15 @@ public class SubjectManageController {
jsonObject
.
put
(
"article"
,
statisticsKeyWordVos
);
jsonObject
.
put
(
"article"
,
statisticsKeyWordVos
);
}
}
if
(
StringUtils
.
isNotBlank
(
words
))
{
if
(
StringUtils
.
isNotBlank
(
words
))
{
List
<
StatisticsKeyWordVo
>
statisticsKeyWordVos
=
extractWords
(
words
);
//List<StatisticsKeyWordVo> statisticsKeyWordVos = extractWords(words);
List
<
StatisticsKeyWordVo
>
statisticsKeyWordVos
=
new
ArrayList
<>();
List
<
String
>
list
=
LLMUtil
.
wordRecommend
(
words
);
for
(
String
s
:
list
)
{
StatisticsKeyWordVo
statisticsKeyWordVo
=
new
StatisticsKeyWordVo
();
statisticsKeyWordVo
.
setName
(
s
);
statisticsKeyWordVo
.
setValue
(
0
);
statisticsKeyWordVos
.
add
(
statisticsKeyWordVo
);
}
jsonObject
.
put
(
"word"
,
statisticsKeyWordVos
);
jsonObject
.
put
(
"word"
,
statisticsKeyWordVos
);
}
}
return
Result
.
OK
(
jsonObject
);
return
Result
.
OK
(
jsonObject
);
...
@@ -1262,9 +1270,9 @@ public class SubjectManageController {
...
@@ -1262,9 +1270,9 @@ public class SubjectManageController {
for
(
SpecialInformation
information
:
records
)
{
for
(
SpecialInformation
information
:
records
)
{
text
.
append
(
information
.
getTitle
()).
append
(
information
.
getContent
());
text
.
append
(
information
.
getTitle
()).
append
(
information
.
getContent
());
}
}
List
<
String
>
wordsList
=
pythonUtil
.
extractKeyword
(
text
.
toString
(),
10
);
//
List<String> wordsList = pythonUtil.extractKeyword(text.toString(), 10);
wordList
=
formatWordInfo
(
text
.
toString
(),
wordsList
);
//
wordList = formatWordInfo(text.toString(), wordsList);
/*
List<Map.Entry<String, Integer>> extractKeyWordsByText = HanlpUtil.extractKeyWordsByText(text.toString(), 10);
List
<
Map
.
Entry
<
String
,
Integer
>>
extractKeyWordsByText
=
HanlpUtil
.
extractKeyWordsByText
(
text
.
toString
(),
10
);
if
(
CollectionUtils
.
isNotEmpty
(
extractKeyWordsByText
))
{
if
(
CollectionUtils
.
isNotEmpty
(
extractKeyWordsByText
))
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
extractKeyWordsByText
)
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
extractKeyWordsByText
)
{
StatisticsKeyWordVo
statisticsKeyWordVo
=
new
StatisticsKeyWordVo
();
StatisticsKeyWordVo
statisticsKeyWordVo
=
new
StatisticsKeyWordVo
();
...
@@ -1272,7 +1280,7 @@ public class SubjectManageController {
...
@@ -1272,7 +1280,7 @@ public class SubjectManageController {
statisticsKeyWordVo
.
setValue
(
entry
.
getValue
());
statisticsKeyWordVo
.
setValue
(
entry
.
getValue
());
wordList
.
add
(
statisticsKeyWordVo
);
wordList
.
add
(
statisticsKeyWordVo
);
}
}
}
*/
}
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/main/java/com/zzsn/event/util/LLMUtil.java
0 → 100644
浏览文件 @
21151fb8
package
com
.
zzsn
.
event
.
util
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONArray
;
import
com.alibaba.fastjson2.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* dify大模型接口调用
*
* @author lkg
* @date 2025/3/21
*/
@Slf4j
public
class
LLMUtil
{
final
static
String
ChatGlm4_URL
=
"https://open.bigmodel.cn/api/paas/v4/chat/completions"
;
final
static
String
API_KEY
=
"2eb40c7bb8e4d22b389cd9ada5a8d6cc.bAbE6g6y71TeC0on"
;
/**
* LLM-推荐关键词
*
* @param keyword 关键词
* @author lkg
* @date 2025/3/21
*/
public
static
List
<
String
>
wordRecommend
(
String
keyword
)
{
List
<
String
>
list
=
new
ArrayList
<>();
JSONObject
params
=
new
JSONObject
();
List
<
JSONObject
>
messages
=
new
ArrayList
<>();
JSONObject
message
=
new
JSONObject
();
String
query
=
String
.
format
(
"请推荐[%s]相关的10个近义词且只要结果"
,
keyword
);
message
.
put
(
"content"
,
query
);
message
.
put
(
"role"
,
"user"
);
messages
.
add
(
message
);
params
.
put
(
"messages"
,
messages
);
params
.
put
(
"model"
,
"glm-4-flash"
);
JSONObject
responseFormat
=
new
JSONObject
();
responseFormat
.
put
(
"type"
,
"json_object"
);
params
.
put
(
"response_format"
,
responseFormat
);
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Content-Type"
,
"application/json"
);
headers
.
put
(
"Authorization"
,
"Bearer "
+
API_KEY
);
String
response
=
null
;
try
{
response
=
HttpUtil
.
doPostWithHeader
(
ChatGlm4_URL
,
params
,
30000
,
headers
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
JSONArray
choices
=
jsonObject
.
getJSONArray
(
"choices"
);
JSONObject
choice
=
choices
.
getJSONObject
(
0
);
JSONObject
content
=
choice
.
getJSONObject
(
"message"
).
getJSONObject
(
"content"
);
JSONArray
answer
=
content
.
getJSONArray
(
"answer"
);
list
=
answer
.
toJavaList
(
String
.
class
);
}
catch
(
Exception
e
)
{
log
.
info
(
"大模型-{},调用异常:{}"
,
"glm-4-flash"
,
e
.
getMessage
());
log
.
info
(
"返回结果:{}"
,
response
);
}
return
list
;
}
public
static
void
main
(
String
[]
args
)
{
List
<
String
>
list
=
wordRecommend
(
"人工智能|汽车"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
list
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论