Skip to content

Instantly share code, notes, and snippets.

@iceener
Created May 16, 2023 04:09
Show Gist options
  • Save iceener/1e4fadf19f58b669ae14edb9285c6c37 to your computer and use it in GitHub Desktop.
Save iceener/1e4fadf19f58b669ae14edb9285c6c37 to your computer and use it in GitHub Desktop.
<?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