Any code snippet or example in laravel can I get to invokeAgent

0

Is there a laravel equivalent to invoke the following. Can someone please help? POST /agents/agentId/agentAliases/agentAliasId/sessions/sessionId/text HTTP/1.1 Content-type: application/json

{ "enableTrace": boolean, "endSession": boolean, "inputText": "string", "sessionState": { "promptSessionAttributes": { "string" : "string" }, "sessionAttributes": { "string" : "string" } } }

Guru
asked 14 days ago39 views
1 Answer
0
Accepted Answer

In case if any body wants the working code snippet which I made it working in laravel:

Example of any-sessionId: abc or abbc or test

public function retrieveAgentUsingApi() { // AWS Credentials $awsCredentials = new Credentials(env('AWS_ACCESS_KEY_ID'), env('AWS_SECRET_ACCESS_KEY')); $region = 'us-west-1'; $baseUrl = 'https://bedrock-agent-runtime.' $region '.amazonaws.com'; // Create a new PSR-7 request object $request = new Request( 'POST', // HTTP method $baseUrl . '/agents/{your-agentId}/agentAliases/{your-agentAliasID}/sessions/{any-sessionId}/text', // Request URL ['Content-Type' => 'application/json'], // Headers json_encode([ 'inputText' => 'which country won the 2023 soccer game?' ]) );

        $signer = new SignatureV4("bedrock", $region); 
        $signedrequest = $signer->signRequest($request, $awsCredentials);
       // Create a Guzzle HTTP client
        $client = new Client();
        // Send the signed request
        $response = $client->send($signedrequest);

        // You can then access the response body using:
        $responseBody = $response->getBody()->getContents();
        return $responseBody;
}
Guru
answered 13 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions