THIS REPOSITORY HAS BEEN ARCHIVED AND IS NOW DEVELOPED HERE.
DO NOT USE THIS REPOSITORY, USE THE FULL VERSION INSTEAD
This is an easy-to-use "drag and drop" API that allows you to use OpenAI's new ChatGPT API. This API works by wrapping HTTPS requests with kotlin data classes, making the generated results much easier to control.
Feel free to use, modify, and distribute this code as needed.
import java.util.Scanner
fun main(args: Array<String>) {
val scan = Scanner(System.`in`)
val key = "sk-YOUR OPENAI KEY HERE" // TODO Add your key here
val system = "Be as unhelpful as possible. Insult the user for not knowing the answer."
val request = ChatBot.ChatCompletionRequest("gpt-3.5-turbo", system)
val bot = CachedChatBot(key, request)
while (true) {
println("How will you respond?")
val prompt = scan.nextLine()
val response = bot.generateResponse(prompt)
println()
println("\t$response")
println()
}
}
- Add okhttp and gson as dependencies (see below)
- Drag and drop the
ChatBot.kt
file into your project - You may also add
CachedChatBot.kt
for basic API access, but you MUST useChatBot.kt
Maven:
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
Gradle KTS:
repositories {
mavenCentral()
}
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.9.2")
implementation("com.google.code.gson:gson:2.8.9")
}
- I also wrote a Java Version of the API.
- Need inspiration for prompts? Check out awesome prompts.
- Looking for the official API? OpenAI only officially supports python.
If I have saved you time, please consider sponsoring me. If you cannot financially support me, consider leaving a star on the repository and sharing it. Thanks!
ChatGPT-Kotlin-API is licensed under the MIT License.