pan3793 commented on code in PR #5828:
URL: https://github.com/apache/kyuubi/pull/5828#discussion_r1418639325


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -3056,6 +3059,23 @@ object KyuubiConf {
       .stringConf
       .createWithDefault("gpt-3.5-turbo")
 
+  val ERNIE_BOT_ACCESS_TOKEN: OptionalConfigEntry[String] =
+    buildConf("kyuubi.engine.chat.ernie.token")
+      .doc("The token to access ernie bot open API, which could be got at " +
+        "https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Ilkkrb0i5";)
+      .version("1.8.0")

Review Comment:
   ```suggestion
         .version("1.9.0")
   ```



##########
externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ErnieBotProvider.scala:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.engine.chat.provider
+
+import java.net.{InetSocketAddress, Proxy, URL}
+import java.time.Duration
+import java.util
+import java.util.concurrent.TimeUnit
+
+import scala.collection.JavaConverters._
+
+import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
+
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.engine.chat.ernie.api.ErnieBotApi
+import org.apache.kyuubi.engine.chat.ernie.bean.{ChatCompletionRequest, 
ChatMessage, ChatMessageRole}
+import org.apache.kyuubi.engine.chat.ernie.service.ErnieBotService
+import 
org.apache.kyuubi.engine.chat.ernie.service.ErnieBotService.{defaultClient, 
defaultObjectMapper, defaultRetrofit}
+
+class ErnieBotProvider(conf: KyuubiConf) extends ChatProvider {
+
+  private val accessToken = 
conf.get(KyuubiConf.ERNIE_BOT_ACCESS_TOKEN).getOrElse {
+    throw new IllegalArgumentException(
+      s"'${KyuubiConf.ERNIE_BOT_ACCESS_TOKEN.key}' must be configured, " +
+        s"which could be got at 
https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Ilkkrb0i5";)
+  }
+
+  private val model = conf.get(KyuubiConf.ERNIE_BOT_MODEL)
+
+  private val ernieBotService: ErnieBotService = {
+    val builder = defaultClient(
+      
Duration.ofMillis(conf.get(KyuubiConf.ENGINE_CHAT_GPT_HTTP_SOCKET_TIMEOUT)))
+      .newBuilder
+      
.connectTimeout(Duration.ofMillis(conf.get(KyuubiConf.ENGINE_CHAT_GPT_HTTP_CONNECT_TIMEOUT)))

Review Comment:
   avoid using configuration starting with `kyuubi.engine.chat.gpt.`



##########
externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/ernie/api/ErnieBotApi.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.engine.chat.ernie.api;
+
+
+import io.reactivex.Single;
+import org.apache.kyuubi.engine.chat.ernie.bean.ChatCompletionRequest;
+import org.apache.kyuubi.engine.chat.ernie.bean.ChatCompletionResult;
+import retrofit2.http.Body;
+import retrofit2.http.POST;
+import retrofit2.http.Query;
+
+public interface ErnieBotApi {
+
+    @POST("/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro")

Review Comment:
   the "completions_pro" actually looks like a path variable, can we refactor 
it?



##########
externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/ernie/service/ErnieBotService.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.engine.chat.ernie.service;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import io.reactivex.Single;
+import okhttp3.ConnectionPool;
+import okhttp3.OkHttpClient;
+import org.apache.kyuubi.engine.chat.ernie.api.*;
+import org.apache.kyuubi.engine.chat.ernie.bean.ChatCompletionRequest;
+import org.apache.kyuubi.engine.chat.ernie.bean.ChatCompletionResult;
+import org.apache.kyuubi.engine.chat.ernie.constants.Model;
+import retrofit2.HttpException;
+import retrofit2.Retrofit;
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
+import retrofit2.converter.jackson.JacksonConverterFactory;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+public class ErnieBotService {
+
+    private static final String BASE_URL = "https://aip.baidubce.com/";;
+    
+    private final ErnieBotApi api;
+
+    public ErnieBotService(ErnieBotApi api) {
+        this.api = api;
+    }
+
+
+    public static <T> T execute(Single<T> apiCall) {
+        try {
+            return apiCall.blockingGet();
+        } catch (HttpException var5) {

Review Comment:
   avoiding variable name like var*



##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -3056,6 +3059,23 @@ object KyuubiConf {
       .stringConf
       .createWithDefault("gpt-3.5-turbo")
 
+  val ERNIE_BOT_ACCESS_TOKEN: OptionalConfigEntry[String] =
+    buildConf("kyuubi.engine.chat.ernie.token")
+      .doc("The token to access ernie bot open API, which could be got at " +
+        "https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Ilkkrb0i5";)
+      .version("1.8.0")
+      .stringConf
+      .createOptional
+
+  val ERNIE_BOT_MODEL: ConfigEntry[String] =
+    buildConf("kyuubi.engine.chat.ernie.model")
+      .doc("ID of the model used in ernie bot. " +
+        "Available models are completions_pro, ernie_bot_8k, completions and 
eb-instant" +
+        "[Model 
overview](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/6lp69is2a).")
+      .version("1.8.0")

Review Comment:
   ```suggestion
         .version("1.9.0")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to