PHP code example of evolvoltd / laravel-openai-assistants

1. Go to this page and download the library: Download evolvoltd/laravel-openai-assistants library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

evolvoltd / laravel-openai-assistants example snippets


  public function parseResponse(string $response)
    {
        return strtoupper($response);
    }

  public function executeFunctions(string $name, $arguments, $toolCall)
    {
        if ($name == 'get_weather') {
            return [
                'tool_call_id' => $toolCall->id,
                'output' => "25 degrees celsius"
            ];
        } else return [];
    }

  public function statusUpdate(string $status, string $run_id, string $thread_id, string $message = null, string $file_path = null, string $file_name = null, string $response = null)
    {
        if ($status === 'new') {
            $query = GptQuery::query()->create([
                'user_id' => auth::id(),
                'status' => $status,
                'run_id' => $run_id,
                'thread_id' => $thread_id,
                'message' => $message,
                'response' => $response,
                'file_path' => $file_path,
                'file_name' => $file_name
            ]);
        } else {
            $query = GptQuery::query()->where('run_id', $run_id)->where('thread_id', $thread_id)->first();
            $query->update([
                'status' => $status,
                'response' => $response
            ]);
        }

        return $query;
    }