-
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.
Merge pull request #1 from xp-forge/feature/integration-tests
Add integration tests for cl100k_base and o200k_base
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
src/main/php/ | ||
src/test/php/ | ||
src/it/php/ |
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,36 @@ | ||
<?php namespace com\openai\unittest; | ||
|
||
use com\openai\{Encoding, TikTokenFilesIn}; | ||
use test\{Args, Assert, Test, Values}; | ||
|
||
#[Args('folder')] | ||
class Cl100kBaseTest { | ||
private $encoder; | ||
|
||
/** Creates an instance with a given folder containing the `.tiktoken` files */ | ||
public function __construct($folder= '.') { | ||
$this->encoder= Encoding::named('cl100k_base')->load(new TikTokenFilesIn($folder)); | ||
} | ||
|
||
/** @return iterable */ | ||
private function fixtures() { | ||
yield ['hello world', [15339, 1917]]; | ||
yield ['привет мир', [8164, 2233, 28089, 8341, 11562, 78746]]; | ||
yield [".\n", [627]]; | ||
yield ["today\n ", [31213, 198, 220]]; | ||
yield ["today\n \n", [31213, 27907]]; | ||
yield ["today\n \n", [31213, 14211]]; | ||
yield ['🌶', [9468, 234, 114]]; | ||
yield ["👍", [9468, 239, 235]]; | ||
} | ||
|
||
#[Test] | ||
public function empty() { | ||
Assert::equals([], [...$this->encoder->encode('')]); | ||
} | ||
|
||
#[Test, Values(from: 'fixtures')] | ||
public function encode($text, $expected) { | ||
Assert::equals($expected, [...$this->encoder->encode($text)]); | ||
} | ||
} |
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,36 @@ | ||
<?php namespace com\openai\unittest; | ||
|
||
use com\openai\{Encoding, TikTokenFilesIn}; | ||
use test\{Args, Assert, Test, Values}; | ||
|
||
#[Args('folder')] | ||
class O200kBaseTest { | ||
private $encoder; | ||
|
||
/** Creates an instance with a given folder containing the `.tiktoken` files */ | ||
public function __construct($folder= '.') { | ||
$this->encoder= Encoding::named('o200k_base')->load(new TikTokenFilesIn($folder)); | ||
} | ||
|
||
/** @return iterable */ | ||
private function fixtures() { | ||
yield ['hello world', [24912, 2375]]; | ||
yield ['привет мир', [9501, 131903, 37934]]; | ||
yield [".\n", [558]]; | ||
yield ["today\n ", [58744, 198, 220]]; | ||
yield ["today\n \n", [58744, 47812]]; | ||
yield ["today\n \n", [58744, 31835]]; | ||
yield ['🌶', [64364, 114]]; | ||
yield ["👍", [82514]]; | ||
} | ||
|
||
#[Test] | ||
public function empty() { | ||
Assert::equals([], [...$this->encoder->encode('')]); | ||
} | ||
|
||
#[Test, Values(from: 'fixtures')] | ||
public function encode($text, $expected) { | ||
Assert::equals($expected, [...$this->encoder->encode($text)]); | ||
} | ||
} |