From 9668be99978f06ecd6c7262a2454ceb477296a14 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sun, 22 Sep 2024 22:25:05 +0200 Subject: [PATCH] refactor: rename supports methods (#13) * Rename method * refactor: supports method names --------- Co-authored-by: Christopher Hertel --- src/Anthropic/Model/Claude.php | 4 ++-- src/Chain.php | 4 ++-- src/LanguageModel.php | 4 ++-- src/OpenAI/Model/Gpt.php | 6 +++--- src/OpenAI/Model/Gpt/Version.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Anthropic/Model/Claude.php b/src/Anthropic/Model/Claude.php index 8cf1e619..4d456f1d 100644 --- a/src/Anthropic/Model/Claude.php +++ b/src/Anthropic/Model/Claude.php @@ -37,12 +37,12 @@ public function call(MessageBag $messages, array $options = []): Response return new Response(new Choice($response['content'][0]['text'])); } - public function hasToolSupport(): bool + public function supportsToolCalling(): bool { return false; // it does, but implementation here is still open. } - public function hasStructuredOutputSupport(): bool + public function supportsStructuredOutput(): bool { return false; } diff --git a/src/Chain.php b/src/Chain.php index 652274a3..381cbd65 100644 --- a/src/Chain.php +++ b/src/Chain.php @@ -27,11 +27,11 @@ public function call(MessageBag $messages, array $options = []): string|object { $llmOptions = $options; - if (!array_key_exists('tools', $llmOptions) && null !== $this->toolRegistry && $this->llm->hasToolSupport()) { + if (!array_key_exists('tools', $llmOptions) && null !== $this->toolRegistry && $this->llm->supportsToolCalling()) { $llmOptions['tools'] = $this->toolRegistry->getMap(); } - if (array_key_exists('output_structure', $llmOptions) && null !== $this->responseFormatFactory && $this->llm->hasStructuredOutputSupport()) { + if (array_key_exists('output_structure', $llmOptions) && null !== $this->responseFormatFactory && $this->llm->supportsStructuredOutput()) { $llmOptions['response_format'] = $this->responseFormatFactory->create($llmOptions['output_structure']); unset($llmOptions['output_structure']); } diff --git a/src/LanguageModel.php b/src/LanguageModel.php index a956f1e3..958493ed 100644 --- a/src/LanguageModel.php +++ b/src/LanguageModel.php @@ -14,7 +14,7 @@ interface LanguageModel */ public function call(MessageBag $messages, array $options = []): Response; - public function hasToolSupport(): bool; + public function supportsToolCalling(): bool; - public function hasStructuredOutputSupport(): bool; + public function supportsStructuredOutput(): bool; } diff --git a/src/OpenAI/Model/Gpt.php b/src/OpenAI/Model/Gpt.php index a34f1f7c..890e309e 100644 --- a/src/OpenAI/Model/Gpt.php +++ b/src/OpenAI/Model/Gpt.php @@ -34,14 +34,14 @@ public function call(MessageBag $messages, array $options = []): Response return new Response(...array_map([$this, 'convertChoice'], $response['choices'])); } - public function hasToolSupport(): bool + public function supportsToolCalling(): bool { return true; } - public function hasStructuredOutputSupport(): bool + public function supportsStructuredOutput(): bool { - return $this->version->hasStructuredOutputSupport(); + return $this->version->supportsStructuredOutput(); } /** diff --git a/src/OpenAI/Model/Gpt/Version.php b/src/OpenAI/Model/Gpt/Version.php index 1ed01228..8abd1bf7 100644 --- a/src/OpenAI/Model/Gpt/Version.php +++ b/src/OpenAI/Model/Gpt/Version.php @@ -13,7 +13,7 @@ enum Version: string case GPT_4o = 'gpt-4o'; case GPT_4o_MINI = 'gpt-4o-mini'; - public function hasStructuredOutputSupport(): bool + public function supportsStructuredOutput(): bool { return self::GPT_4o === $this || self::GPT_4o_MINI === $this; }