Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
91cf70e
Add cancel run endpoint
branislav-burdiliak Jul 15, 2024
ba9e33d
Add modify run endpoint
branislav-burdiliak Jul 15, 2024
9a986bd
Add list runs endpoint
branislav-burdiliak Jul 15, 2024
771a8d2
Add newly introduced methods to service wrapper
branislav-burdiliak Jul 15, 2024
584d59e
Finish createRun
branislav-burdiliak Aug 4, 2024
626850a
Separate assistant tool hierarchy to be used by create assistant and …
branislav-burdiliak Aug 4, 2024
c23d710
wip
branislav-burdiliak Aug 6, 2024
20b953c
Add order param to list runs endpoint
branislav-burdiliak Aug 9, 2024
1ec0e1d
Fix submit tool outputs endpoint
branislav-burdiliak Aug 9, 2024
eae9d68
Add retrieve run step endpoint
branislav-burdiliak Aug 9, 2024
5387e5b
Fix assistant tool codec
branislav-burdiliak Aug 9, 2024
c2a80dd
Reformat code
branislav-burdiliak Aug 9, 2024
810373b
Fix serialization of assistant's code interpreter tool's file IDs
branislav-burdiliak Aug 9, 2024
c55fc19
WIP - create thread and run
branislav-burdiliak Sep 5, 2024
a196332
added JsonFormats, compiling
bburdiliak Sep 9, 2024
8f9025a
fix formats, add Assistants example
bburdiliak Sep 10, 2024
b456777
scalafmt
bburdiliak Sep 10, 2024
95c1986
Merge remote-tracking branch 'origin/master' into feature/finish_run_API
bburdiliak Sep 11, 2024
84f94de
compilable after merging master
bburdiliak Sep 11, 2024
eecf951
scalafmt
bburdiliak Sep 11, 2024
bd4c94e
deleteThreadMessage + reorder methods to match the API reference
bburdiliak Sep 12, 2024
c319641
get rid of UploadFileSettings
bburdiliak Sep 12, 2024
a38d2ab
polling example for createThreadAndRun
bburdiliak Sep 12, 2024
6f44021
added methods: modifyVectorStore, retrieveVectorStore, retrieveVector…
bburdiliak Sep 13, 2024
b4b6bf9
scalafmt
bburdiliak Sep 13, 2024
e6ff47d
Merge branch 'master' into feature/finish_run_API
peterbanda Sep 16, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
polling example for createThreadAndRun
  • Loading branch information
bburdiliak committed Sep 12, 2024
commit a38d2abe64f23faf905c9f17da859d696d363edf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ object RunStatus {
case object Completed extends RunStatus
case object Incomplete extends RunStatus
case object Expired extends RunStatus

def finishedStates: Set[RunStatus] =
Set(
Completed,
Failed,
Cancelled,
Incomplete, // TODO: is this a finished state?
Expired
)
}

sealed trait ToolChoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,8 @@ object CreateRunWithCodeInterpretation extends Example with PollingHelper {
stream = false
)

doneStatues: Set[RunStatus] = Set(
RunStatus.Completed,
RunStatus.Failed,
RunStatus.Expired,
RunStatus.Expired
)

// poll until done
runNew <- pollUntilDone((run: Run) => doneStatues.contains(run.status)) {
runNew <- pollUntilDone((run: Run) => RunStatus.finishedStates.contains(run.status)) {
service
.retrieveRun(thread.id, run.id)
.map(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.cequence.openaiscala.examples.scenario

import io.cequence.openaiscala.domain.AssistantTool.FileSearchTool
import io.cequence.openaiscala.domain.settings.FileUploadPurpose
import io.cequence.openaiscala.domain.{
AssistantId,
AssistantToolResource,
Run,
RunStatus,
ThreadMessage
}
import io.cequence.openaiscala.examples.CreateRunWithCodeInterpretation.{
pollUntilDone,
service
}
import io.cequence.openaiscala.examples.{Example, PollingHelper}
import io.cequence.openaiscala.examples.scenario.Assistants.{getClass, scheduleFile, service}

import java.io.File
import scala.concurrent.Future

object CreateThreadAndRunScenario extends Example with PollingHelper {

private def scheduleFile(): File = {
val resource = getClass.getResource("/CRA.txt")
if (resource == null) {
throw new RuntimeException("Failed to load CRA.txt from resources")
}
new File(resource.getFile)
}

override protected def run: Future[_] = {
for {
fileInfo <- service.uploadFile(
scheduleFile(),
purpose = FileUploadPurpose.assistants
)

vectorStore <- service.createVectorStore(
fileIds = Seq(fileInfo.id),
name = Some("CUSTOMER RELATIONSHIP AGREEMENT")
)

assistant <- service.createAssistant(
model = "gpt-4o-2024-05-13",
name = Some("Customer Relationship Assistant"),
description = Some(
"You are a trustworthy and reliable assistant that helps businesses with their customer relationship agreements."
),
instructions = Some(
"Please assist with customer relationship agreements based on the provided document."
),
tools = Seq(FileSearchTool()),
toolResources = Some(
AssistantToolResource(
AssistantToolResource.FileSearchResources(
vectorStoreIds = Seq(vectorStore.id)
)
)
)
)

run <- service.createThreadAndRun(
assistantId = AssistantId(assistant.id),
thread = None,
stream = false
)

runNew <- pollUntilDone((run: Run) => RunStatus.finishedStates.contains(run.status)) {
service
.retrieveRun(run.thread_id, run.id)
.map(
_.getOrElse(
throw new IllegalStateException(s"Run with id ${run.id} not found.")
)
)
}

_ = println(s"Run status: ${runNew.status}")

// get the messages
threadMessages <- service.listThreadMessages(run.thread_id)

} yield {
println(s"File created: ${fileInfo.id}")
println(s"Vector store created: ${vectorStore.id}")
println(s"Assistant created: ${assistant.id}")
println(s"Thread created: ${run.thread_id}")
println(s"Run created: ${run.id}")
threadMessages.foreach(println)
}
}

}