From 841075569e37033fc9ab94d7cf1ef1007fff09d5 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Mon, 6 Oct 2025 23:32:24 +0200 Subject: [PATCH] Adopt asX methods of result for better type support --- examples/aimlapi/chat.php | 2 +- examples/aimlapi/image-input-binary.php | 2 +- examples/albert/chat.php | 2 +- examples/anthropic/chat.php | 2 +- examples/anthropic/image-input-binary.php | 2 +- examples/anthropic/image-input-url.php | 2 +- examples/anthropic/pdf-input-binary.php | 2 +- examples/anthropic/pdf-input-url.php | 2 +- examples/azure/chat-gpt.php | 2 +- examples/azure/chat-llama.php | 2 +- examples/bedrock/chat-claude.php | 2 +- examples/bedrock/chat-llama.php | 2 +- examples/bedrock/chat-nova.php | 2 +- examples/bedrock/image-claude-binary.php | 2 +- examples/bedrock/image-nova.php | 2 +- examples/bootstrap.php | 2 +- examples/cerebras/chat.php | 2 +- examples/gemini/audio-input.php | 2 +- examples/gemini/chat.php | 2 +- examples/gemini/image-input.php | 2 +- examples/gemini/pdf-input-binary.php | 2 +- examples/lmstudio/chat.php | 2 +- examples/lmstudio/image-input-binary.php | 2 +- examples/mistral/chat-multiple.php | 2 +- examples/mistral/chat.php | 2 +- examples/mistral/image.php | 2 +- examples/mistral/pdf-input-binary.php | 2 +- examples/mistral/pdf-input-url.php | 2 +- examples/ollama/chat-llama.php | 2 +- examples/openai/audio-input.php | 2 +- examples/openai/chat-with-string-options.php | 2 +- examples/openai/chat.php | 2 +- examples/openai/image-input-binary.php | 2 +- examples/openai/image-input-url.php | 2 +- examples/openai/pdf-input-binary.php | 2 +- examples/openrouter/chat-gemini.php | 2 +- examples/perplexity/chat.php | 4 ++-- examples/perplexity/disable-search.php | 4 ++-- examples/perplexity/web-search.php | 4 ++-- examples/replicate/chat-llama.php | 2 +- examples/scaleway/stream.php | 2 +- examples/scaleway/vision.php | 2 +- examples/vertexai/audio-input.php | 2 +- examples/vertexai/chat.php | 2 +- examples/vertexai/image-input.php | 2 +- examples/vertexai/pdf-input-binary.php | 2 +- examples/vertexai/server-tools.php | 2 +- 47 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/aimlapi/chat.php b/examples/aimlapi/chat.php index 9265f2eaa..84ccfb862 100644 --- a/examples/aimlapi/chat.php +++ b/examples/aimlapi/chat.php @@ -25,4 +25,4 @@ 'max_tokens' => 500, // specific options just for this call ]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/aimlapi/image-input-binary.php b/examples/aimlapi/image-input-binary.php index 7362681e2..646c647e3 100644 --- a/examples/aimlapi/image-input-binary.php +++ b/examples/aimlapi/image-input-binary.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('google/gemma-3-27b-it', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/albert/chat.php b/examples/albert/chat.php index 9a30ed73e..dd7e42747 100644 --- a/examples/albert/chat.php +++ b/examples/albert/chat.php @@ -41,4 +41,4 @@ $result = $platform->invoke('llama-3.3-70b-instruct', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/anthropic/chat.php b/examples/anthropic/chat.php index 979d25fdf..68de4b06b 100644 --- a/examples/anthropic/chat.php +++ b/examples/anthropic/chat.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('claude-3-5-sonnet-20241022', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/anthropic/image-input-binary.php b/examples/anthropic/image-input-binary.php index 2ffb2bb36..2c412fee5 100644 --- a/examples/anthropic/image-input-binary.php +++ b/examples/anthropic/image-input-binary.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('claude-3-5-sonnet-20241022', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/anthropic/image-input-url.php b/examples/anthropic/image-input-url.php index f08fa83bb..4c1d88d20 100644 --- a/examples/anthropic/image-input-url.php +++ b/examples/anthropic/image-input-url.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('claude-3-5-sonnet-20241022', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/anthropic/pdf-input-binary.php b/examples/anthropic/pdf-input-binary.php index b93975906..326cd85f5 100644 --- a/examples/anthropic/pdf-input-binary.php +++ b/examples/anthropic/pdf-input-binary.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('claude-3-5-sonnet-20241022', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/anthropic/pdf-input-url.php b/examples/anthropic/pdf-input-url.php index 9276a1edc..afc9f0b86 100644 --- a/examples/anthropic/pdf-input-url.php +++ b/examples/anthropic/pdf-input-url.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('claude-3-5-sonnet-20241022', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/azure/chat-gpt.php b/examples/azure/chat-gpt.php index 2ee4b4413..494abbb67 100644 --- a/examples/azure/chat-gpt.php +++ b/examples/azure/chat-gpt.php @@ -28,4 +28,4 @@ ); $result = $platform->invoke('gpt-4o-mini', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/azure/chat-llama.php b/examples/azure/chat-llama.php index a8c34c39a..375c4c360 100644 --- a/examples/azure/chat-llama.php +++ b/examples/azure/chat-llama.php @@ -26,4 +26,4 @@ 'frequency_penalty' => 0, ]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bedrock/chat-claude.php b/examples/bedrock/chat-claude.php index 594342eb4..706410515 100644 --- a/examples/bedrock/chat-claude.php +++ b/examples/bedrock/chat-claude.php @@ -29,4 +29,4 @@ ); $result = $platform->invoke('claude-3-7-sonnet-20250219', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bedrock/chat-llama.php b/examples/bedrock/chat-llama.php index 4ebceda3f..ff9e85a57 100644 --- a/examples/bedrock/chat-llama.php +++ b/examples/bedrock/chat-llama.php @@ -29,4 +29,4 @@ ); $result = $platform->invoke('llama-3.2-3b-instruct', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bedrock/chat-nova.php b/examples/bedrock/chat-nova.php index f5db0923e..79b5bbb2e 100644 --- a/examples/bedrock/chat-nova.php +++ b/examples/bedrock/chat-nova.php @@ -29,4 +29,4 @@ ); $result = $platform->invoke('nova-pro', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bedrock/image-claude-binary.php b/examples/bedrock/image-claude-binary.php index 85fe32f9c..72037c2aa 100644 --- a/examples/bedrock/image-claude-binary.php +++ b/examples/bedrock/image-claude-binary.php @@ -33,4 +33,4 @@ ); $result = $platform->invoke('claude-3-7-sonnet-20250219', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bedrock/image-nova.php b/examples/bedrock/image-nova.php index 253a2afc4..5f3561c79 100644 --- a/examples/bedrock/image-nova.php +++ b/examples/bedrock/image-nova.php @@ -33,4 +33,4 @@ ); $result = $platform->invoke('nova-pro', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/bootstrap.php b/examples/bootstrap.php index a489578b1..de9440a50 100644 --- a/examples/bootstrap.php +++ b/examples/bootstrap.php @@ -180,7 +180,7 @@ function perplexity_print_citations(Metadata $metadata): void function print_stream(ResultPromise $result): void { - foreach ($result->getResult()->getContent() as $word) { + foreach ($result->asStream() as $word) { echo $word; } echo \PHP_EOL; diff --git a/examples/cerebras/chat.php b/examples/cerebras/chat.php index a6ccfa797..86e9f0b2c 100644 --- a/examples/cerebras/chat.php +++ b/examples/cerebras/chat.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('llama3.1-8b', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/gemini/audio-input.php b/examples/gemini/audio-input.php index 9a975936f..d38ea27e3 100644 --- a/examples/gemini/audio-input.php +++ b/examples/gemini/audio-input.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gemini-1.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/gemini/chat.php b/examples/gemini/chat.php index b1e8aefba..0890f79ae 100644 --- a/examples/gemini/chat.php +++ b/examples/gemini/chat.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('gemini-2.0-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/gemini/image-input.php b/examples/gemini/image-input.php index d3b2aede2..3fa400ef9 100644 --- a/examples/gemini/image-input.php +++ b/examples/gemini/image-input.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('gemini-1.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/gemini/pdf-input-binary.php b/examples/gemini/pdf-input-binary.php index 316fef388..d15f0e1dd 100644 --- a/examples/gemini/pdf-input-binary.php +++ b/examples/gemini/pdf-input-binary.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gemini-1.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/lmstudio/chat.php b/examples/lmstudio/chat.php index 4dd26f720..38aa2705c 100644 --- a/examples/lmstudio/chat.php +++ b/examples/lmstudio/chat.php @@ -25,4 +25,4 @@ 'max_tokens' => 500, // specific options just for this call ]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/lmstudio/image-input-binary.php b/examples/lmstudio/image-input-binary.php index 0d7ba8e52..9b66882dc 100644 --- a/examples/lmstudio/image-input-binary.php +++ b/examples/lmstudio/image-input-binary.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('gemma-3-4b-it-qat', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/mistral/chat-multiple.php b/examples/mistral/chat-multiple.php index ae731fc6e..03ff427a3 100644 --- a/examples/mistral/chat-multiple.php +++ b/examples/mistral/chat-multiple.php @@ -26,6 +26,6 @@ 'n' => 10, ]); -foreach ($result->getResult()->getContent() as $key => $choice) { +foreach ($result->asStream() as $key => $choice) { echo sprintf('Choice #%d: %s', ++$key, $choice->getContent()).\PHP_EOL; } diff --git a/examples/mistral/chat.php b/examples/mistral/chat.php index c96b08932..0f03371ca 100644 --- a/examples/mistral/chat.php +++ b/examples/mistral/chat.php @@ -22,4 +22,4 @@ 'temperature' => 0.7, ]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/mistral/image.php b/examples/mistral/image.php index a17b178ab..fafa8cdb1 100644 --- a/examples/mistral/image.php +++ b/examples/mistral/image.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('mistral-small-latest', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/mistral/pdf-input-binary.php b/examples/mistral/pdf-input-binary.php index 81eabc1d2..fd8226c2c 100644 --- a/examples/mistral/pdf-input-binary.php +++ b/examples/mistral/pdf-input-binary.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('mistral-small-latest', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/mistral/pdf-input-url.php b/examples/mistral/pdf-input-url.php index 37b6fe32a..1c2fb6206 100644 --- a/examples/mistral/pdf-input-url.php +++ b/examples/mistral/pdf-input-url.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('mistral-small-latest', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/ollama/chat-llama.php b/examples/ollama/chat-llama.php index 2f4f82316..8d02b0215 100644 --- a/examples/ollama/chat-llama.php +++ b/examples/ollama/chat-llama.php @@ -24,7 +24,7 @@ try { $result = $platform->invoke(env('OLLAMA_LLM'), $messages); - echo $result->getResult()->getContent().\PHP_EOL; + echo $result->asText().\PHP_EOL; } catch (InvalidArgumentException $e) { echo $e->getMessage()."\nMaybe use a different model?\n"; } diff --git a/examples/openai/audio-input.php b/examples/openai/audio-input.php index 5440fd751..9022cc912 100644 --- a/examples/openai/audio-input.php +++ b/examples/openai/audio-input.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gpt-4o-audio-preview', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openai/chat-with-string-options.php b/examples/openai/chat-with-string-options.php index 729ce0b69..878f1ac97 100644 --- a/examples/openai/chat-with-string-options.php +++ b/examples/openai/chat-with-string-options.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('gpt-4o-mini?max_tokens=7', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openai/chat.php b/examples/openai/chat.php index 298d753d4..b1ab48cf7 100644 --- a/examples/openai/chat.php +++ b/examples/openai/chat.php @@ -25,4 +25,4 @@ 'max_tokens' => 500, // specific options just for this call ]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openai/image-input-binary.php b/examples/openai/image-input-binary.php index bf14a7829..1de00516c 100644 --- a/examples/openai/image-input-binary.php +++ b/examples/openai/image-input-binary.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('gpt-4o-mini', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openai/image-input-url.php b/examples/openai/image-input-url.php index cabc35cc9..8988a5072 100644 --- a/examples/openai/image-input-url.php +++ b/examples/openai/image-input-url.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('gpt-4o-mini', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openai/pdf-input-binary.php b/examples/openai/pdf-input-binary.php index 305eb6cc7..c1946557a 100644 --- a/examples/openai/pdf-input-binary.php +++ b/examples/openai/pdf-input-binary.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gpt-4o-mini', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/openrouter/chat-gemini.php b/examples/openrouter/chat-gemini.php index 0c79c0e01..699341e42 100644 --- a/examples/openrouter/chat-gemini.php +++ b/examples/openrouter/chat-gemini.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke($model, $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/perplexity/chat.php b/examples/perplexity/chat.php index 0b62e607a..d4aa32b94 100644 --- a/examples/perplexity/chat.php +++ b/examples/perplexity/chat.php @@ -18,6 +18,6 @@ $platform = PlatformFactory::create(env('PERPLEXITY_API_KEY'), http_client()); $messages = new MessageBag(Message::ofUser('What is the best French cheese?')); -$response = $platform->invoke('sonar', $messages); +$result = $platform->invoke('sonar', $messages); -echo $response->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/perplexity/disable-search.php b/examples/perplexity/disable-search.php index 5cf4d7bb9..79db584f9 100644 --- a/examples/perplexity/disable-search.php +++ b/examples/perplexity/disable-search.php @@ -18,8 +18,8 @@ $platform = PlatformFactory::create(env('PERPLEXITY_API_KEY'), http_client()); $messages = new MessageBag(Message::ofUser('What is 2 + 2?')); -$response = $platform->invoke('sonar', $messages, [ +$result = $platform->invoke('sonar', $messages, [ 'disable_search' => true, ]); -echo $response->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/perplexity/web-search.php b/examples/perplexity/web-search.php index d4d0fcfab..41bc659e0 100644 --- a/examples/perplexity/web-search.php +++ b/examples/perplexity/web-search.php @@ -18,7 +18,7 @@ $platform = PlatformFactory::create(env('PERPLEXITY_API_KEY'), http_client()); $messages = new MessageBag(Message::ofUser('What is the best French cheese?')); -$response = $platform->invoke('sonar', $messages, [ +$result = $platform->invoke('sonar', $messages, [ 'search_domain_filter' => [ 'https://en.wikipedia.org/wiki/Cheese', ], @@ -27,4 +27,4 @@ 'search_recency_filter' => 'week', ]); -echo $response->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/replicate/chat-llama.php b/examples/replicate/chat-llama.php index 4dd371472..632fff9f1 100644 --- a/examples/replicate/chat-llama.php +++ b/examples/replicate/chat-llama.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('llama-3.1-405b-instruct', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/scaleway/stream.php b/examples/scaleway/stream.php index 7192bb14a..54042eaf7 100644 --- a/examples/scaleway/stream.php +++ b/examples/scaleway/stream.php @@ -23,7 +23,7 @@ ); $result = $platform->invoke('gpt-oss-120b', $messages, ['stream' => true]); -foreach ($result->getResult()->getContent() as $word) { +foreach ($result->asStream() as $word) { echo $word; } echo \PHP_EOL; diff --git a/examples/scaleway/vision.php b/examples/scaleway/vision.php index 378165ac6..a98e7253e 100644 --- a/examples/scaleway/vision.php +++ b/examples/scaleway/vision.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('pixtral-12b-2409', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/vertexai/audio-input.php b/examples/vertexai/audio-input.php index b2c26ea16..7cc5dea59 100644 --- a/examples/vertexai/audio-input.php +++ b/examples/vertexai/audio-input.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gemini-2.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/vertexai/chat.php b/examples/vertexai/chat.php index eace1c4ad..25e2ca5d1 100644 --- a/examples/vertexai/chat.php +++ b/examples/vertexai/chat.php @@ -23,4 +23,4 @@ ); $result = $platform->invoke('gemini-2.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/vertexai/image-input.php b/examples/vertexai/image-input.php index 31fe1b29f..6737af2a6 100644 --- a/examples/vertexai/image-input.php +++ b/examples/vertexai/image-input.php @@ -27,4 +27,4 @@ ); $result = $platform->invoke('gemini-2.5-pro', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/vertexai/pdf-input-binary.php b/examples/vertexai/pdf-input-binary.php index 25ebe67ad..79dc7a8ff 100644 --- a/examples/vertexai/pdf-input-binary.php +++ b/examples/vertexai/pdf-input-binary.php @@ -26,4 +26,4 @@ ); $result = $platform->invoke('gemini-2.5-flash', $messages); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL; diff --git a/examples/vertexai/server-tools.php b/examples/vertexai/server-tools.php index 10a2e1734..eea527b21 100644 --- a/examples/vertexai/server-tools.php +++ b/examples/vertexai/server-tools.php @@ -27,4 +27,4 @@ $result = $platform->invoke('gemini-2.5-pro', $messages, ['server_tools' => ['url_context' => true]]); -echo $result->getResult()->getContent().\PHP_EOL; +echo $result->asText().\PHP_EOL;