Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openai-java-spring-boot-starter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test:2.7.18")
testImplementation("org.assertj:assertj-core:3.27.7")

constraints {
testImplementation("org.yaml:snakeyaml:2.6") {
because("avoid known vulnerabilities in Spring Boot's test dependency")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
package com.openai.springboot

import com.openai.client.OpenAIClient
import java.nio.charset.StandardCharsets
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.getBean
import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.env.YamlPropertySourceLoader
import org.springframework.boot.test.context.runner.ApplicationContextRunner
import org.springframework.core.io.ByteArrayResource

internal class OpenAIClientAutoConfigurationTest {

Expand Down Expand Up @@ -37,6 +40,36 @@ internal class OpenAIClientAutoConfigurationTest {
}
}

@Test
fun yamlProperties() {
val resource =
ByteArrayResource(
"""
openai:
base-url: https://api.openai.com/v1
api-key: YAML API Key
org-id: YAML Organization
"""
.trimIndent()
.toByteArray(StandardCharsets.UTF_8)
)
val propertySources = YamlPropertySourceLoader().load("test", resource)

contextRunner
.withInitializer { context ->
propertySources.reversed().forEach {
context.environment.propertySources.addFirst(it)
}
}
.run { context ->
val properties = context.getBean<OpenAIClientProperties>()
assertThat(properties.baseUrl).isEqualTo("https://api.openai.com/v1")
assertThat(properties.apiKey).isEqualTo("YAML API Key")
assertThat(properties.organization).isEqualTo("YAML Organization")
context.getBean<OpenAIClient>()
}
}

@Test
fun client() {
contextRunner
Expand Down
Loading