From 718cd219cff24dd738a9ef147572d7238205644d Mon Sep 17 00:00:00 2001 From: Tom Lloyd Date: Mon, 6 Mar 2023 22:49:58 +0000 Subject: [PATCH] Multiple matching tables --- src/Oracle.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Oracle.php b/src/Oracle.php index 7c26a65..8094fee 100755 --- a/src/Oracle.php +++ b/src/Oracle.php @@ -135,16 +135,14 @@ protected function filterMatchingTables(string $question, array $tables): array ]); $prompt = rtrim($prompt, PHP_EOL); - $matchingTables = $this->queryOpenAi($prompt, "\n"); + $matchingTablesResult = $this->queryOpenAi($prompt, "\n"); - Str::of($matchingTables) + $matchingTables = Str::of($matchingTablesResult) ->explode(',') - ->transform(fn (string $tableName) => trim($tableName)) - ->filter() - ->each(function (string $tableName) use (&$tables) { - $tables = array_filter($tables, fn ($table) => strtolower($table->getName()) === strtolower($tableName)); - }); + ->transform(fn (string $tableName) => strtolower(trim($tableName))); - return $tables; + return collect($tables)->filter(function ($table) use ($matchingTables) { + return $matchingTables->contains(strtolower($table->getName())); + })->toArray(); } }