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

Revamp OpenAI Client #697

Merged
merged 41 commits into from
Apr 1, 2024
Merged

Revamp OpenAI Client #697

merged 41 commits into from
Apr 1, 2024

Conversation

nomisRev
Copy link
Contributor

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 through HttpClient, and every individual method has a configure: 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 the KMMGenerator.
These return a Flow immediately, with the return type listed by streamingOps. That way it's easier to support custom data types like AssistantEvent. Streaming uses the same setup as we currently have.

In the case of a File it immediately returns Ktor's HttpResponse, and for input it uses the existing UploadFile.

The API is designed as discussed with Raul:

val openAI = OpenAI(...)
openAI.chat.createCompletion(..)
openAI.audio.createSpeech(...)

TODO:

  • FIT INTO XEF 😅

nomisRev and others added 30 commits March 21, 2024 14:19
…ient

# Conflicts:
#	evaluator-example/src/main/kotlin/com/xebia/functional/xef/evaluator/examples/TestExample.kt
@nomisRev nomisRev marked this pull request as ready for review March 27, 2024 18:10
@raulraja raulraja merged commit dc55080 into main Apr 1, 2024
6 checks passed
@raulraja raulraja deleted the simon-client branch April 1, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants