|
9 | 9 | use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
|
10 | 10 | use PhpLlm\LlmChain\Platform\Exception\InvalidArgumentException;
|
11 | 11 | use PHPUnit\Framework\Attributes\CoversClass;
|
12 |
| -use PHPUnit\Framework\Attributes\DataProvider; |
13 | 12 | use PHPUnit\Framework\Attributes\Small;
|
14 | 13 | use PHPUnit\Framework\Attributes\Test;
|
| 14 | +use PHPUnit\Framework\Attributes\TestWith; |
15 | 15 | use PHPUnit\Framework\TestCase;
|
16 | 16 | use Symfony\Component\HttpClient\EventSourceHttpClient;
|
17 | 17 | use Symfony\Component\HttpClient\MockHttpClient;
|
@@ -118,7 +118,11 @@ public function doesNotSupportNonGPTModel(): void
|
118 | 118 | }
|
119 | 119 |
|
120 | 120 | #[Test]
|
121 |
| - #[DataProvider('requestDataProvider')] |
| 121 | + #[TestWith([['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], [], ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo']], 'with array payload and no options')] |
| 122 | + #[TestWith(['test message', [], 'test message'], 'with string payload and no options')] |
| 123 | + #[TestWith([['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], ['temperature' => 0.7, 'max_tokens' => 150], ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo', 'temperature' => 0.7, 'max_tokens' => 150]], 'with array payload and options')] |
| 124 | + #[TestWith([['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo', 'temperature' => 1.0], ['temperature' => 0.5], ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo', 'temperature' => 0.5]], 'options override payload values')] |
| 125 | + #[TestWith([['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], ['stream' => true], ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo', 'stream' => true]], 'with streaming option')] |
122 | 126 | public function requestSendsCorrectHttpRequest(array|string $payload, array $options, array|string $expectedJson): void
|
123 | 127 | {
|
124 | 128 | $capturedRequest = null;
|
@@ -153,38 +157,6 @@ public function requestSendsCorrectHttpRequest(array|string $payload, array $opt
|
153 | 157 | }
|
154 | 158 | }
|
155 | 159 |
|
156 |
| - public static function requestDataProvider(): \Iterator |
157 |
| - { |
158 |
| - yield 'with array payload and no options' => [ |
159 |
| - 'payload' => ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
160 |
| - 'options' => [], |
161 |
| - 'expectedJson' => ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
162 |
| - ]; |
163 |
| - |
164 |
| - yield 'with string payload and no options' => [ |
165 |
| - 'payload' => 'test message', |
166 |
| - 'options' => [], |
167 |
| - 'expectedJson' => 'test message', |
168 |
| - ]; |
169 |
| - |
170 |
| - yield 'with array payload and options' => [ |
171 |
| - 'payload' => ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
172 |
| - 'options' => ['temperature' => 0.7, 'max_tokens' => 150], |
173 |
| - 'expectedJson' => ['temperature' => 0.7, 'max_tokens' => 150, 'messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
174 |
| - ]; |
175 |
| - |
176 |
| - yield 'options override payload values' => [ |
177 |
| - 'payload' => ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo', 'temperature' => 1.0], |
178 |
| - 'options' => ['temperature' => 0.5], |
179 |
| - 'expectedJson' => ['temperature' => 0.5, 'messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
180 |
| - ]; |
181 |
| - |
182 |
| - yield 'with streaming option' => [ |
183 |
| - 'payload' => ['messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
184 |
| - 'options' => ['stream' => true], |
185 |
| - 'expectedJson' => ['stream' => true, 'messages' => [['role' => 'user', 'content' => 'Hello']], 'model' => 'gpt-3.5-turbo'], |
186 |
| - ]; |
187 |
| - } |
188 | 160 |
|
189 | 161 | #[Test]
|
190 | 162 | public function requestHandlesBaseUrlWithoutTrailingSlash(): void
|
|
0 commit comments