diff --git a/src/main/php/com/openai/realtime/RealtimeApi.class.php b/src/main/php/com/openai/realtime/RealtimeApi.class.php index 18469a4..e002f78 100644 --- a/src/main/php/com/openai/realtime/RealtimeApi.class.php +++ b/src/main/php/com/openai/realtime/RealtimeApi.class.php @@ -2,11 +2,11 @@ use com\openai\Tools; use com\openai\tools\Functions; -use lang\IllegalStateException; +use lang\{IllegalStateException, Value}; use text\json\Json; -use util\URI; use util\data\Marshalling; use util\log\Traceable; +use util\{Comparison, URI}; use websocket\WebSocket; /** @@ -17,7 +17,9 @@ * @test com.openai.unittest.RealtimeApiTest * @see https://platform.openai.com/docs/guides/realtime */ -class RealtimeApi implements Traceable { +class RealtimeApi implements Traceable, Value { + use Comparison; + private $ws, $marshalling; private $cat= null; @@ -117,4 +119,16 @@ public function transmit($payload) { public function __destruct() { $this->ws && $this->ws->close(); } + + /** @return string */ + public function toString() { + $socket= $this->ws->socket(); + return sprintf( + '%s(->wss://%s:%d%s)', + nameof($this), + $socket->host, + $socket->port, + $this->ws->path() + ); + } } \ No newline at end of file diff --git a/src/test/php/com/openai/unittest/AzureAIEndpointTest.class.php b/src/test/php/com/openai/unittest/AzureAIEndpointTest.class.php index 8a3d701..9d15a3e 100644 --- a/src/test/php/com/openai/unittest/AzureAIEndpointTest.class.php +++ b/src/test/php/com/openai/unittest/AzureAIEndpointTest.class.php @@ -28,4 +28,12 @@ public function version_extracted_from_uri() { public function api_key_header_set() { Assert::equals('1e51...', $this->fixture(self::URI)->headers()['API-Key']); } + + #[Test] + public function string_representation() { + Assert::equals( + 'com.openai.rest.AzureAIEndpoint(->https://test.openai.azure.com/openai/deployments/omni/?api-version=2024-02-01)', + $this->fixture(self::URI, '2024-02-01')->toString() + ); + } } \ No newline at end of file diff --git a/src/test/php/com/openai/unittest/OpenAIEndpointTest.class.php b/src/test/php/com/openai/unittest/OpenAIEndpointTest.class.php index ec813b3..2f9741a 100644 --- a/src/test/php/com/openai/unittest/OpenAIEndpointTest.class.php +++ b/src/test/php/com/openai/unittest/OpenAIEndpointTest.class.php @@ -37,4 +37,12 @@ public function optional_project_header() { $this->fixture(self::URI, 'org-test', 'prj-test')->headers()['OpenAI-Project'] ); } + + #[Test] + public function string_representation() { + Assert::equals( + 'com.openai.rest.OpenAIEndpoint(->https://api.openai.example.com/v1/)', + $this->fixture(self::URI)->toString() + ); + } } \ No newline at end of file diff --git a/src/test/php/com/openai/unittest/RealtimeApiTest.class.php b/src/test/php/com/openai/unittest/RealtimeApiTest.class.php index 86b4355..e42702a 100755 --- a/src/test/php/com/openai/unittest/RealtimeApiTest.class.php +++ b/src/test/php/com/openai/unittest/RealtimeApiTest.class.php @@ -5,6 +5,7 @@ use test\{Assert, Expect, Test, Values}; class RealtimeApiTest { + const URI= 'wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01'; const SESSION_CREATED= '{"type": "session.created"}'; /** Returns authentications */ @@ -15,7 +16,7 @@ private function authentications(): iterable { #[Test] public function can_create() { - new RealtimeApi('wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01'); + new RealtimeApi(self::URI); } #[Test] @@ -91,4 +92,12 @@ public function transmit() { Assert::equals(['type' => 'conversation.item.created'], $response); } + + #[Test] + public function string_representation() { + Assert::equals( + 'com.openai.realtime.RealtimeApi(->wss://api.openai.com:443/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01)', + (new RealtimeApi(self::URI))->toString() + ); + } } \ No newline at end of file