From cf94841b93d08a28542ea3858c27d959ad8eb8d9 Mon Sep 17 00:00:00 2001 From: Mouaad Aallam Date: Sat, 20 Jul 2024 11:08:22 +0200 Subject: [PATCH] feat(messages): add assistant tools to attachements --- .../message/Attachment.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/message/Attachment.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/message/Attachment.kt index fdf4ecb2..6ec31813 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/message/Attachment.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/message/Attachment.kt @@ -1,5 +1,7 @@ package com.aallam.openai.api.message +import com.aallam.openai.api.BetaOpenAI +import com.aallam.openai.api.assistant.AssistantTool import com.aallam.openai.api.file.FileId import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -8,9 +10,42 @@ import kotlinx.serialization.Serializable * References an Attachment in the message request. */ @Serializable +@OptIn(BetaOpenAI::class) public data class Attachment( /** * The ID of the file to attach to the message. */ - @SerialName("file_id") val fileId: FileId + @SerialName("file_id") val fileId: FileId? = null, + + /** + * The tools to add this file to. + */ + @SerialName("tools") val tools: List? = null, ) + +/** + * A message attachment builder. + */ +public fun attachment(block: AttachmentBuilder.() -> Unit): Attachment = AttachmentBuilder().apply(block).build() + +/** + * A message attachment builder. + */ +public class AttachmentBuilder { + /** + * The ID of the file to attach to the message. + */ + public var fileId: FileId? = null + + /** + * The tools to add this file to. + */ + @OptIn(BetaOpenAI::class) + public var tools: List? = null + + /** + * Build the attachment. + */ + @OptIn(BetaOpenAI::class) + public fun build(): Attachment = Attachment(fileId, tools) +}