php-llm-agent/tests/04_RecursiveQueries_ProduceLongContent.php
2025-09-11 10:58:00 +00:00

41 lines
1.5 KiB
PHP

<?php require_once __DIR__."/../LlamaCli.func.php";
// TEST 04: RECURSIVE QUERY, to produce long-content from short-one. LONG-WRITING. ( GOAL: Learning from model deep knowledge )
// -------- BOOK EXAMPLE ---------
// 0. CATEGORY
$category = "learning finnish";
$expert = "teacher";
$total_no_of_chapters = 3;
// 1. TITLE
$book_title = LlamaCli_raw("Write me a title for my new book about $category. Output title only, no options, no chat.","You are an expert $expert.");
// 2. CHAPTER TITLES
$sys_msg = "You are an expert $expert writing a book with the title $book_title with $total_no_of_chapters chapters";
$chapters = []; $conv_hist = [];
$msg = "Write me the title of my first chapter. Output title only, no options, no chat.";
$conv_hist[] = ["role"=>"user","content"=>$msg];
$conv_hist[] = ["role"=>"assistant","content"=>($chapters[] = LlamaCli_raw($msg,$sys_msg,["debug_level"=>0]))];
for($no=1; $no < $total_no_of_chapters; $no++) {
$msg = "Write me the title of chapter number $no.";
$conv_hist[] = ["role"=>"user","content"=>$msg];
$conv_hist[] = ["role"=>"assistant","content"=>($chapters[] = LlamaCli_raw($msg,$sys_msg,["previousConversation"=>$conv_hist, "debug_level"=>0]))];
}
// 3. CHAPTER CONTENTS
$content = [];
foreach($chapters as $chapter_title)
$content[$chapter_title] = LlamaCli_raw(
"Write 2 paragraphs for a chapter titled $chapter_title in a book called $book_title. Output content only, no chat.",
"You are an expert $expert."
);
print_r([$book_title, $content]);