
Offers an idiomatic library for interacting with the Groq API, featuring chat completions, audio transcription, translation, real-time streaming, and a rich DSL for clean syntax.
An idiomatic Kotlin Multiplatform library for the Groq API.
Add these dependencies to your project:
dependencies {
implementation("io.github.vyfor:groq-kt:$version")
/* required */
implementation("io.ktor:ktor-client-$engine:$version")
}For the list of supported engines, see Ktor Client Engines.
/* It is recommended to use an environment variable for the API key */
val apiKey = System.getenv("GROQ_API_KEY") // JVM
val apiKey = process.env.GROQ_API_KEY // JS
val apiKey = getenv("GROQ_API_KEY")!!.toKString() // Native
val client = GroqClient(apiKey)You can configure default values for requests. These values will be automatically applied to every request made with a DSL function.
val client = GroqClient(apiKey) {
defaults {
chatCompletion {
model = GroqModel.LLAMA_3_8B_8192
}
audioTranscription {
format = AudioResponseFormat.VERBOSE_JSON
}
}
}val response = client.chat {
model = GroqModel.LLAMA_3_8B_8192
messages {
system("You are a helpful assistant.")
text("What is the capital of Germany?")
}
}val response = client.chatStreaming {
model = GroqModel("$VISION_MODEL")
messages {
user(
"Describe what you see in the image.",
"https://example.com/image.png"
)
}
}.data.collect { chunk ->
println(chunk)
}val response = client.transcribe {
model = GroqModel("$TRANSCRIPTION_MODEL")
file("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}[!NOTE] Does not seem to be supported by the API yet.
val response = client.translate {
model = GroqModel("$TRANSLATION_MODEL")
file("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}groq-kt is licensed under the MIT License.
The project is not affiliated with Groq in any way.
The REST API documentation can be found on console.groq.com.
This project is in beta and hasn't undergone excessive testing. Contributions of any kind are welcome, just make sure you read the Contribution Guidelines first. You can also contact me directly on Discord (vyfor) if you have any questions.
An idiomatic Kotlin Multiplatform library for the Groq API.
Add these dependencies to your project:
dependencies {
implementation("io.github.vyfor:groq-kt:$version")
/* required */
implementation("io.ktor:ktor-client-$engine:$version")
}For the list of supported engines, see Ktor Client Engines.
/* It is recommended to use an environment variable for the API key */
val apiKey = System.getenv("GROQ_API_KEY") // JVM
val apiKey = process.env.GROQ_API_KEY // JS
val apiKey = getenv("GROQ_API_KEY")!!.toKString() // Native
val client = GroqClient(apiKey)You can configure default values for requests. These values will be automatically applied to every request made with a DSL function.
val client = GroqClient(apiKey) {
defaults {
chatCompletion {
model = GroqModel.LLAMA_3_8B_8192
}
audioTranscription {
format = AudioResponseFormat.VERBOSE_JSON
}
}
}val response = client.chat {
model = GroqModel.LLAMA_3_8B_8192
messages {
system("You are a helpful assistant.")
text("What is the capital of Germany?")
}
}val response = client.chatStreaming {
model = GroqModel("$VISION_MODEL")
messages {
user(
"Describe what you see in the image.",
"https://example.com/image.png"
)
}
}.data.collect { chunk ->
println(chunk)
}val response = client.transcribe {
model = GroqModel("$TRANSCRIPTION_MODEL")
file("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}[!NOTE] Does not seem to be supported by the API yet.
val response = client.translate {
model = GroqModel("$TRANSLATION_MODEL")
file("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}groq-kt is licensed under the MIT License.
The project is not affiliated with Groq in any way.
The REST API documentation can be found on console.groq.com.
This project is in beta and hasn't undergone excessive testing. Contributions of any kind are welcome, just make sure you read the Contribution Guidelines first. You can also contact me directly on Discord (vyfor) if you have any questions.