-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0238af1
commit 51e4491
Showing
7 changed files
with
76 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: 'Prompts' | ||
docname: 'prompt_text' | ||
--- | ||
|
||
## Overview | ||
|
||
`Prompt` class in Instructor PHP provides a way to define and use | ||
prompt templates using Twig or Blade template syntax. | ||
|
||
|
||
## Example | ||
|
||
```php | ||
<?php | ||
$loader = require 'vendor/autoload.php'; | ||
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/'); | ||
|
||
use Cognesy\Instructor\Extras\Prompt\Prompt; | ||
use Cognesy\Instructor\Features\LLM\Inference; | ||
use Cognesy\Instructor\Utils\Str; | ||
|
||
// EXAMPLE 1: Simplfied API | ||
|
||
// use default template language, prompt files are in /prompts/twig/<prompt>.twig | ||
$prompt = Prompt::text('capital', ['country' => 'Germany']); | ||
$answer = (new Inference)->create(messages: $prompt)->toText(); | ||
|
||
echo "EXAMPLE 1: prompt = $prompt\n"; | ||
echo "ASSISTANT: $answer\n"; | ||
echo "\n"; | ||
assert(Str::contains($answer, 'Berlin')); | ||
|
||
// EXAMPLE 2: Define prompt template inline | ||
|
||
$prompt = Prompt::using('twig') | ||
->withTemplateContent('What is capital of {{country}}') | ||
->withValues(['country' => 'Germany']) | ||
->toText(); | ||
$answer = (new Inference)->create(messages: $prompt)->toText(); | ||
|
||
|
||
|
||
echo "EXAMPLE 2: prompt = $prompt\n"; | ||
echo "ASSISTANT: $answer\n"; | ||
echo "\n"; | ||
assert(Str::contains($answer, 'Berlin')); | ||
|
||
?> | ||
``` |
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
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