Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-module-operation
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-module-operation
Commits
3805a22e
提交
3805a22e
authored
5月 12, 2025
作者:
李秋林
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1、测试阿里云通义AI功能
上级
67d4f113
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
78 行增加
和
0 行删除
+78
-0
pom.xml
pom.xml
+17
-0
Test.java
...main/java/com/sfa/operation/controller/qwenplus/Test.java
+61
-0
没有找到文件。
pom.xml
浏览文件 @
3805a22e
...
...
@@ -90,6 +90,23 @@
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.openai/openai-java -->
<dependency>
<groupId>
com.openai
</groupId>
<artifactId>
openai-java
</artifactId>
<version>
${openai-java.version}
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
dashscope-sdk-java
</artifactId>
<version>
${dashscope-sdk-java.version}
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/sfa/operation/controller/qwenplus/Test.java
0 → 100644
浏览文件 @
3805a22e
package
com
.
sfa
.
operation
.
controller
.
qwenplus
;
import
java.util.Arrays
;
import
java.lang.System
;
import
com.alibaba.dashscope.aigc.generation.Generation
;
import
com.alibaba.dashscope.aigc.generation.GenerationParam
;
import
com.alibaba.dashscope.aigc.generation.GenerationResult
;
import
com.alibaba.dashscope.common.Message
;
import
com.alibaba.dashscope.common.Role
;
import
com.alibaba.dashscope.exception.ApiException
;
import
com.alibaba.dashscope.exception.InputRequiredException
;
import
com.alibaba.dashscope.exception.NoApiKeyException
;
import
com.alibaba.dashscope.utils.JsonUtils
;
/**
* @author : liqiulin
* @date : 2025-03-19 15
* @describe :
*/
public
class
Test
{
public
static
GenerationResult
callWithMessage
()
throws
ApiException
,
NoApiKeyException
,
InputRequiredException
{
Generation
gen
=
new
Generation
();
Message
systemMsg
=
Message
.
builder
()
.
role
(
Role
.
SYSTEM
.
getValue
())
.
content
(
"你是一个辅助员工工作的助手。"
)
.
build
();
Message
userMsg1
=
Message
.
builder
()
.
role
(
Role
.
USER
.
getValue
())
.
content
(
"你是谁?是什么角色?"
)
.
build
();
Message
userMsg2
=
Message
.
builder
()
.
role
(
Role
.
USER
.
getValue
())
.
content
(
"是什么角色?"
)
.
build
();
GenerationParam
param
=
GenerationParam
.
builder
()
.
apiKey
(
"sk-6d8476b4756648f0b740bd200234d1e6"
)
.
model
(
"qwen-plus"
)
.
messages
(
Arrays
.
asList
(
systemMsg
,
userMsg1
,
userMsg2
))
.
resultFormat
(
GenerationParam
.
ResultFormat
.
MESSAGE
)
.
build
();
return
gen
.
call
(
param
);
}
public
static
void
main
(
String
[]
args
)
{
try
{
GenerationResult
result
=
callWithMessage
();
System
.
out
.
println
(
JsonUtils
.
toJson
(
result
));
}
catch
(
ApiException
|
NoApiKeyException
|
InputRequiredException
e
)
{
// 使用日志框架记录异常信息
System
.
err
.
println
(
"An error occurred while calling the generation service: "
+
e
.
getMessage
());
}
System
.
exit
(
0
);
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论