You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "bowenliang123 (via GitHub)" <gi...@apache.org> on 2023/03/19 09:22:24 UTC
[GitHub] [kyuubi] bowenliang123 commented on a diff in pull request #4556: [CHAT] Refactor ChatGPTProvider to use high-level API with `openai-java`
bowenliang123 commented on code in PR #4556:
URL: https://github.com/apache/kyuubi/pull/4556#discussion_r1141308502
##########
externals/kyuubi-chat-engine/src/main/scala/org/apache/kyuubi/engine/chat/provider/ChatGPTProvider.scala:
##########
@@ -75,29 +74,19 @@ class ChatGPTProvider(conf: KyuubiConf) extends ChatProvider {
override def ask(sessionId: String, q: String): String = {
val messages = chatHistory.get(sessionId)
- messages.addLast(Message("user", q))
-
- val request = new HttpPost("https://api.openai.com/v1/chat/completions")
- val req = Map(
- "messages" -> messages,
- "model" -> "gpt-3.5-turbo",
- "max_tokens" -> 200,
- "temperature" -> 0.5,
- "top_p" -> 1)
- val entity = new StringEntity(mapper.writeValueAsString(req), ContentType.APPLICATION_JSON)
- request.setEntity(entity)
- request.setConfig(requestConfig)
- val response = httpClient.execute(request)
- val respJson = mapper.readTree(EntityUtils.toString(response.getEntity))
- response.getStatusLine.getStatusCode match {
- case HttpStatus.SC_OK =>
- val replyMessage = mapper.treeToValue[Message](
- respJson.get("choices").get(0).get("message"))
- messages.addLast(replyMessage)
- replyMessage.content
- case errorStatusCode =>
+ try {
+ messages.addLast(new ChatMessage("user", q))
+ val completionRequest = ChatCompletionRequest.builder()
+ .messages(messages.asScala.toList.asJava)
+ .model("gpt-3.5-turbo")
Review Comment:
Sure. Make it configurable of other ChatCompletionRequest settings like model name, max tokens, etc.
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org