-
Notifications
You must be signed in to change notification settings - Fork 0
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
ed6f622
commit 5d4045a
Showing
3 changed files
with
65 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Danny50610\BpeTokeniser\Tests; | ||
|
||
use Danny50610\BpeTokeniser\EncodingFactory; | ||
use InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class EncodingFactoryTest extends TestCase | ||
{ | ||
public function testCreateByEncodingName() | ||
{ | ||
$enc = EncodingFactory::createByEncodingName('cl100k_base'); | ||
|
||
$this->assertSame('cl100k_base', $enc->getName()); | ||
} | ||
|
||
public function testCreateByEncodingNameWithNonExist() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Unknown encoding: "danny"'); | ||
|
||
EncodingFactory::createByEncodingName('danny'); | ||
} | ||
|
||
public function testCreateByModelName() | ||
{ | ||
$enc = EncodingFactory::createByModelName('gpt-4'); | ||
|
||
$this->assertSame('cl100k_base', $enc->getName()); | ||
} | ||
|
||
public function testCreateByModelNameUsePrefix() | ||
{ | ||
$enc = EncodingFactory::createByModelName('gpt-3.5-turbo-0301'); | ||
|
||
$this->assertSame('cl100k_base', $enc->getName()); | ||
} | ||
|
||
public function testCreateByModelNameWithNonExist() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Could not automatically map "danny" to a tokeniser. Please use `createByEncodingName` to explicitly get the tokeniser you expect.'); | ||
|
||
EncodingFactory::createByModelName('danny'); | ||
} | ||
} |