aallam / openai-kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.
MIT License
1.44k stars 168 forks source link

Unable to integrate the library in a Kotlin springboot project #288

Open swapnilgt opened 9 months ago

swapnilgt commented 9 months ago

Description

Trying to setup a Kotlin sprint boot project. Added the required libraries as dependencies. Unable to import the OpenAI class in my class. The IDE cannot find the class.

Steps to Reproduce

  1. Create a basic Sprint project from https://start.spring.io/ . Choose Gradle - Kotlin, Kotlin Language, Jar Packaging and Java 17
  2. Import the required libraries in the gradle script. Here is the gradle script
    
    import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins { id("org.springframework.boot") version "3.2.1" id("io.spring.dependency-management") version "1.1.4" kotlin("jvm") version "1.9.21" kotlin("plugin.spring") version "1.9.21" }

group = "com.ultgpts.rechargegpt" version = "0.0.1-SNAPSHOT"

java { sourceCompatibility = JavaVersion.VERSION_17 }

repositories { mavenCentral() }

dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib") implementation("com.aallam.openai:openai-client:3.6.2") implementation("io.ktor:ktor-client-java:2.3.2")

testImplementation("org.springframework.boot:spring-boot-starter-test")

}

tasks.withType { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" jvmTarget = "17" } }

tasks.withType { useJUnitPlatform() }



4. Create a new class and try to import the `OpenAI` class. Unless to import the calls

### Environment

- **openai-kotlin version 3.6.2**
- **Kotlin version**: 1.9.21
- **OS**: macOS

### Additional Info

Not sure what am I missing here.
aallam commented 9 months ago

I've followed the same steps and didn't encounter any issues. I believe this might be related to your IDE, possibly involving the cache, Gradle cache, etc.