Skip to content

Commit

Permalink
Merge pull request #21 from SheepFromHeaven/main
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanerday authored Nov 4, 2022
2 parents e87a33d + e84f07a commit ba06505
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ $complete = $open_ai->complete([
]);
```

## Images (Dall-E)

Given a prompt, the model will return one or more generated images as urls or base64 encoded.

```php
$complete = $open_ai->image([
'prompt' => 'A cat drinking milk',
'n' => 1,
'size' => '256x256',
'response_format' => 'url',
]);
```

## Searches

Given a query and a set of documents or labels, the model ranks each document based on its semantic similarity to the
Expand Down
11 changes: 11 additions & 0 deletions src/OpenAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public function complete($opts)
return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param $opts
* @return bool|string
*/
public function image($opts)
{
$url = Url::imageUrl();

return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param $opts
* @return bool|string
Expand Down
9 changes: 9 additions & 0 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,13 @@ public static function answersUrl(): string
{
return self::OPEN_AI_URL . "/answers";
}

/**
* @param
* @return string
*/
public static function imageUrl(): string
{
return self::OPEN_AI_URL . "/images/generations";
}
}
9 changes: 9 additions & 0 deletions tests/OpenAiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,12 @@
$result = $open_ai->engine($engine_id);
$this->assertStringContainsString($engine_id, $result);
});

it('should handle image', function () use ($open_ai) {
$result = $open_ai->image([
'prompt' => "a picture of a cat",
'n' => 1,
'size' => "256x256",
]);
$this->assertStringContainsString('data', $result);
});

0 comments on commit ba06505

Please sign in to comment.