Skip to content

Commit f8629a8

Browse files
committed
Run isFinished
1 parent fc22785 commit f8629a8

File tree

11 files changed

+17
-29
lines changed

11 files changed

+17
-29
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.8"
10+
ThisBuild / version := "1.1.1.RC.9"
1111
ThisBuild / isSnapshot := false
1212

1313
lazy val commonSettings = Seq(

openai-core/src/main/scala/io/cequence/openaiscala/JsonFormats.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ object JsonFormats {
11661166
case c: JsonSchema.Boolean =>
11671167
Json.toJson(c).as[JsObject]
11681168

1169-
case c: JsonSchema.Null =>
1169+
case _: JsonSchema.Null =>
11701170
Json.obj()
11711171

11721172
case c: JsonSchema.Object =>

openai-core/src/main/scala/io/cequence/openaiscala/domain/Run.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ case class Run(
7474
usage: Option[UsageInfo]
7575
// tool_choice: Either[String, Any], // Replace Any with the actual type when available
7676
// response_format: Either[String, Any] // Replace Any with the actual type when available
77-
)
77+
) {
78+
def isFinished: Boolean = RunStatus.finishedStates.contains(status)
79+
}
7880

7981
object Run {
8082

openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateBatch.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ object CreateBatch extends Example {
88
override protected def run: Future[_] =
99
for {
1010
assistant <- service.createBatch(
11-
// inputFileId = "file-mjdvW9DTeWDXO2g6sks1kvuQ",
12-
// inputFileId = "file-bRFkk72miUWa48tDrE9b2lnL",
13-
inputFileId = "file-8v4jKZa0cviulgJLnEofCW1N",
11+
inputFileId = "file-xyz",
1412
endpoint = BatchEndpoint.`/v1/chat/completions`,
1513
completionWindow = CompletionWindow.`24h`,
1614
metadata = Map(
17-
"customer_id" -> "user_123456789",
15+
"customer_id" -> "user_abc",
1816
"batch_description" -> "Nightly eval job"
1917
)
2018
)

openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateChatCompletion.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.cequence.openaiscala.examples
22

3-
import io.cequence.openaiscala.domain.settings.{
4-
ChatCompletionResponseFormatType,
5-
CreateChatCompletionSettings
6-
}
3+
import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings
74
import io.cequence.openaiscala.domain._
85

96
import scala.concurrent.Future

openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateRunWithCodeInterpretation.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ object CreateRunWithCodeInterpretation extends Example with PollingHelper {
5353
)
5454

5555
// poll until done
56-
runNew <- pollUntilDone((run: Run) => RunStatus.finishedStates.contains(run.status)) {
56+
runNew <- pollUntilDone((run: Run) => run.isFinished) {
5757
service
5858
.retrieveRun(thread.id, run.id)
5959
.map(
60-
_.getOrElse(
61-
throw new IllegalStateException(s"Run with id ${run.id} not found.")
62-
)
60+
_.getOrElse(throw new IllegalStateException(s"Run with id ${run.id} not found."))
6361
)
6462
}
6563

openai-examples/src/main/scala/io/cequence/openaiscala/examples/RetrieveBatch.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import scala.concurrent.Future
99
object RetrieveBatch extends Example {
1010

1111
override protected def run: Future[Option[Unit]] =
12-
// service.retrieveBatch("batch_zb1dpz3HcFjOdo058gEg8iPn").map { maybeBatch =>
13-
// service.retrieveBatch("batch_wDuIbjt22f2vpjpn0ulU5xI1").map { maybeBatch =>
14-
service.retrieveBatch("batch_Ghy5a9EEXDLFqBcJqANpr17F").map { maybeBatch =>
12+
service.retrieveBatch("batch_xyz").map { maybeBatch =>
1513
println(maybeBatch)
1614

1715
maybeBatch.map { batch =>

openai-examples/src/main/scala/io/cequence/openaiscala/examples/RetrieveBatchResponses.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ object RetrieveBatchResponses extends Example {
66

77
override protected def run: Future[_] =
88
for {
9-
// maybeBatchResponses <- service.retrieveBatchResponses("file-A9V1zO4XpjjqBke8Kdp78vMU")
10-
maybeBatchResponses <- service.retrieveBatchResponses("batch_Ghy5a9EEXDLFqBcJqANpr17F")
9+
maybeBatchResponses <- service.retrieveBatchResponses("batch_xyz")
1110
} yield {
1211
maybeBatchResponses match {
1312
case Some(batchResponses) =>

openai-examples/src/main/scala/io/cequence/openaiscala/examples/RetrieveFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object RetrieveFile extends Example {
66

77
override protected def run: Future[_] =
88
for {
9-
assistant <- service.retrieveFile("file-2bZn9Vu6WicoTMOAEGW92pml")
9+
assistant <- service.retrieveFile("file-xyz")
1010
} yield {
1111
println(assistant)
1212
}

openai-examples/src/main/scala/io/cequence/openaiscala/examples/fixtures/TestFixtures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait TestFixtures {
1414

1515
val capitalsSchemaDef2 = capitalsSchemaDefAux(Right(capitalsSchema2))
1616

17-
def capitalsSchemaDefAux(schema: Either[JsonSchema, Map[String, Any]]) =
17+
def capitalsSchemaDefAux(schema: Either[JsonSchema, Map[String, Any]]): JsonSchemaDef =
1818
JsonSchemaDef(
1919
name = "capitals_response",
2020
strict = true,

openai-examples/src/main/scala/io/cequence/openaiscala/examples/scenario/CreateThreadAndRunScenario.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,16 @@ object CreateThreadAndRunScenario extends Example with PollingHelper {
5656
stream = false
5757
)
5858

59-
runNew <- pollUntilDone((run: Run) => RunStatus.finishedStates.contains(run.status)) {
59+
runNew <- pollUntilDone((run: Run) => run.isFinished) {
6060
service
6161
.retrieveRun(run.thread_id, run.id)
6262
.map(
63-
_.getOrElse(
64-
throw new IllegalStateException(s"Run with id ${run.id} not found.")
65-
)
63+
_.getOrElse(throw new IllegalStateException(s"Run with id ${run.id} not found."))
6664
)
6765
}
6866

69-
_ = println(s"Run status: ${runNew.status}")
70-
7167
// get the messages
72-
threadMessages <- service.listThreadMessages(run.thread_id)
68+
threadMessages <- service.listThreadMessages(runNew.thread_id)
7369

7470
} yield {
7571
println(s"File created: ${fileInfo.id}")

0 commit comments

Comments
 (0)