Threads API

Call the thread API

import io.github.quafadas.dairect.*
import io.github.quafadas.dairect.ThreadApi.*
import io.github.quafadas.dairect.ChatGpt .*

val vsApi = VectorStoreApi.defaultAuthLogToFile(fs2.io.file.Path("thread.txt")).allocated.map(_._1).Ø
// vsApi: VectorStoreApi = io.github.quafadas.dairect.VectorStoreApi$proxy$1@57f20d18
val (threadApi, _) = ThreadApi.defaultAuthLogToFile(fs2.io.file.Path("vectorStore.txt")).allocated.Ø
// threadApi: ThreadApi = io.github.quafadas.dairect.ThreadApi$proxy$1@770b7b49

val newThread = threadApi.create(List(
    ThreadMessage("I am cow".msg)
  )
).Ø
// newThread: Thread = Thread(
//   id = "thread_8JVqVy2tlTcGAGt4iiql4YpT",
//   object = "thread",
//   created_at = 1724939545L,
//   metadata = Map()
// )

println(newThread)
// Thread(thread_8JVqVy2tlTcGAGt4iiql4YpT,thread,1724939545,Map())

val vs = vsApi.list().Ø.data.head.id
// vs: String = "vs_skJUCFj83DLnhOGOfmy7CrQi"

val modThread = threadApi
  .modifyThread(
    newThread.id,
    ToolResources(file_search = FileSearch(vector_store_ids = VectorStoreIds(List(vs)).some).some)
  )
// modThread: Thread = Thread(
//   id = "thread_8JVqVy2tlTcGAGt4iiql4YpT",
//   object = "thread",
//   created_at = 1724939545L,
//   metadata = Map()
// )

println(modThread)
// Thread(thread_8JVqVy2tlTcGAGt4iiql4YpT,thread,1724939545,Map())

val getThread = threadApi.getThread(newThread.id).Ø
// getThread: Thread = Thread(
//   id = "thread_8JVqVy2tlTcGAGt4iiql4YpT",
//   object = "thread",
//   created_at = 1724939545L,
//   metadata = Map()
// )

println(getThread)
// Thread(thread_8JVqVy2tlTcGAGt4iiql4YpT,thread,1724939545,Map())

val deleted = threadApi.deleteThread(newThread.id).Ø
// deleted: ThreadDeleted = ThreadDeleted(
//   id = "thread_8JVqVy2tlTcGAGt4iiql4YpT",
//   object = "thread.deleted",
//   deleted = true
// )

println(deleted)
// ThreadDeleted(thread_8JVqVy2tlTcGAGt4iiql4YpT,thread.deleted,true)
In this article