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

Multiple matching tables #2

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/Oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}