Created
May 16, 2023 04:09
-
-
Save iceener/1e4fadf19f58b669ae14edb9285c6c37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('../gpt3turbo.php'); | |
$question = 'what Buddha said about happines?'; | |
// wyciągamy słowa kluczowe | |
$keywords = $gpt3->query('return up to 2 keywords (only nouns) separated by spaces for this sentence: '.$question); | |
// jeśli GPT użyje kropki lub przecinka jako spearatora, to zmieniamy go na spację | |
$keywords = preg_replace('/[,.]+/',' ',$keywords); | |
// połączenie z bazą SQLite | |
$db = new SQLite3('brain.db'); | |
// wyciągamy pierwszy rekord, który pasuje do zapytania | |
$query = $db->query('select * from brain where body match(\\''.$keywords.'\\')'); | |
$row = $query->fetchArray(SQLITE3_ASSOC); | |
// prosimy GPT o odpowiedź na pytanie użytkownika na podstawie wyciągniętego kontekstu | |
$final = $gpt3->query("Answer following question using only context: | |
$question | |
### | |
Context: | |
{$row['body']}"); | |
echo $final; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment