Skip to content

Commit 72b30d7

Browse files
committed
add organization support to ChatBot
1 parent 8c3bc76 commit 72b30d7

File tree

1 file changed

+3
-0
lines changed
  • src/main/kotlin/com/cjcrafter/openai/chat

1 file changed

+3
-0
lines changed

src/main/kotlin/com/cjcrafter/openai/chat/ChatBot.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import java.util.function.Consumer
3131
* to the API dashboard, where you can find your unique API key. Copy and store it securely.
3232
*
3333
* @property apiKey Your OpenAI API key. It starts with `"sk-"` (without the quotes).
34+
* @property organization If you belong to multiple organizations, specify which one to use (else `null`).
3435
* @property client Controls proxies, timeouts, etc.
3536
* @constructor Create a ChatBot for responding to requests.
3637
*/
3738
class ChatBot @JvmOverloads constructor(
3839
private val apiKey: String,
40+
private val organization: String? = null,
3941
private val client: OkHttpClient = OkHttpClient()
4042
) {
4143

@@ -51,6 +53,7 @@ class ChatBot @JvmOverloads constructor(
5153
.url("https://api.openai.com/v1/chat/completions")
5254
.addHeader("Content-Type", "application/json")
5355
.addHeader("Authorization", "Bearer $apiKey")
56+
.apply { if (organization != null) addHeader("OpenAI-Organization", organization) }
5457
.post(body).build()
5558
}
5659

0 commit comments

Comments
 (0)