Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(messages): add assistant tools to attachements #370

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<AssistantTool>? = 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<AssistantTool>? = null

/**
* Build the attachment.
*/
@OptIn(BetaOpenAI::class)
public fun build(): Attachment = Attachment(fileId, tools)
}
Loading