OpenAI's persistent assistants
Build persistent AI assistants using OpenAI's Assistants API with file handling, code execution, and long-term memory.
Advanced stateful assistants with tool capabilities beyond simple chat interactions.
Complete implementation of OpenAI's Assistants API in Kotlin with Spring Boot. Creates intelligent AI assistants with file search capabilities.
// Upload & Index
val file = openAIAssistant.uploadFile(
fileBytes = movieFile.toByteArray(),
filename = "movies.txt",
purpose = "assistants"
)
// Create Vector Store
val vectorStore = openAIAssistant.createVectorStore(
name = "Movie Database",
fileIds = listOf(file.id)
)
// Create Assistant with File Search
val assistant = openAIAssistant.createAssistant(
name = "Movie Expert",
instructions = MOVIE_ASSISTANT_PROMPT,
model = Models.Chat.GPT_4O,
tools = listOf(AssistantTool("file_search")),
vectorStoreIds = listOf(vectorStore.id)
)
// Multi-step async conversation
val thread = assistant.createThread()
assistant.addMessageToThread(thread.id, userMessage)
val run = assistant.runAssistant(thread.id, assistant.id)
// Poll for completion
while (run.status == "in_progress") {
delay(2000)
runStatus = assistant.getRunStatus(thread.id, run.id)
}
val response = assistant.getMessages(thread.id)
.data.filter { it.role == "assistant" }
.maxByOrNull { it.createdAt }