You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by bo...@apache.org on 2023/05/10 03:53:24 UTC

[kyuubi] branch master updated: [KYUUBI #4810] [CHAT] Request and use a sginle choice for chat completion

This is an automated email from the ASF dual-hosted git repository.

bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new e112e381f [KYUUBI #4810] [CHAT] Request and use a sginle choice for chat completion
e112e381f is described below

commit e112e381fff99f1d619185521edb064d88d35873
Author: bowenliang <bo...@apache.org>
AuthorDate: Wed May 10 11:53:14 2023 +0800

    [KYUUBI #4810] [CHAT] Request and use a sginle choice for chat completion
    
    ### _Why are the changes needed?_
    
    - explicitly set `n` to 1 in ChatGPT chat completion request (default to 1, https://platform.openai.com/docs/api-reference/chat/create#chat/create-n)
    - use the only one choice of the chat completion response
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #4810 from bowenliang123/chat-onechoice.
    
    Closes #4810
    
    f221de4e8 [bowenliang] one message
    
    Authored-by: bowenliang <bo...@apache.org>
    Signed-off-by: bowenliang <bo...@apache.org>
---
 .../org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala     | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala b/externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala
index 03bf0b820..aae8b488a 100644
--- a/externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala
+++ b/externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala
@@ -83,9 +83,10 @@ class ChatGPTProvider(conf: KyuubiConf) extends ChatProvider {
         .model(conf.get(KyuubiConf.ENGINE_CHAT_GPT_MODEL))
         .messages(messages.asScala.toList.asJava)
         .user(sessionUser.orNull)
+        .n(1)
         .build()
-      val responseText = openAiService.createChatCompletion(completionRequest).getChoices.asScala
-        .map(c => c.getMessage.getContent).mkString
+      val responseText = openAiService.createChatCompletion(completionRequest)
+        .getChoices.get(0).getMessage.getContent
       responseText
     } catch {
       case e: Throwable =>