dvcrn / ex_openai

Auto-generated Elixir SDK for OpenAI APIs with full typespecs, docs and streaming support
MIT License
71 stars 27 forks source link

Adding support for new OpanAI API #25

Closed benitezhm closed 4 days ago

benitezhm commented 3 weeks ago

Trying to add new OpenAI API endpoints that are marked with "beta" as of right now

Hello, first of all, thanks for the library, it saved some time for me already, however, I noticed there is no support for the new OpenAI API, therefore I followed your instructions to update the docs.yaml and also found some problems with the auto-generation so, this is my attempt to fix it, can you please have a look and advise, I'm afraid I may have missed something, any feedback is welcome I can take care of the changes.

Also, I added a new configuration http_client to facilitate testing, in my case I use mox.

dvcrn commented 3 weeks ago

Thanks for taking the time to look into the generation!

I'm assuming that OpenAI changed the docs format again, that's why the conflicts. Let me take a look!

dvcrn commented 3 weeks ago

It looks like the tests are breaking, could you take a look?

benitezhm commented 2 weeks ago

I fixed the tests, however, I noticed that for allOf a better implementation is needed when converting the response, sadly my priorities changed right now, so I do not have much time to dedicate to this at the moment, but I did a quick fix, essentially I'm using the first component from the list of possible components to build the struct and this is the part that needs to be improved, if someone else can take it, it would be nice, if not perhaps I can retake it in the future.

dvcrn commented 2 weeks ago

Thanks for taking the time to fix this! I'll take a look and take it over from here :)

dbrody commented 6 days ago

This will support the beta endpoints such as File Search and Vector Stores? https://platform.openai.com/docs/assistants/tools/file-search/vector-stores

I would love to see that in this library!

dvcrn commented 5 days ago

Apologies for the delay. I've already started working on this, but it's usually after work in the evenings. Hope to have this merged by weekend :)

dvcrn commented 4 days ago

I'll fix the remaining items (parsing of types, assistant API in a separate PR).

I noticed that for allOf a better implementation is needed when converting the response

@benitezhm do you have an example of this happening?

dvcrn commented 4 days ago

Okay I fixed handling of oneOf types in return spec over in #26

iex(36)> h ExOpenAI.Audio.create_transcription

               def create_transcription(file, model, opts \\ [])                

  @spec create_transcription(
          bitstring() | {String.t(), bitstring()},
          :"whisper-1" | String.t(),
          openai_organization_key: String.t(),
          openai_api_key: String.t(),
          "timestamp_granularities[]": [:segment | :word],
          temperature: float(),
          response_format: :vtt | :verbose_json | :srt | :text | :json,
          prompt: String.t(),
          language: String.t(),
          stream_to: (... -> any()) | pid()
        ) ::
          {:ok,
           ExOpenAI.Components.CreateTranscriptionResponseVerboseJson.t()
           | ExOpenAI.Components.CreateTranscriptionResponseJson.t()}
          | {:error, any()}

however, doing this messes with LSP/ElixirSense, so we can no longer have autosuggestion for struct fields. Open to suggestions.

@dbrody When you have time, could you give #26 a go? I've never used File Search or Vector Store so I couldn't properly try (and write a test) for it yet

dvcrn commented 4 days ago

Alright, I've figured the proper way to represent oneOf in responses out:

{:ok, ExOpenAI.Components.CreateTranscriptionResponseVerboseJson.t()}
| {:ok, ExOpenAI.Components.CreateTranscriptionResponseJson.t()}
| {:error, any()}

I've merged everything back into master. Please give it a go, and if all is good we can cut a release