Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make genai use common #86

Merged
merged 9 commits into from
Mar 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,20 @@ val JSON = Json {
* @property apiVersion the endpoint version to communicate with.
* @property timeout the maximum amount of time for a request to take in the initial exchange.
Comment on lines 64 to 65
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are out of date now, as they were moved to RequestOptions

*/
class APIController(
class APIController
internal constructor(
private val key: String,
model: String,
private val requestOptions: RequestOptions,
httpEngine: HttpClientEngine = OkHttp.create(),
httpEngine: HttpClientEngine
) {

constructor(
key: String,
model: String,
requestOptions: RequestOptions
) : this(key, model, requestOptions, OkHttp.create())

private val model = fullModelName(model)

private val client =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package com.google.ai.client.generativeai.common.util

// import com.google.ai.client.generativeai.internal.util.send
// import com.google.ai.client.generativeai.type.RequestOptions
import com.google.ai.client.generativeai.common.APIController
import com.google.ai.client.generativeai.common.GenerateContentRequest
import com.google.ai.client.generativeai.common.GenerateContentResponse
Expand Down
16 changes: 4 additions & 12 deletions generativeai/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ android {
}

dependencies {
val ktorVersion = "2.3.2"
implementation(project(":common"))

implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("androidx.core:core-ktx:1.12.0")
implementation("org.slf4j:slf4j-nop:2.0.9")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
Expand All @@ -92,10 +85,9 @@ dependencies {
implementation("androidx.concurrent:concurrent-futures:1.2.0-alpha02")
implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0-alpha02")
testImplementation("junit:junit:4.13.2")
testImplementation("io.kotest:kotest-assertions-core:4.0.7")
testImplementation("io.kotest:kotest-assertions-jvm:4.0.7")
testImplementation("io.kotest:kotest-assertions-json:4.0.7")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("io.kotest:kotest-assertions-core:5.5.5")
testImplementation("io.kotest:kotest-assertions-core-jvm:5.5.5")
testImplementation("io.mockk:mockk:1.13.10")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.google.ai.client.generativeai

import android.graphics.Bitmap
import com.google.ai.client.generativeai.internal.api.APIController
import com.google.ai.client.generativeai.internal.api.CountTokensRequest
import com.google.ai.client.generativeai.internal.api.GenerateContentRequest
import com.google.ai.client.generativeai.common.APIController
import com.google.ai.client.generativeai.common.CountTokensRequest
import com.google.ai.client.generativeai.common.GenerateContentRequest
import com.google.ai.client.generativeai.internal.util.toInternal
import com.google.ai.client.generativeai.internal.util.toPublic
import com.google.ai.client.generativeai.type.Content
Expand Down Expand Up @@ -71,7 +71,7 @@ internal constructor(
generationConfig,
safetySettings,
requestOptions,
APIController(apiKey, modelName, requestOptions)
APIController(apiKey, modelName, requestOptions.toInternal())
)

/**
Expand All @@ -97,8 +97,8 @@ internal constructor(
fun generateContentStream(vararg prompt: Content): Flow<GenerateContentResponse> =
controller
.generateContentStream(constructRequest(*prompt))
.map { it.toPublic().validate() }
.catch { throw GoogleGenerativeAIException.from(it) }
.map { it.toPublic().validate() }

/**
* Generates a response from the backend with the provided text represented [Content].
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading