PHP code example of amohamed / jsconnector

1. Go to this page and download the library: Download amohamed/jsconnector 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/ */

    

amohamed / jsconnector example snippets


return [
    'api_url' => env('JS_CONNECTOR_API_URL', 'http://localhost:3000/api'),
    'retry_times' => env('JS_CONNECTOR_RETRY_TIMES', 3),
    'retry_interval' => env('JS_CONNECTOR_RETRY_INTERVAL', 100),
];

$response = JSConnector::post('test-endpoint', ['baz' => 'qux']);



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Amohamed\JSConnector\Facades\JSConnector;

class LangChainController extends Controller
{
    public function chat(Request $request)
    {
        $input = $request->input('message');

        // We use the post method on the JSConnector facade
        $response = JSConnector::post('chat', ['input' => $input]);

        // Then we return the response from the langchainjs service
        return response()->json(['response' => $response]);
    }
}

bash
php artisan vendor:publish --provider="Amohamed\JSConnector\JSConnectorServiceProvider" --tag="config"
bash
php artisan jsconnector:serve
bash
php artisan jsconnector:stop