Skip to content

Commit f255f6b

Browse files
committed
OpenAIChatCompletionExtra - support for failover models added to createChatCompletionWithJSON
1 parent f6d2c1e commit f255f6b

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ val scala3 = "3.2.2"
77

88
ThisBuild / organization := "io.cequence"
99
ThisBuild / scalaVersion := scala212
10-
ThisBuild / version := "1.1.1.RC.2"
10+
ThisBuild / version := "1.1.1.RC.8"
1111
ThisBuild / isSnapshot := false
1212

1313
lazy val commonSettings = Seq(

openai-core/src/main/scala/io/cequence/openaiscala/service/OpenAIChatCompletionExtra.scala

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ object OpenAIChatCompletionExtra {
5757
def createChatCompletionWithJSON[T: Format](
5858
messages: Seq[BaseMessage],
5959
settings: CreateChatCompletionSettings,
60-
taskNameForLogging: Option[String] = None,
61-
maxRetries: Option[Int] = Some(5),
62-
retryOnAnyError: Boolean = false
60+
failoverModels: Seq[String],
61+
maxRetries: Option[Int] = Some(defaultMaxRetries),
62+
retryOnAnyError: Boolean = false,
63+
taskNameForLogging: Option[String] = None
6364
)(
6465
implicit ec: ExecutionContext,
6566
scheduler: Scheduler
@@ -78,10 +79,14 @@ object OpenAIChatCompletionExtra {
7879
(messages, settings)
7980
}
8081

81-
val callFuture = openAIChatCompletionService
82-
.createChatCompletion(
82+
openAIChatCompletionService
83+
.createChatCompletionWithFailover(
8384
messagesFinal,
84-
settingsFinal
85+
settingsFinal,
86+
failoverModels,
87+
maxRetries,
88+
retryOnAnyError,
89+
failureMessage = s"${taskNameForLoggingFinal.capitalize} failed."
8590
)
8691
.map { response =>
8792
val content = response.choices.head.message.content
@@ -95,18 +100,6 @@ object OpenAIChatCompletionExtra {
95100

96101
json.as[T]
97102
}
98-
99-
maxRetries.map { maxRetries =>
100-
implicit val retrySettings: RetrySettings = RetrySettings(maxRetries = maxRetries)
101-
102-
callFuture.retryOnFailure(
103-
failureMessage = Some(s"${taskNameForLoggingFinal.capitalize} failed."),
104-
log = Some(logger.warn),
105-
isRetryable = isRetryable(retryOnAnyError)
106-
)
107-
}.getOrElse(
108-
callFuture
109-
)
110103
}
111104

112105
private def isRetryable(
@@ -125,7 +118,7 @@ object OpenAIChatCompletionExtra {
125118
ModelId.gpt_4o_2024_08_06
126119
)
127120

128-
private def handleOutputJsonSchema(
121+
def handleOutputJsonSchema(
129122
messages: Seq[BaseMessage],
130123
settings: CreateChatCompletionSettings,
131124
taskNameForLogging: String,

0 commit comments

Comments
 (0)