From fb66ca94070128c04e5a423ff6e6397c25d17df0 Mon Sep 17 00:00:00 2001 From: Erdum Date: Thu, 23 Nov 2023 10:25:20 +0500 Subject: [PATCH 1/8] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f158755..115a4de 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,12 @@ $thread_id = isset($_SESSION[$session_id]) ? $_SESSION[$session_id] : null; if (empty($thread_id)) { $thread_id = $openai->create_thread($query); $_SESSION[$session_id] = $thread_id; +} else { + $openai->add_message($thread_id, 'Can you help me?'); } +$openai->run_thread($thread_id); -$message_id = $openai->create_message($thread_id, 'Can you help me?'); - -if ($message_id) $openai->run_thread($thread_id); - -if ($openai->has_tool_calls) { +while ($openai->has_tool_calls) { $outputs = $openai->execute_tools( $thread_id, $openai->tool_call_id From b6bec35862e300024c1f5e8f3b71653cb87c45c7 Mon Sep 17 00:00:00 2001 From: Erdum Date: Thu, 23 Nov 2023 10:43:54 +0500 Subject: [PATCH 2/8] Update README.md --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 115a4de..a4e2485 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,75 @@ if ($message['role'] == 'assistant') { exit($output); } ``` +### Create a new Assistant +```php +create_assistant( + 'Customer Support Assistant', + 'You are a customer support assistant of Telecom company. which is a wholesale DID numbers marketplace. You have to greet the customers and ask them how you can help them then understand their query and do the required operation. The functions and tools my required order-id in the arguments but don not ask the customers to provide their order-id because order-id will be included automatically to function calls.', + array( + array( + 'type' => 'function', + 'function' => array( + 'name' => 'get_account_balance', + 'description' => 'This function retrieves the account balance of the customer with the provided order-id.', + 'parameters' => array( + 'type' => 'object', + 'properties' => array( + 'order_id' => array( + 'type' => 'string', + 'description' => 'The order-id of the customer.' + ) + ), + 'required' => array('order_id') + ), + ) + ) + ) +); +``` +### How PHP functions will be call + +Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method +```php +execute_tools( + $thread_id, + $openai->tool_call_id +); + +// This will call methods on an instance of a class +$myObj = new MyAPI(); +$outputs = $openai->execute_tools( + $thread_id, + $openai->tool_call_id, + $myObj +); + +// This will call static methods of a class +$outputs = $openai->execute_tools( + $thread_id, + $openai->tool_call_id, + 'MyAPI' +); + +$openai->submit_tool_outputs( + $thread_id, + $openai->tool_call_id, + $outputs +); +``` + ## API Reference #### Create Assistant Object From eb77c823a17a4aff0a4c7da55adcc31c51bcd9e1 Mon Sep 17 00:00:00 2001 From: Erdum Date: Thu, 23 Nov 2023 10:44:34 +0500 Subject: [PATCH 3/8] Update README.md --- README.md | 67 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index a4e2485..7c0050b 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,39 @@ if ($message['role'] == 'assistant') { exit($output); } ``` +### How PHP functions will be call + +Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method +```php +execute_tools( + $thread_id, + $openai->tool_call_id +); + +// This will call methods on an instance of a class +$myObj = new MyAPI(); +$outputs = $openai->execute_tools( + $thread_id, + $openai->tool_call_id, + $myObj +); + +// This will call static methods of a class +$outputs = $openai->execute_tools( + $thread_id, + $openai->tool_call_id, + 'MyAPI' +); + +$openai->submit_tool_outputs( + $thread_id, + $openai->tool_call_id, + $outputs +); +``` ### Create a new Assistant ```php create_assistant( ) ); ``` -### How PHP functions will be call - -Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method -```php -execute_tools( - $thread_id, - $openai->tool_call_id -); - -// This will call methods on an instance of a class -$myObj = new MyAPI(); -$outputs = $openai->execute_tools( - $thread_id, - $openai->tool_call_id, - $myObj -); - -// This will call static methods of a class -$outputs = $openai->execute_tools( - $thread_id, - $openai->tool_call_id, - 'MyAPI' -); - -$openai->submit_tool_outputs( - $thread_id, - $openai->tool_call_id, - $outputs -); -``` - ## API Reference #### Create Assistant Object From a3b277b21e0c19966a2fbc652d0b3058fc94dd2d Mon Sep 17 00:00:00 2001 From: Erdum Date: Thu, 23 Nov 2023 10:45:17 +0500 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c0050b..91be36c 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ if ($message['role'] == 'assistant') { ``` ### How PHP functions will be call -Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method +Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present in your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method ```php Date: Fri, 24 Nov 2023 20:56:24 +0500 Subject: [PATCH 5/8] Update README.md --- README.md | 121 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 91be36c..e6da9e4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A PHP class for seamless interaction with the OpenAI Assistant API, enabling dev - [Installation](#installation) - [Usage](#usage) -- [API Reference](#api-reference) +- [Reference](#reference) - [Feedback](#feedback) - [License](#license) @@ -88,13 +88,13 @@ if ($message['role'] == 'assistant') { exit($output); } ``` -### How PHP functions will be call +### How PHP functions will be called -Whatever function names you will provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present in your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method +Whatever function names you provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present in your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method ```php execute_tools( $thread_id, $openai->tool_call_id @@ -134,7 +134,7 @@ $openai = new OpenAIAssistant($api_key); $openai->create_assistant( 'Customer Support Assistant', - 'You are a customer support assistant of Telecom company. which is a wholesale DID numbers marketplace. You have to greet the customers and ask them how you can help them then understand their query and do the required operation. The functions and tools my required order-id in the arguments but don not ask the customers to provide their order-id because order-id will be included automatically to function calls.', + 'You are a customer support assistant of Telecom company. which is a wholesale DID numbers marketplace. You have to greet the customers and ask them how you can help them then understand their query and do the required operation. The functions and tools may require order-id in the arguments but do not ask the customers to provide their order-id because order-id will be included automatically to function calls.', array( array( 'type' => 'function', @@ -156,24 +156,109 @@ $openai->create_assistant( ) ); ``` -## API Reference -#### Create Assistant Object +## Reference -```php - Date: Fri, 24 Nov 2023 21:01:22 +0500 Subject: [PATCH 6/8] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e6da9e4..84f4518 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,11 @@ if ($message['role'] == 'assistant') { ``` ### How PHP functions will be called -Whatever function names you provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present in your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide additonal argument to "execute_tools" method +Whatever function names you provide in the tools array will be called in your PHP environment accordingly by the Assistant API, for example in the below code function "get_account_balance" should be present in your PHP environment in order to be executed. If you want to run methods of an object or static methods of a class then you can provide an additional argument to the "execute_tools" method ```php execute_tools( $thread_id, $openai->tool_call_id @@ -134,7 +134,7 @@ $openai = new OpenAIAssistant($api_key); $openai->create_assistant( 'Customer Support Assistant', - 'You are a customer support assistant of Telecom company. which is a wholesale DID numbers marketplace. You have to greet the customers and ask them how you can help them then understand their query and do the required operation. The functions and tools may require order-id in the arguments but do not ask the customers to provide their order-id because order-id will be included automatically to function calls.', + 'You are a customer support assistant of an Telecom company. which is a wholesale DID numbers marketplace. You have to greet the customers and ask them how you can help them then understand their query and do the required operation. The functions and tools may require order-id in the arguments but do not ask the customers to provide their order-id because order-id will be included automatically to function calls.', array( array( 'type' => 'function', From db418d506acdbcc5f562c72d9520c21e43eff393 Mon Sep 17 00:00:00 2001 From: Erdum Date: Fri, 24 Nov 2023 21:04:23 +0500 Subject: [PATCH 7/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84f4518..8e914da 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ $openai = new OpenAIAssistant( ``` ## Usage -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. +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 the [Reference](#reference) to see all the available methods. ```php Date: Wed, 29 Nov 2023 16:56:10 +0500 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e914da..a9c1ddb 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ while ($openai->has_tool_calls) { } // Get the last recent message -$message = $openai->list_messages($thread_id); +$message = $openai->list_thread_messages($thread_id); $message = $message[0]; $output = '';