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

[Bug]: Empty body in HttpTransporter::requestObject ($response->getBody()->getContents()) when using Guzzle client with Middleware::log() #432

Open
root-phpdev opened this issue Jun 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@root-phpdev
Copy link

Description

When using the Guzzle client and middleware to log requests/responses in the \Anthropic\Transporters\HttpTransporter::requestObject() method, when calling $response->getBody()->getContents() the result is an empty string. This is a well known old issue guzzle/guzzle#1582

and it produce an error: Syntax error

Perhaps to solve the problem it is worth using cast to string or calling the __toString() method or rewind body

Steps To Reproduce

$stack = HandlerStack::create();

$stack->push(Middleware::log(
    $this->logger,
    new MessageFormatter('{hostname} {req_header_User-Agent} - [{date_common_log}] "{method} {uri} HTTP/{version}" {code} {res_header_Content-Type} {res_header_Content-Length} {res_body}')
));

$httpClient = new \GuzzleHttp\Client([
    'handler' => $stack,
]);

$client = OpenAI::factory()
    ->withApiKey($apiKey)
    ->withHttpClient($httpClient)
    ->make();

OpenAI PHP Client Version

v0.8.5

PHP Version

8.1.20

Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant