generated from softwaremill/sbt-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add streaming support for chat completions (#124)
- Loading branch information
Showing
18 changed files
with
657 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/scala/sttp/openai/requests/completions/chat/ChatChunkRequestResponseData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package sttp.openai.requests.completions.chat | ||
|
||
import sttp.openai.json.SnakePickle | ||
|
||
object ChatChunkRequestResponseData { | ||
|
||
/** @param role | ||
* The role of the author of this message. | ||
* @param content | ||
* The contents of the message. | ||
* @param functionCall | ||
* The name of the author of this message. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters. | ||
*/ | ||
case class Delta(role: Option[Role] = None, content: Option[String] = None, functionCall: Option[FunctionCall] = None) | ||
|
||
object Delta { | ||
implicit val deltaR: SnakePickle.Reader[Delta] = SnakePickle.macroR[Delta] | ||
} | ||
|
||
case class Choices( | ||
delta: Delta, | ||
finishReason: String, | ||
index: Int | ||
) | ||
|
||
object Choices { | ||
implicit val choicesR: SnakePickle.Reader[Choices] = SnakePickle.macroR[Choices] | ||
} | ||
|
||
case class ChatChunkResponse( | ||
id: String, | ||
`object`: String, | ||
created: Int, | ||
model: String, | ||
choices: Seq[Choices] | ||
) | ||
|
||
object ChatChunkResponse { | ||
val DoneEventMessage = "[DONE]" | ||
|
||
implicit val chunkChatR: SnakePickle.Reader[ChatChunkResponse] = SnakePickle.macroR[ChatChunkResponse] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/scala/sttp/openai/requests/completions/chat/FunctionCall.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sttp.openai.requests.completions.chat | ||
|
||
import sttp.openai.json.SnakePickle | ||
|
||
/** @param arguments | ||
* The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid | ||
* JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your | ||
* function. | ||
* @param name | ||
* The name of the function to call. | ||
*/ | ||
case class FunctionCall(arguments: String, name: String) | ||
|
||
object FunctionCall { | ||
implicit val functionCallRW: SnakePickle.ReadWriter[FunctionCall] = SnakePickle.macroRW[FunctionCall] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.