ahmadrosid / anthropic-php

Anthropic PHP Client
MIT License
7 stars 0 forks source link

Response for ToolUse in CreateResponseMessage #1

Open wgerick opened 1 month ago

wgerick commented 1 month ago

Thanks for your anthropic client. I assume, you left out tool calls for your client.

When you provide tools for claude to use, the response content will not contain a "text" attribute, but the attributes for the tool, therefor "id", "name" and "input". This will break your implementation:

`?php

namespace Anthropic\Response;

final class CreateResponseMessage {

private function __construct(
    public readonly string $type,
    public readonly string $content,
) {
}

public static function from(array $attributes)
{
    return new self(
        $attributes['type'],
        $attributes['text'],
    );
}

public function toArray() 
{
    return [
        'type' => $this->type,
        'content' => $this->content,
    ];
}

}`

Here is the OpenAi PHP CreateMessageResponse equivalent: https://github.com/openai-php/client/blob/main/src/Responses/Chat/CreateResponseMessage.php

ahmadrosid commented 1 month ago

I haven't implemented the tool call yet. Feel free to create a pull request to implement it.