Skip to content

Commit

Permalink
Migrate model name to APIController
Browse files Browse the repository at this point in the history
  • Loading branch information
daymxn committed Dec 19, 2023
1 parent 650801b commit 4786338
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ internal constructor(
apiKey: String,
generationConfig: GenerationConfig? = null,
safetySettings: List<SafetySetting>? = null,
) : this(
modelName,
apiKey,
generationConfig,
safetySettings,
APIController(apiKey, fullModelName(modelName))
)
) : this(modelName, apiKey, generationConfig, safetySettings, APIController(apiKey, modelName))

/**
* Generates a response from the backend with the provided [Content]s.
Expand Down Expand Up @@ -188,11 +182,3 @@ internal constructor(
?.let { throw ResponseStoppedException(this) }
}
}

/**
* Ensures the model name provided has a `models/` prefix
*
* Models must be prepended with the `models/` prefix when communicating with the backend.
*/
private fun fullModelName(name: String): String =
name.takeIf { it.startsWith("models/") } ?: "models/$name"
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ internal val JSON = Json {
*/
internal class APIController(
private val key: String,
private val model: String,
model: String,
httpEngine: HttpClientEngine = OkHttp.create()
) {
private val model = fullModelName(model)

private val client =
HttpClient(httpEngine) {
install(HttpTimeout) {
Expand Down Expand Up @@ -106,6 +108,14 @@ internal class APIController(
}
}

/**
* Ensures the model name provided has a `models/` prefix
*
* Models must be prepended with the `models/` prefix when communicating with the backend.
*/
private fun fullModelName(name: String): String =
name.takeIf { it.startsWith("models/") } ?: "models/$name"

/**
* Makes a POST request to the specified [url] and returns a [Flow] of deserialized response objects
* of type [R]. The response is expected to be a stream of JSON objects that are parsed in real-time
Expand Down

0 comments on commit 4786338

Please sign in to comment.