Skip to content

Commit 1a7bff4

Browse files
authored
Update README.md
1 parent 966cc8c commit 1a7bff4

File tree

1 file changed

+60
-34
lines changed

1 file changed

+60
-34
lines changed

README.md

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A PHP class for seamless interaction with the OpenAI Assistant API, enabling dev
99

1010
- [Installation](#installation)
1111
- [Usage](#usage)
12+
- [API Reference](#api-reference)
1213
- [Feedback](#feedback)
1314
- [License](#license)
1415

@@ -31,57 +32,82 @@ git clone https://github.com/erdum/php-open-ai-assistant-sdk.git
3132
require(__DIR__ . 'php-open-ai-assistant-sdk/src/OpenAIAssistant.php');
3233

3334
use Erdum\OpenAIAssistant;
35+
36+
$openai = new OpenAIAssistant(
37+
$api_key,
38+
$assistant_id
39+
);
3440
```
3541

3642
## Usage
3743
Currently, this usage example does not contain any information about OpenAI Assistant API working for a better understanding of how OpenAI Assistant API works and its lifecycle please refer to the [OpenAI documentation](https://platform.openai.com/docs/assistants/how-it-works) and look inside the OpenAIAssistant.php file to see all the available methods.
3844
```php
3945
<?php
4046

41-
$thread_id = $_SESSION[$session_id];
47+
require(__DIR__ . '/vendor/autoload.php');
48+
# require(__DIR__ . '/php-open-ai-assistant-sdk/src/OpenAIAssistant.php');
4249

43-
try {
44-
$openai = new OpenAIAssistant(
45-
OpenAI-API-Key,
46-
Assistant-ID
47-
);
50+
use Erdum\OpenAIAssistant;
4851

49-
if (empty($thread_id)) {
50-
$thread_id = $openai->create_thread();
51-
$_SESSION[$session_id] = $thread_id;
52-
}
52+
$openai = new OpenAIAssistant(
53+
$api_key,
54+
$assistant_id
55+
);
5356

54-
$message_id = $openai->create_message($thread_id, 'I want to check my account balance');
57+
$thread_id = isset($_SESSION[$session_id]) ? $_SESSION[$session_id] : null;
5558

56-
if ($message_id) $openai->run_thread($thread_id);
59+
if (empty($thread_id)) {
60+
$thread_id = $openai->create_thread($query);
61+
$_SESSION[$session_id] = $thread_id;
62+
}
5763

58-
if ($openai->has_tool_calls) {
59-
$outputs = $openai->execute_tools(
60-
$thread_id,
61-
$openai->tool_call_id
62-
);
63-
$openai->submit_tool_outputs(
64-
$thread_id,
65-
$openai->tool_call_id,
66-
$outputs
67-
);
68-
}
64+
$message_id = $openai->create_message($thread_id, 'Can you help me?');
65+
66+
if ($message_id) $openai->run_thread($thread_id);
67+
68+
if ($openai->has_tool_calls) {
69+
$outputs = $openai->execute_tools(
70+
$thread_id,
71+
$openai->tool_call_id
72+
);
73+
$openai->submit_tool_outputs(
74+
$thread_id,
75+
$openai->tool_call_id,
76+
$outputs
77+
);
78+
}
6979

70-
// Get the last recent message
71-
$message = $openai->list_messages($thread_id);
72-
$message = $message[0];
73-
$output = '';
80+
// Get the last recent message
81+
$message = $openai->list_messages($thread_id);
82+
$message = $message[0];
83+
$output = '';
7484

75-
if ($message['role'] == 'assistant') {
76-
foreach ($message['content'] as $msg) {
77-
$output .= "{$msg['text']['value']}\n";
78-
}
79-
exit($output);
85+
if ($message['role'] == 'assistant') {
86+
foreach ($message['content'] as $msg) {
87+
$output .= "{$msg['text']['value']}\n";
8088
}
81-
} catch (Exception $err) {
82-
echo($err);
89+
exit($output);
8390
}
8491
```
92+
## API Reference
93+
94+
#### Create Assistant Object
95+
96+
```php
97+
<?php
98+
99+
use Erdum\OpenAIAssistant;
100+
101+
$openai = new OpenAIAssistant($api_key);
102+
```
103+
104+
| Parameter | Type | Description |
105+
| :------------- | :------- | :---------- |
106+
| `api_key` | `string` | **Required**. Your OpenAI API key |
107+
| `assistant_id` | `string` | Assistant ID (default = null) |
108+
| `base_url` | `string` | OpenAI API base URL (default = 'https://api.openai.com/v1') |
109+
| `version_header` | `string` | OpenAI API version header (default = 'OpenAI-Beta: assistants=v1' ) |
110+
85111
## Feedback
86112

87113
If you have any feedback, please reach out to us at erdumadnan@gmail.com

0 commit comments

Comments
 (0)