Skip to content

Commit

Permalink
Merge branch 'feat/ark_bot_runtime_addon' into 'master'
Browse files Browse the repository at this point in the history
feat(ark_bot_chat): add bot chat refs and examples

See merge request iaasng/volcengine-java-sdk!199
  • Loading branch information
修杰 committed Jun 25, 2024
2 parents 939d00e + 90750a5 commit da903a6
Show file tree
Hide file tree
Showing 49 changed files with 347 additions and 47 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>volcengine-java-sdk-bom</artifactId>
<version>0.1.116</version>
<version>0.1.117</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -70,12 +70,12 @@
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>volcengine-java-sdk-vpc</artifactId>
<version>0.1.116</version>
<version>0.1.117</version>
</dependency>
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>volcengine-java-sdk-ecs</artifactId>
<version>0.1.116</version>
<version>0.1.117</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"lasted": "0.1.116",
"lasted": "0.1.117",
"meta_commit": "7bbb70335644b7f832dca3226792ed293ac901aa"
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.volcengine</groupId>
<artifactId>volcengine-java-sdk</artifactId>
<packaging>pom</packaging>
<version>0.1.116</version>
<version>0.1.117</version>
<name>volcengine-java-sdk</name>
<url>https://open.volcengineapi.com</url>
<description>The Java SDK For Volcengine</description>
Expand Down
2 changes: 1 addition & 1 deletion volcengine-java-sdk-alb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>volcengine-java-sdk</artifactId>
<groupId>com.volcengine</groupId>
<version>0.1.116</version>
<version>0.1.117</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion volcengine-java-sdk-ark-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>volcengine-java-sdk</artifactId>
<groupId>com.volcengine</groupId>
<version>0.1.116</version>
<version>0.1.117</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public String toString() {
'}';
}

public static final class Builder {
public static Builder builder() {
return new Builder();
}

public static final class Builder extends ChatCompletionRequest.Builder {
private Map<String, Object> metadata;
private String botId;
private String model;
Expand Down Expand Up @@ -97,6 +101,8 @@ public Builder metadata(Map<String, Object> metadata) {

public Builder botId(String botId) {
this.botId = botId;
// overwrite the model.
this.model = botId;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.volcengine.ark.runtime.model.bot.completion.chat.reference.BotChatResultReference;
import com.volcengine.ark.runtime.model.bot.completion.chat.usage.BotUsage;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionChoice;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionResult;

import java.util.List;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -20,4 +23,33 @@ public class BotChatCompletionResult extends ChatCompletionResult {
*/
@JsonProperty("bot_usage")
private BotUsage botUsage;

/**
* The references returned by Search Actions.
*/
private List<BotChatResultReference> references;

public Map<String, Object> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}

public BotUsage getBotUsage() {
return botUsage;
}

public void setBotUsage(BotUsage botUsage) {
this.botUsage = botUsage;
}

public List<BotChatResultReference> getReferences() {
return references;
}

public void setReferences(List<BotChatResultReference> references) {
this.references = references;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,164 @@ public class BotChatResultReference {
*/
@JsonProperty("extra")
private Map<String, Object> extra;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getLogoUrl() {
return logoUrl;
}

public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}

public String getMobileUrl() {
return mobileUrl;
}

public void setMobileUrl(String mobileUrl) {
this.mobileUrl = mobileUrl;
}

public String getSiteName() {
return siteName;
}

public void setSiteName(String siteName) {
this.siteName = siteName;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public BotCoverImage getCoverImage() {
return coverImage;
}

public void setCoverImage(BotCoverImage coverImage) {
this.coverImage = coverImage;
}

public String getSummary() {
return summary;
}

public void setSummary(String summary) {
this.summary = summary;
}

public String getPublishTime() {
return publishTime;
}

public void setPublishTime(String publishTime) {
this.publishTime = publishTime;
}

public String getCollectionName() {
return collectionName;
}

public void setCollectionName(String collectionName) {
this.collectionName = collectionName;
}

public String getProject() {
return project;
}

public void setProject(String project) {
this.project = project;
}

public String getDocId() {
return docId;
}

public void setDocId(String docId) {
this.docId = docId;
}

public String getDocName() {
return docName;
}

public void setDocName(String docName) {
this.docName = docName;
}

public String getDocType() {
return docType;
}

public void setDocType(String docType) {
this.docType = docType;
}

public String getDocTitle() {
return docTitle;
}

public void setDocTitle(String docTitle) {
this.docTitle = docTitle;
}

public String getChunkId() {
return chunkId;
}

public void setChunkId(String chunkId) {
this.chunkId = chunkId;
}

public String getChunkTitle() {
return chunkTitle;
}

public void setChunkTitle(String chunkTitle) {
this.chunkTitle = chunkTitle;
}

public String getPageNums() {
return pageNums;
}

public void setPageNums(String pageNums) {
this.pageNums = pageNums;
}

public Integer getOriginTextTokenLen() {
return originTextTokenLen;
}

public void setOriginTextTokenLen(Integer originTextTokenLen) {
this.originTextTokenLen = originTextTokenLen;
}

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

public Map<String, Object> getExtra() {
return extra;
}

public void setExtra(Map<String, Object> extra) {
this.extra = extra;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.volcengine.ark.runtime.model.completion.chat;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionRequest;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.volcengine.ark.runtime.service;


import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionChunk;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionRequest;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionResult;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionChunk;
Expand All @@ -17,5 +18,5 @@ public interface ArkBaseServiceImpl {

BotChatCompletionResult createBotChatCompletion(BotChatCompletionRequest request);

Flowable<ChatCompletionChunk> streamBotChatCompletion(BotChatCompletionRequest request);
Flowable<BotChatCompletionChunk> streamBotChatCompletion(BotChatCompletionRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.volcengine.StringUtil;
import com.volcengine.ark.runtime.*;
import com.volcengine.ark.runtime.exception.ArkAPIError;
import com.volcengine.ark.runtime.exception.ArkException;
Expand All @@ -13,6 +14,7 @@
import com.volcengine.ark.runtime.interceptor.ArkResourceStsAuthenticationInterceptor;
import com.volcengine.ark.runtime.interceptor.RequestIdInterceptor;
import com.volcengine.ark.runtime.interceptor.RetryInterceptor;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionChunk;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionRequest;
import com.volcengine.ark.runtime.model.bot.completion.chat.BotChatCompletionResult;
import com.volcengine.ark.runtime.model.completion.chat.*;
Expand All @@ -25,6 +27,7 @@
import io.reactivex.Single;
import okhttp3.Headers;
import okhttp3.ResponseBody;
import org.apache.commons.lang.StringUtils;
import retrofit2.Call;
import retrofit2.HttpException;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
Expand Down Expand Up @@ -190,9 +193,9 @@ public BotChatCompletionResult createBotChatCompletion(BotChatCompletionRequest
}

@Override
public Flowable<ChatCompletionChunk> streamBotChatCompletion(BotChatCompletionRequest request) {
public Flowable<BotChatCompletionChunk> streamBotChatCompletion(BotChatCompletionRequest request) {
request.setStream(true);
return stream(api.createBotChatCompletionStream(request, request.getModel(), new HashMap<>()), ChatCompletionChunk.class);
return stream(api.createBotChatCompletionStream(request, request.getModel(), new HashMap<>()), BotChatCompletionChunk.class);
}

public void shutdownExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
while (!emitter.isCancelled() && (line = reader.readLine()) != null) {
if (line.startsWith("data:")) {
String data = line.substring(5).trim();

ArkAPIError err = mapper.readValue(data, ArkAPIError.class);
if (err.getError() != null) {
throw new ArkHttpException(err, null, -1, requestId);
}

sse = new SSE(data);
} else if (line.equals("") && sse != null) {
if (sse.isDone()) {
Expand Down
Loading

0 comments on commit da903a6

Please sign in to comment.