Skip to content

Commit f31aa8a

Browse files
author
CptBronzebeard
committed
fix: allow creation of custom OpenAIClient without env variables
1 parent c8e692c commit f31aa8a

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

activators/llm/src/main/kotlin/com/justai/jaicf/activator/llm/action/LLMActionAPI.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ import com.justai.jaicf.context.BotContext
88
import com.openai.client.OpenAIClient
99
import com.openai.client.okhttp.OpenAIOkHttpClient
1010
import com.openai.core.http.StreamResponse
11+
import com.openai.credential.BearerTokenCredential
1112
import com.openai.models.chat.completions.ChatCompletionChunk
1213
import com.openai.models.chat.completions.ChatCompletionCreateParams
1314

1415

15-
private val DefaultOpenAIClient = OpenAIOkHttpClient.fromEnv()
16+
private val DefaultOpenAIClient = try {
17+
OpenAIOkHttpClient.fromEnv()
18+
} catch (_: IllegalStateException
19+
) {
20+
OpenAIOkHttpClient.builder().credential(BearerTokenCredential.create("")).build()
21+
}
1622
private val DefaultProps = LLMProps(
1723
client = DefaultOpenAIClient,
1824
withUsages = true,

activators/llm/src/main/kotlin/com/justai/jaicf/activator/llm/action/LLMActionContext.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import kotlinx.coroutines.launch
5656
import kotlinx.coroutines.runBlocking
5757
import kotlinx.coroutines.yield
5858
import java.util.stream.Stream
59-
import kotlin.coroutines.coroutineContext
6059
import kotlin.jvm.optionals.getOrDefault
6160
import kotlin.jvm.optionals.getOrNull
6261

@@ -116,7 +115,7 @@ data class LLMActionContext<A: ActivatorContext, B: BotRequest, R: Reactions>(
116115
)
117116
)
118117
}
119-
response = api.createStreaming(params)
118+
response = api.createStreaming(params, props.client)
120119
stream = response.stream()
121120
throwIfCancelled()
122121
}

0 commit comments

Comments
 (0)