Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit eae5785

Browse files
authored
Merge pull request #2 from tomlloyd/main
Multiple matching tables
2 parents 5b1d4b4 + 718cd21 commit eae5785

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Oracle.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,14 @@ protected function filterMatchingTables(string $question, array $tables): array
135135
]);
136136
$prompt = rtrim($prompt, PHP_EOL);
137137

138-
$matchingTables = $this->queryOpenAi($prompt, "\n");
138+
$matchingTablesResult = $this->queryOpenAi($prompt, "\n");
139139

140-
Str::of($matchingTables)
140+
$matchingTables = Str::of($matchingTablesResult)
141141
->explode(',')
142-
->transform(fn (string $tableName) => trim($tableName))
143-
->filter()
144-
->each(function (string $tableName) use (&$tables) {
145-
$tables = array_filter($tables, fn ($table) => strtolower($table->getName()) === strtolower($tableName));
146-
});
142+
->transform(fn (string $tableName) => strtolower(trim($tableName)));
147143

148-
return $tables;
144+
return collect($tables)->filter(function ($table) use ($matchingTables) {
145+
return $matchingTables->contains(strtolower($table->getName()));
146+
})->toArray();
149147
}
150148
}

0 commit comments

Comments
 (0)