Skip to content

Commit

Permalink
Merge pull request #85 from reply2future/main
Browse files Browse the repository at this point in the history
Fix stream check condition
  • Loading branch information
orhanerday authored Jun 11, 2023
2 parents 85cd93a + 746dd87 commit 896665e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/OpenAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public function complete($opts)
*/
public function completion($opts, $stream = null)
{
if ($stream != null && array_key_exists('stream', $opts)) {
if (!$opts['stream']) {
if (array_key_exists('stream', $opts) && $opts['stream']) {
if ($stream == null) {
throw new Exception(
'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.'
);
Expand Down
22 changes: 15 additions & 7 deletions tests/OpenAiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi('OPEN-AI-KEY');
$open_ai = new OpenAi(getenv('OPENAI_API_KEY'));

it('should handle simple completion using the new endpoint', function () use ($open_ai) {
$result = $open_ai->completion([
Expand All @@ -17,6 +17,17 @@
$this->assertStringContainsString('text', $result);
})->group('working');

it('should throw error when set the stream to true and does not set the stream method', function () use ($open_ai) {
expect(fn () => $open_ai->completion([
'prompt' => "Hello",
'temperature' => 0.9,
"max_tokens" => 150,
"frequency_penalty" => 0,
"presence_penalty" => 0.6,
"stream" => true
]))->toThrow(Exception::class, 'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.');
})->group('working');

it('should handle simple completion using the deprecated endpoint', function () use ($open_ai) {
$result = $open_ai->complete([
'engine' => 'davinci',
Expand Down Expand Up @@ -107,22 +118,19 @@
$result = $open_ai->cancelFineTune('file-XGinujblHPwGLSztz8cPS8XY');

$this->assertStringContainsString('training_files', $result);
})->group('requires-missing-file');
;
})->group('requires-missing-file');;

it('should handle list fine-tune event', function () use ($open_ai) {
$result = $open_ai->listFineTuneEvents('file-XGinujblHPwGLSztz8cPS8XY');

$this->assertStringContainsString('data', $result);
})->group('requires-missing-file');
;
})->group('requires-missing-file');;

it('should handle delete fine-tune model', function () use ($open_ai) {
$result = $open_ai->deleteFineTune('curie:ft-acmeco-2021-03-03-21-44-20');

$this->assertStringContainsString('deleted', $result);
})->group('requires-missing-file');
;
})->group('requires-missing-file');;

it('should handle answers', function () use ($open_ai) {
$result = $open_ai->answer([
Expand Down

0 comments on commit 896665e

Please sign in to comment.