File tree Expand file tree Collapse file tree 4 files changed +78
-2
lines changed
volcengine-java-sdk-llmshield/src/main/java/com/volcengine/llmshield Expand file tree Collapse file tree 4 files changed +78
-2
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,19 @@ public void Close() throws IOException {
9898 }
9999 }
100100
101+ /**
102+ * 设置环境
103+ * @param IsDev 是否为dev环境
104+ * @return 无
105+ */
106+ public void SetServiceCode (boolean IsDev ) {
107+ Sign .setServiceCode (IsDev );
108+ }
109+
110+ public String GetServiceCode () {
111+ return Sign .getServiceCode ();
112+ }
113+
101114 /**
102115 * 多模态、多轮对话审核
103116 *
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .annotation .JsonProperty ;
44
5+ import java .util .ArrayList ;
6+ import java .util .List ;
7+
58// 消息结构
69public class MessageV2 {
710 @ JsonProperty ("Role" )
@@ -13,13 +16,23 @@ public class MessageV2 {
1316 @ JsonProperty ("ContentType" )
1417 private ContentTypeV2 contentType ; // 内容类型
1518
19+ @ JsonProperty ("MultiPart" )
20+ private List <MultiPart > multiPart ; // 多模态内容
21+
1622 // 深拷贝构造方法
1723 public MessageV2 (MessageV2 other ) {
1824 // String是不可变类型,直接赋值即可
1925 this .role = other .role ;
2026 this .content = other .content ;
21-
2227 this .contentType = other .contentType ;
28+
29+ // List<multiPart>:新建List并对每个元素深拷贝
30+ if (other .multiPart != null ) {
31+ this .multiPart = new ArrayList <>();
32+ for (MultiPart contPart : other .multiPart ) {
33+ this .multiPart .add (new MultiPart (contPart )); // 假设MultiPart有深拷贝构造方法
34+ }
35+ }
2336 }
2437
2538 // 无参构造方法(保留,用于JSON反序列化等场景)
@@ -48,4 +61,8 @@ public ContentTypeV2 getContentType() {
4861 public void setContentType (ContentTypeV2 contentType ) {
4962 this .contentType = contentType ;
5063 }
64+
65+ public List <MultiPart > getMultiPart () { return multiPart ; }
66+
67+ public void setMultiPart (List <MultiPart > multiPart ) { this .multiPart = multiPart ; }
5168}
Original file line number Diff line number Diff line change 1+ package com .volcengine .llmshield ;
2+
3+ import com .fasterxml .jackson .annotation .JsonProperty ;
4+
5+ public class MultiPart {
6+ @ JsonProperty ("Content" )
7+ private String content ; // 内容文本或链接
8+
9+ @ JsonProperty ("ContentType" )
10+ private ContentTypeV2 contentType ; // 内容类型
11+
12+ // 深拷贝构造方法
13+ public MultiPart (MultiPart other ) {
14+ // String是不可变类型,直接赋值即可
15+ this .content = other .content ;
16+ this .contentType = other .contentType ;
17+ }
18+
19+ public String getContent () { return content ; }
20+
21+ public void setContent (String content ) { this .content = content ; }
22+
23+ public ContentTypeV2 getContentType () { return contentType ; }
24+
25+ public void setContentType (ContentTypeV2 contentType ) { this .contentType = contentType ; }
26+ }
Original file line number Diff line number Diff line change 3434 */
3535public class Sign {
3636 // 常量定义
37+ private static final String SERVICE_CODE_DEV = "llmshield_dev" ;
38+ private static final String SERVICE_CODE_ONLINE = "llmshield" ;
39+
3740 private static final String VERSION = "2025-08-31" ;
38- private static final String SERVICE = "llmshield" ;
3941 private static final BitSet URLENCODER = new BitSet (256 );
4042 private static final String CONST_ENCODE = "0123456789ABCDEF" ;
4143 public static final Charset UTF_8 = StandardCharsets .UTF_8 ;
4244 // 默认 Content-Type(可根据实际需求调整,若请求体为 JSON 可改为 application/json)
4345 private static final String DEFAULT_CONTENT_TYPE = "application/json" ;
4446
47+ private static boolean isModified = false ; //记录是否已修改过
48+ private static String SERVICE = SERVICE_CODE_ONLINE ;
49+
4550 // 静态初始化 URL 编码允许的字符(复用原逻辑)
4651 static {
4752 int i ;
@@ -62,6 +67,21 @@ public class Sign {
6267 URLENCODER .set ('~' );
6368 }
6469
70+ public static synchronized void setServiceCode (boolean IsDev ) {
71+ if (!isModified ) {
72+ if (IsDev ) {
73+ SERVICE = SERVICE_CODE_DEV ;
74+ } else {
75+ SERVICE = SERVICE_CODE_ONLINE ;
76+ }
77+ isModified = true ;
78+ }
79+ }
80+
81+ public static String getServiceCode () {
82+ return SERVICE ;
83+ }
84+
6585 /**
6686 * 核心加签方法:为 HttpPost 请求添加火山引擎 API 签名
6787 *
You can’t perform that action at this time.
0 commit comments