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 <[email protected]>
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 <[email protected]>
Signed-off-by: bowenliang <[email protected]>
---
.../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 =>