-
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.
* Working model gen, not correct package * Ktor API done * Clean-up, and add mapping from java.net.URI to String * Generate OpenAPI, Operation interfaces, and Remove Api Suffix * Clean-up generation * Remove redundant fixes * Add support for streaming * Remove redundant new lines in data class, fix JsName edge-case * Build similar smart constructor * Put back project * Clean-up * Few changes to progress with compilation * Xef builds with new generated client * fixes from main * Fixed assistant BETA headers * Update enum * Update enum as discussed with @raulraja * Value class serialization for running evaluator/TestExample * Add debugging tasks, and README.md * Small fixes, WIP deserialize enum * Fix paths * Apply spotless formatting * Fix vision examples * Update oneOf KSerializer * Apply spotless formatting * Add beta headers to assistant calls * Fix (query) parameter generation in api.mustache * Update oneOf names to CaseInnerType * Automatically add stream flag to JSON * Cleanup * Move generated source to build folder * Report all errors on oneOf * Make sure client is generated, when module is required as dependency * Attempt to fix build in CI for new OpenAI client (#709) * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build in CI * Attempt to fix build/release in CI --------- Co-authored-by: raulraja <raulraja@gmail.com>
- Loading branch information
Showing
354 changed files
with
10,965 additions
and
14,867 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,4 +148,6 @@ kotlin-js-store/ | |
|
||
.env | ||
|
||
*.bin | ||
*.bin | ||
model.log | ||
operations.log |
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
74 changes: 0 additions & 74 deletions
74
core/src/commonMain/kotlin/com/xebia/functional/xef/Audio.kt
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
core/src/commonMain/kotlin/com/xebia/functional/xef/Config.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,83 @@ | ||
package com.xebia.functional.xef | ||
|
||
import arrow.core.nonEmptyListOf | ||
import com.xebia.functional.openai.Config as OpenAIConfig | ||
import com.xebia.functional.openai.generated.api.OpenAI | ||
import com.xebia.functional.xef.env.getenv | ||
import io.ktor.client.* | ||
import io.ktor.client.engine.* | ||
import io.ktor.client.plugins.* | ||
import io.ktor.client.plugins.contentnegotiation.* | ||
import io.ktor.client.plugins.logging.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import io.ktor.serialization.kotlinx.json.* | ||
import kotlinx.serialization.json.Json | ||
|
||
data class Config( | ||
val baseUrl: String = getenv(HOST_ENV_VAR) ?: "https://api.openai.com/v1/", | ||
val token: String? = null, | ||
val org: String? = getenv(ORG_ENV_VAR), | ||
val json: Json = Json { | ||
ignoreUnknownKeys = true | ||
prettyPrint = true | ||
isLenient = true | ||
explicitNulls = false | ||
useArrayPolymorphism = true | ||
}, | ||
val streamingPrefix: String = "data:", | ||
val streamingDelimiter: String = "data: [DONE]" | ||
) | ||
|
||
private const val ORG_ENV_VAR = "OPENAI_ORG" | ||
private const val HOST_ENV_VAR = "OPENAI_HOST" | ||
private const val KEY_ENV_VAR = "OPENAI_TOKEN" | ||
|
||
/** | ||
* Constructor that mimics the behavior of "ApiClient", but without the additional layer in between. | ||
* Just simple fun on top of generated API. | ||
*/ | ||
fun OpenAI( | ||
config: Config = Config(), | ||
httpClientEngine: HttpClientEngine? = null, | ||
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null, | ||
logRequests: Boolean = false | ||
): OpenAI { | ||
val token = | ||
config.token | ||
?: getenv(KEY_ENV_VAR) | ||
?: throw AIError.Env.OpenAI(nonEmptyListOf("missing $KEY_ENV_VAR env var")) | ||
val clientConfig: HttpClientConfig<*>.() -> Unit = { | ||
install(ContentNegotiation) { json(config.json) } | ||
install(HttpTimeout) { | ||
requestTimeoutMillis = 45 * 1000 | ||
connectTimeoutMillis = 45 * 1000 | ||
socketTimeoutMillis = 45 * 1000 | ||
} | ||
install(HttpRequestRetry) { | ||
maxRetries = 5 | ||
retryIf { _, response -> !response.status.isSuccess() } | ||
retryOnExceptionIf { _, _ -> true } | ||
delayMillis { retry -> retry * 1000L } | ||
} | ||
install(Logging) { level = if (logRequests) LogLevel.ALL else LogLevel.NONE } | ||
httpClientConfig?.invoke(this) | ||
defaultRequest { | ||
url(config.baseUrl) | ||
config.org?.let { headers.append("org", it) } | ||
bearerAuth(token) | ||
} | ||
} | ||
val client = httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig) | ||
return OpenAI( | ||
client, | ||
OpenAIConfig( | ||
baseUrl = config.baseUrl, | ||
token = token, | ||
org = config.org, | ||
json = config.json, | ||
streamingPrefix = config.streamingPrefix, | ||
streamingDelimiter = config.streamingDelimiter | ||
) | ||
) | ||
} |
Oops, something went wrong.