From dc136d7f4cfda12b49d7399c19dbdee8d19d3fdf Mon Sep 17 00:00:00 2001 From: Sejal Patel Date: Thu, 20 Feb 2025 11:42:56 -0500 Subject: [PATCH 1/3] Update to work with Google Gemini --- .../kotlin/com.aallam.openai.client/OpenAIConfig.kt | 5 +++++ .../kotlin/com.aallam.openai.api/chat/ChatCompletion.kt | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/openai-client/src/commonMain/kotlin/com.aallam.openai.client/OpenAIConfig.kt b/openai-client/src/commonMain/kotlin/com.aallam.openai.client/OpenAIConfig.kt index a3e20d7b..28a02a2c 100644 --- a/openai-client/src/commonMain/kotlin/com.aallam.openai.client/OpenAIConfig.kt +++ b/openai-client/src/commonMain/kotlin/com.aallam.openai.client/OpenAIConfig.kt @@ -99,6 +99,11 @@ public class OpenAIHost( */ public val OpenAI: OpenAIHost = OpenAIHost(baseUrl = "https://api.openai.com/v1/") + /** + * A pre-configured instance of [OpenAIHost] for Google Gemini`. + */ + public val Gemini: OpenAIHost = OpenAIHost(baseUrl = "https://generativelanguage.googleapis.com/v1beta/openai/") + /** * Creates an instance of [OpenAIHost] configured for Azure hosting with the given resource name, deployment ID, * and API version. diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt index eb0c94b8..e39e5a4f 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt @@ -15,7 +15,7 @@ public data class ChatCompletion( /** * A unique id assigned to this completion */ - @SerialName("id") public val id: String, + @SerialName("id") public val id: String? = null, // gemini doesn't provide back an id /** * The creation time in epoch milliseconds. */ @@ -43,4 +43,6 @@ public data class ChatCompletion( * might impact determinism. */ @SerialName("system_fingerprint") public val systemFingerprint: String? = null, + + @SerialName("citations") public val citations: List? = null, ) From 207b78f3894d61f3b7a37772ea6b2ce7dcce9358 Mon Sep 17 00:00:00 2001 From: Sejal Patel Date: Sun, 6 Apr 2025 15:17:39 -0400 Subject: [PATCH 2/3] Fix streaming nullable chat id support. Also added in citations to better handle perplexity's citations. --- .../kotlin/com.aallam.openai.api/chat/ChatCompletionChunk.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletionChunk.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletionChunk.kt index bdde1808..c4fe5364 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletionChunk.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletionChunk.kt @@ -16,7 +16,7 @@ public data class ChatCompletionChunk( * A unique id assigned to this completion */ @SerialName("id") - public val id: String, + public val id: String? = null, /** * The creation time in epoch milliseconds. @@ -48,4 +48,7 @@ public data class ChatCompletionChunk( */ @SerialName("system_fingerprint") public val systemFingerprint: String? = null, + + @SerialName("citations") + public val citations: List? = null, ) From 3d95bbad7a7548e2f2ed4cf0f5ead9ffb98d616b Mon Sep 17 00:00:00 2001 From: Sejal Patel Date: Sun, 4 May 2025 05:59:30 -0400 Subject: [PATCH 3/3] Allow for nullable id --- .../kotlin/com.aallam.openai.api/chat/ChatCompletion.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt index e39e5a4f..5f8285ae 100644 --- a/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt +++ b/openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletion.kt @@ -15,7 +15,7 @@ public data class ChatCompletion( /** * A unique id assigned to this completion */ - @SerialName("id") public val id: String? = null, // gemini doesn't provide back an id + @SerialName("id") public val idOrNull: String? = null, /** * The creation time in epoch milliseconds. */ @@ -45,4 +45,7 @@ public data class ChatCompletion( @SerialName("system_fingerprint") public val systemFingerprint: String? = null, @SerialName("citations") public val citations: List? = null, -) +) { + val id: String + get() = requireNotNull(idOrNull) +}