Skip to content

Commit 1a9bb01

Browse files
authored
feat(messages): add assistant tools to attachements (#370)
1 parent ebde0a2 commit 1a9bb01

File tree

1 file changed

+36
-1
lines changed
  • openai-core/src/commonMain/kotlin/com.aallam.openai.api/message

1 file changed

+36
-1
lines changed
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.aallam.openai.api.message
22

3+
import com.aallam.openai.api.BetaOpenAI
4+
import com.aallam.openai.api.assistant.AssistantTool
35
import com.aallam.openai.api.file.FileId
46
import kotlinx.serialization.SerialName
57
import kotlinx.serialization.Serializable
@@ -8,9 +10,42 @@ import kotlinx.serialization.Serializable
810
* References an Attachment in the message request.
911
*/
1012
@Serializable
13+
@OptIn(BetaOpenAI::class)
1114
public data class Attachment(
1215
/**
1316
* The ID of the file to attach to the message.
1417
*/
15-
@SerialName("file_id") val fileId: FileId
18+
@SerialName("file_id") val fileId: FileId? = null,
19+
20+
/**
21+
* The tools to add this file to.
22+
*/
23+
@SerialName("tools") val tools: List<AssistantTool>? = null,
1624
)
25+
26+
/**
27+
* A message attachment builder.
28+
*/
29+
public fun attachment(block: AttachmentBuilder.() -> Unit): Attachment = AttachmentBuilder().apply(block).build()
30+
31+
/**
32+
* A message attachment builder.
33+
*/
34+
public class AttachmentBuilder {
35+
/**
36+
* The ID of the file to attach to the message.
37+
*/
38+
public var fileId: FileId? = null
39+
40+
/**
41+
* The tools to add this file to.
42+
*/
43+
@OptIn(BetaOpenAI::class)
44+
public var tools: List<AssistantTool>? = null
45+
46+
/**
47+
* Build the attachment.
48+
*/
49+
@OptIn(BetaOpenAI::class)
50+
public fun build(): Attachment = Attachment(fileId, tools)
51+
}

0 commit comments

Comments
 (0)