-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic implementation of gcp embeddings via rest api (yet to be tested) * complete impl of gcp embeddings; add GCP_TOKEN env var * remove enum EmbeddingModel (no usages and not generic) * apply spotless * remove scala test for removed EmbeddingModel class * Update integrations/gcp/src/commonMain/kotlin/com/xebia/functional/xef/gcp/GcpChat.kt Co-authored-by: Raúl Raja Martínez <raulraja@gmail.com> * return token usage info for gcp embedding --------- Co-authored-by: ron <ron.spannagel@47deg.com> Co-authored-by: Raúl Raja Martínez <raulraja@gmail.com>
- Loading branch information
1 parent
547a1b2
commit fd12b91
Showing
13 changed files
with
139 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/embeddings/EmbeddingModel.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/gpc/Chat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
integrations/gcp/src/commonMain/kotlin/com/xebia/functional/xef/gcp/GcpEmbeddings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.xebia.functional.xef.gcp | ||
|
||
import arrow.fx.coroutines.parMap | ||
import com.xebia.functional.xef.embeddings.Embedding | ||
import com.xebia.functional.xef.embeddings.Embeddings | ||
import com.xebia.functional.xef.llm.models.embeddings.EmbeddingRequest | ||
import com.xebia.functional.xef.llm.models.embeddings.RequestConfig | ||
|
||
class GcpEmbeddings(private val gcpClient: com.xebia.functional.xef.llm.Embeddings) : Embeddings { | ||
override suspend fun embedDocuments( | ||
texts: List<String>, | ||
chunkSize: Int?, | ||
requestConfig: RequestConfig | ||
): List<Embedding> { | ||
suspend fun createEmbeddings(texts: List<String>): List<Embedding> { | ||
val req = EmbeddingRequest(gcpClient.name, texts, requestConfig.user.id) | ||
return gcpClient.createEmbeddings(req).data.map { Embedding(it.embedding) } | ||
} | ||
val lists: List<List<Embedding>> = | ||
if (texts.isEmpty()) emptyList() | ||
else texts.chunked(chunkSize ?: 400).parMap { createEmbeddings(it) } | ||
return lists.flatten() | ||
} | ||
|
||
override suspend fun embedQuery(text: String, requestConfig: RequestConfig): List<Embedding> = | ||
if (text.isNotEmpty()) embedDocuments(listOf(text), null, requestConfig) else emptyList() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
scala/src/test/scala/com/xebia/functional/xef/llm/models/embeddings/RequestConfigSpec.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters