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
已提问 1 个月前59 查看次数
1 回答
0
已接受的回答

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
已回答 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容