-
Notifications
You must be signed in to change notification settings - Fork 15
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
Revamp OpenAI Client #697
Merged
Merged
Revamp OpenAI Client #697
Conversation
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
…ient # Conflicts: # evaluator-example/src/main/kotlin/com/xebia/functional/xef/evaluator/examples/TestExample.kt
* 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
Montagon
approved these changes
Apr 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR revamps the OpenAI client, as discussed with @raulraja and @franciscodr.
The goal is to get rid of as much of maintenance, whilst getting as much for free as we can from the generator.
This PR takes a slightly different approach, it relies more on custom templating and less on "workarounds" for the templates.
By doing so we can also support
oneOf
by providing a template for it, since we are now writing our own template for Ktor and multiplatform we can focus exclusively on that and provide the nicest and most idiomatic out of the experience. Which means relying on Ktor types out-of-the-box where needed, and not use any abstractions in between.The PR also tries to solve several other problems, besides fixing the issues with generating the models (
oneOf
, and some edge cases).It also gives more powerful, and fine-grained control over the
HttpClient
. We offer a global configuration throughHttpClient
, and every individual method has aconfigure: HttpRequestBuilder.() -> Unit = {}
paramater that allows customising the global configuration but we still guarantee the correct configuration for every request (request details are not overridable).It also generates streaming functions, for those that are explicitly listed as supported
streamingOps
in theKMMGenerator
.These return a
Flow
immediately, with the return type listed bystreamingOps
. That way it's easier to support custom data types likeAssistantEvent
. Streaming uses the same setup as we currently have.In the case of a
File
it immediately returns Ktor'sHttpResponse
, and for input it uses the existingUploadFile
.The API is designed as discussed with Raul:
TODO: