Closed JaredShay closed 7 months ago
This PR enables this kinda thing as needed I think. eg. if you set
OpenAI::Client.new do |client|
client.response :logger, ::Logger.new(STDOUT), bodies: true
end
ya get everything including
openai-version: "2020-10-01"
strict-transport-security: "max-age=15724800; includeSubDomains"
x-ratelimit-limit-requests: "3500"
x-ratelimit-limit-tokens: "90000"
x-ratelimit-remaining-requests: "3499"
x-ratelimit-remaining-tokens: "89980"
x-ratelimit-reset-requests: "17ms"
x-ratelimit-reset-tokens: "12ms"
That looks great. Allowing the ability to pass in middleware means anything can be modified. I can access the headers and set them as variables, add them to the response, log them, etc.
Absolutely solves my use case. Thanks for the quick reply.
@JaredShay Awesome, that's released in v6.3!
Responses contain a lot of information in headers.
These are not accessible as the response objects are json representations of the response body.
Having access to these values would be helpful to implement custom rate limiting without relying on parsing out values from error messages.
There are a few ways to do this:
include_headers
could be provided to the client interface. The response object could then contain a top level key with the headers (parsed into a usable format). This modifies the payload from the underlying service so it isn't a very clean solution.response.dig("choices", 0, "message", "function_call", "arguments")
when you're trying to fetch values from the payload