Openai_ex - OpenAI API client library

@dlobo apologies for the delayed response. i only check the forum from time to time, so I didn’t see this. Apparently i only get immediate notifications if I am tagged in a message.

The library handles run status monitoring through streaming - just pass stream: true when creating a run. The response includes a body_stream field which is an Elixir Stream, allowing you to efficiently process run updates using Elixir’s Stream API for real-time monitoring.

If you need polling (in a non-streamed call), you can implement it using Runs.retrieve/2. Here’s a simple example:

def poll_run(openai, thread_id, run_id, interval \\ 1000) do
  case OpenaiEx.Beta.Threads.Runs.retrieve(openai, %{thread_id: thread_id, run_id: run_id}) do
    {:ok, %{"status" => status}} when status in ["completed", "failed", "cancelled", "expired"] ->
      {:done, status}
    {:ok, %{"status" => status}} ->
      Process.sleep(interval)
      poll_run(openai, thread_id, run_id, interval)
    error -> 
      error
  end
end

Let me know if you have any other questions. Please tag me so it doesn’t slip through the cracks again :wink: