Detecting file content type before submitting binary content to LLM, a small Kotlin multiplatform library.
The APIs of AI companies, like OpenAI API and Anthropic API, are accepting binary content, (e.g. images and documents), encoded as base64 strings with accompanied MIME type. This library provides a minimal support of detecting the MediaType of binary data, therefore it simplifies API usage, so that only a file is referenced directly, and all the other parameters can be detected and set automatically.
Note
The xemantic-ai-file-magic
was initially a part of the anthropic-sdk-kotlin, but was eventually externalized, as a common functionality applicable across various API-related use cases.
In build.gradle.kts
add:
dependencies {
implementation("com.xemantic.ai:xemantic-ai-file-magic:0.2")
}
See test cases for further information.
Clone this repo and then in the project dir:
./gradlew build