Skip to content

Commit

Permalink
Document realtime API
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 1, 2024
1 parent bc8bdb3 commit dabe869
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ OpenAI APIs for XP ChangeLog

## ?.?.? / ????-??-??

## 0.7.0 / ????-??-??

* Merged PR #15: Implement realtime API. This implements issue #8 in a
new `com.openai.realtime` package
(@thekid)

## 0.6.0 / 2024-10-27

* Merged PR #9: Support uploading files, e.g. for transcribing audio.
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,38 @@ For more complex load balancing, have a look at [this blog article using Azure A

Realtime API
------------
*Coming soon*
The realtime API allows streaming audio and/or text to and from language models, see https://platform.openai.com/docs/guides/realtime

```php
use com\openai\realtime\RealtimeApi;
use util\cmd\Console;

$api= new RealtimeApi('wss://example.openai.azure.com/openai/realtime?'.
'?api-version=2024-10-01-preview'.
'&deployment=gpt-4o-realtime-preview'
);
$session= $api->connect(['api-key' => getenv('AZUREAI_API_KEY')]);
Console::writeLine($session);

// Send prompt
$api->transmit([
'type' => 'conversation.item.create',
'item' => [
'type' => 'message',
'role' => 'user',
'content' => $content,
]
]);

// Receive response(s)
$api->send(['type' => 'response.create', 'response' => ['modalities' => ['text']]]);
do {
$event= $api->receive();
Console::writeLine($event);
} while ('response.done' !== $event['type'] && 'error' !== $event['type']);

$api->close();
```

See also
--------
Expand Down

0 comments on commit dabe869

Please sign in to comment.