Skip to content

🔍 🌱 Kotlin spring starter implementation of chatGPT official api

License

Notifications You must be signed in to change notification settings

Sprytin/chatgpt-spring-boot-starter

Repository files navigation

Kotlin ChatGPT

How to use

  • Add the JitPack repository to your root build.gradle file:
repositories {
    maven { url "https://jitpack.io" }
}
  • Add the code to your module's build.gradle file:
dependencies {
    implementation 'tech.sprytin:chatgpt-spring-boot-starter:x.y.z'
}

//build.gradle.kts
dependencies {
    implementation("tech.sprytin:chatgpt-spring-boot-starter:x.y.z")
}

Put token from OpenAI in application.yml

chatgpt:
  token: "TOKEN"

Example

  • add GptService bean
@Service
class ExampleService(
    val gptService: GptService
) 
  • Request example
fun example() {
    val response = gptService.askGpt(
        ChatCompletionRequest(
            listOf(ChatMessage(content = "Hello!"))
        )
    ).block()

    println(response)
}

Messages must be an array of message objects, where each object has a role (either “system”, “user”, or “assistant”) and content (the content of the message). Conversations can be as short as 1 message or fill many pages. If a conversation cannot fit within the model’s token limit, it will need to be shortened in some way.

About

🔍 🌱 Kotlin spring starter implementation of chatGPT official api

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages