
Offers a library for interacting with OpenAI APIs, featuring a clean, testable interface. Utilizes Ktor and Kotlinx Serialization for seamless integration and API communication.
Kotlin Multiplatform library to interact with OpenAI APIs, designed for use in Android, iOS, and other Kotlin-supported platforms with a clean and testable interface.
Add to your KMP project:
dependencies {
implementation("com.github.alderfurtado:openai-kmp:<latest-version>")
}First, create an instance of the OpenAiInput class. It consists of:
openAiModel: The model type to use (see available models)content: The prompt or command you want the AI to respond toinstruction: The way or tone the AI should respond inval input = OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Who discovered Brazil?",
instruction = "Respond like a history teacher"
)Next, create an instance of the OpenAiKmp class. It provides the sendContent function, which requires:
openAiInput: the input object you just created πtoken: your OpenAI API key get your API key here
val response = OpenAiKmp().sendContent(
openAiInput = input,
token = "your-openai-api-key"
)Then, receive the responde which consinst of:
content: result of contenterror: error if something goes wrongresult.content?.let {
// SUCCESS CODE FLOW
}
result.error?.let {
// ERROR CODE FLOW
}val openAiInput = OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Who discovered Brazil",
instruction = "Talks as History teacher"
)
val result = OpenAiKmp().sendContent(
OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Quem descobriu o Brasil", instruction = "Talks as History teacher"
),
"token" // put your openAi token
)
result.content?.let {
// SUCCESS CODE FLOW
}
result.error?.let {
// ERROR CODE FLOW
}This project is licensed under the MIT License.
Kotlin Multiplatform library to interact with OpenAI APIs, designed for use in Android, iOS, and other Kotlin-supported platforms with a clean and testable interface.
Add to your KMP project:
dependencies {
implementation("com.github.alderfurtado:openai-kmp:<latest-version>")
}First, create an instance of the OpenAiInput class. It consists of:
openAiModel: The model type to use (see available models)content: The prompt or command you want the AI to respond toinstruction: The way or tone the AI should respond inval input = OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Who discovered Brazil?",
instruction = "Respond like a history teacher"
)Next, create an instance of the OpenAiKmp class. It provides the sendContent function, which requires:
openAiInput: the input object you just created πtoken: your OpenAI API key get your API key here
val response = OpenAiKmp().sendContent(
openAiInput = input,
token = "your-openai-api-key"
)Then, receive the responde which consinst of:
content: result of contenterror: error if something goes wrongresult.content?.let {
// SUCCESS CODE FLOW
}
result.error?.let {
// ERROR CODE FLOW
}val openAiInput = OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Who discovered Brazil",
instruction = "Talks as History teacher"
)
val result = OpenAiKmp().sendContent(
OpenAiInput(
openAiModel = OpenAiModel.GPT_4O,
content = "Quem descobriu o Brasil", instruction = "Talks as History teacher"
),
"token" // put your openAi token
)
result.content?.let {
// SUCCESS CODE FLOW
}
result.error?.let {
// ERROR CODE FLOW
}This project is licensed under the MIT License.