Skip to content

Commit 43f9493

Browse files
feat(ark-runtime): add context chat api supports
1 parent ef6070b commit 43f9493

File tree

10 files changed

+650
-0
lines changed

10 files changed

+650
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.volcengine.ark.runtime.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public class PromptTokensDetails {
8+
9+
@JsonProperty("cached_tokens")
10+
private Integer cachedTokens;
11+
12+
public Integer getCachedTokens() {
13+
return cachedTokens;
14+
}
15+
16+
public void setCachedTokens(Integer cachedTokens) {
17+
this.cachedTokens = cachedTokens;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "PromptTokensDetails{" +
23+
"cachedTokens=" + cachedTokens +
24+
'}';
25+
}
26+
}

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/model/Usage.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ public class Usage {
2323
@JsonProperty("total_tokens")
2424
long totalTokens;
2525

26+
@JsonProperty("prompt_tokens_details")
27+
private PromptTokensDetails promptTokensDetails;
28+
2629
public Usage(long promptTokens, long completionTokens, long totalTokens) {
2730
this.promptTokens = promptTokens;
2831
this.completionTokens = completionTokens;
2932
this.totalTokens = totalTokens;
3033
}
3134

35+
public Usage(long promptTokens, long completionTokens, long totalTokens, PromptTokensDetails promptTokensDetails) {
36+
this.promptTokens = promptTokens;
37+
this.completionTokens = completionTokens;
38+
this.totalTokens = totalTokens;
39+
this.promptTokensDetails = promptTokensDetails;
40+
}
41+
3242
public Usage() {}
3343

3444
public long getPromptTokens() {
@@ -55,12 +65,21 @@ public void setTotalTokens(long totalTokens) {
5565
this.totalTokens = totalTokens;
5666
}
5767

68+
public PromptTokensDetails getPromptTokensDetails() {
69+
return promptTokensDetails;
70+
}
71+
72+
public void setPromptTokensDetails(PromptTokensDetails promptTokensDetails) {
73+
this.promptTokensDetails = promptTokensDetails;
74+
}
75+
5876
@Override
5977
public String toString() {
6078
return "Usage{" +
6179
"promptTokens=" + promptTokens +
6280
", completionTokens=" + completionTokens +
6381
", totalTokens=" + totalTokens +
82+
", promptTokensDetails=" + promptTokensDetails +
6483
'}';
6584
}
6685
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.volcengine.ark.runtime.model.context;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
6+
7+
import java.util.List;
8+
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class CreateContextRequest {
11+
12+
@JsonProperty("model")
13+
private String model;
14+
15+
@JsonProperty("messages")
16+
private List<ChatMessage> messages;
17+
18+
@JsonProperty("ttl")
19+
private Integer ttl;
20+
21+
@JsonProperty("truncation_strategy")
22+
private TruncationStrategy truncationStrategy;
23+
24+
public CreateContextRequest() {
25+
}
26+
27+
public CreateContextRequest(String model, List<ChatMessage> messages, Integer ttl, TruncationStrategy truncationStrategy) {
28+
this.model = model;
29+
this.messages = messages;
30+
this.ttl = ttl;
31+
this.truncationStrategy = truncationStrategy;
32+
}
33+
34+
public String getModel() {
35+
return model;
36+
}
37+
38+
public void setModel(String model) {
39+
this.model = model;
40+
}
41+
42+
public List<ChatMessage> getMessages() {
43+
return messages;
44+
}
45+
46+
public void setMessages(List<ChatMessage> messages) {
47+
this.messages = messages;
48+
}
49+
50+
public Integer getTtl() {
51+
return ttl;
52+
}
53+
54+
public void setTtl(Integer ttl) {
55+
this.ttl = ttl;
56+
}
57+
58+
public TruncationStrategy getTruncationStrategy() {
59+
return truncationStrategy;
60+
}
61+
62+
public void setTruncationStrategy(TruncationStrategy truncationStrategy) {
63+
this.truncationStrategy = truncationStrategy;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return "CreateContextRequest{" +
69+
"model='" + model + '\'' +
70+
", messages=" + messages +
71+
", ttl=" + ttl +
72+
", truncationStrategy=" + truncationStrategy +
73+
'}';
74+
}
75+
76+
public static CreateContextRequest.Builder builder() {
77+
return new Builder();
78+
}
79+
80+
public static class Builder {
81+
private String model;
82+
private List<ChatMessage> messages;
83+
private Integer ttl;
84+
private TruncationStrategy truncationStrategy;
85+
86+
private Builder() {
87+
}
88+
89+
public Builder model(String model) {
90+
this.model = model;
91+
return this;
92+
}
93+
94+
public Builder messages(List<ChatMessage> messages) {
95+
this.messages = messages;
96+
return this;
97+
}
98+
99+
public Builder ttl(Integer ttl) {
100+
this.ttl = ttl;
101+
return this;
102+
}
103+
104+
public Builder truncationStrategy(TruncationStrategy truncationStrategy) {
105+
this.truncationStrategy = truncationStrategy;
106+
return this;
107+
}
108+
109+
public CreateContextRequest build() {
110+
CreateContextRequest createContextRequest = new CreateContextRequest();
111+
createContextRequest.setModel(model);
112+
createContextRequest.setMessages(messages);
113+
createContextRequest.setTtl(ttl);
114+
createContextRequest.setTruncationStrategy(truncationStrategy);
115+
return createContextRequest;
116+
}
117+
}
118+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.volcengine.ark.runtime.model.context;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public class CreateContextResult {
8+
9+
@JsonProperty("id")
10+
private String id;
11+
12+
@JsonProperty("model")
13+
private String model;
14+
15+
@JsonProperty("ttl")
16+
private Integer ttl;
17+
18+
@JsonProperty("truncation_strategy")
19+
private TruncationStrategy truncationStrategy;
20+
21+
public String getId() {
22+
return id;
23+
}
24+
25+
public void setId(String id) {
26+
this.id = id;
27+
}
28+
29+
public String getModel() {
30+
return model;
31+
}
32+
33+
public void setModel(String model) {
34+
this.model = model;
35+
}
36+
37+
public Integer getTtl() {
38+
return ttl;
39+
}
40+
41+
public void setTtl(Integer ttl) {
42+
this.ttl = ttl;
43+
}
44+
45+
public TruncationStrategy getTruncationStrategy() {
46+
return truncationStrategy;
47+
}
48+
49+
public void setTruncationStrategy(TruncationStrategy truncationStrategy) {
50+
this.truncationStrategy = truncationStrategy;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "CreateContextResult{" +
56+
"id='" + id + '\'' +
57+
", model='" + model + '\'' +
58+
", ttl=" + ttl +
59+
", truncationStrategy=" + truncationStrategy +
60+
'}';
61+
}
62+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.volcengine.ark.runtime.model.context;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public class TruncationStrategy {
8+
9+
public static final String TRUNCATION_STRATEGY_TYPE_LAST_HISTORY_TOKENS = "last_history_tokens";
10+
11+
@JsonProperty("type")
12+
private String Type;
13+
14+
@JsonProperty("last_history_tokens")
15+
private Integer LastHistoryTokens;
16+
17+
public TruncationStrategy() {
18+
}
19+
20+
public TruncationStrategy(String type, Integer lastHistoryTokens) {
21+
Type = type;
22+
LastHistoryTokens = lastHistoryTokens;
23+
}
24+
25+
public String getType() {
26+
return Type;
27+
}
28+
29+
public void setType(String type) {
30+
Type = type;
31+
}
32+
33+
public Integer getLastHistoryTokens() {
34+
return LastHistoryTokens;
35+
}
36+
37+
public void setLastHistoryTokens(Integer lastHistoryTokens) {
38+
LastHistoryTokens = lastHistoryTokens;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "TruncationStrategy{" +
44+
"Type='" + Type + '\'' +
45+
", LastHistoryTokens=" + LastHistoryTokens +
46+
'}';
47+
}
48+
49+
public static TruncationStrategy.Builder builder() {
50+
return new Builder();
51+
}
52+
53+
public static class Builder {
54+
private Integer LastHistoryTokens;
55+
private String Type;
56+
57+
private Builder() {
58+
}
59+
60+
public Builder LastHistoryTokens(Integer LastHistoryTokens) {
61+
this.LastHistoryTokens = LastHistoryTokens;
62+
return this;
63+
}
64+
65+
public Builder Type(String Type) {
66+
this.Type = Type;
67+
return this;
68+
}
69+
70+
public TruncationStrategy build() {
71+
TruncationStrategy truncationStrategy = new TruncationStrategy();
72+
truncationStrategy.setLastHistoryTokens(LastHistoryTokens);
73+
truncationStrategy.setType(Type);
74+
return truncationStrategy;
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)