Skip to content

Commit

Permalink
add a start to few shot
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 27, 2023
1 parent 36d3166 commit 35c7422
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 5 additions & 6 deletions src/FewShotPromptTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

class FewShotPromptTemplate extends \Spatie\LaravelData\Data
{

/**
* @param PromptTemplate[] $promptTemplates
* @param PromptTemplate[] $promptTemplates
*/
public function __construct(
public array $promptTemplates,
public ?string $prefix,
public PromptTemplate $suffix,
)
{
) {

}

public function format(string $input) {
public function format(string $input)
{
$results = [];
$results[] = $this->prefix;

foreach($this->promptTemplates as $index => $promptTemplate) {
foreach ($this->promptTemplates as $index => $promptTemplate) {
$results[] = $promptTemplate->format();
}

Expand Down
16 changes: 6 additions & 10 deletions tests/FewShotPromptTemplateTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

use Sundance\LarachainPromptTemplates\FewShotPromptTemplate;
use function PHPUnit\Framework\assertEquals;
use Sundance\LarachainPromptTemplates\FewShotPromptTemplate;
use Sundance\LarachainPromptTemplates\Prompts\PromptToken;
use Sundance\LarachainPromptTemplates\PromptTemplate;

it('test few show', function () {
$prefix = "Give the antonym of every input";
$prefix = 'Give the antonym of every input';

$template = <<<EOD
$template = <<<'EOD'
Word: {word}
Antonym: {antonym}
EOD;
Expand Down Expand Up @@ -45,7 +45,6 @@
$template
);


$input_variables = [
new PromptToken(
'word',
Expand All @@ -57,9 +56,7 @@
),
];



$template = <<<EOD
$template = <<<'EOD'
Word: {word}
Antonym:
EOD;
Expand All @@ -72,7 +69,7 @@
$suffix
);

$expected = <<<EOD
$expected = <<<'EOD'
Give the antonym of every input
Word: happy
Antonym: sad
Expand All @@ -82,6 +79,5 @@
Antonym:
EOD;

assertEquals($expected, $dto->format("big"));
assertEquals($expected, $dto->format('big'));
});

1 change: 0 additions & 1 deletion tests/PromptTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
What is a good name for a company that makes colorful socks, colorful hats and colorful headbands?', $dto->format());
});


it('test no prompt', function () {
$template = <<<'EOD'
I want you to act as a naming consultant for new companies.
Expand Down

0 comments on commit 35c7422

Please sign in to comment.