diff --git a/composer.lock b/composer.lock index c9478696c..27e6dffe1 100644 --- a/composer.lock +++ b/composer.lock @@ -118,16 +118,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.285.0", + "version": "3.288.1", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "41c7a9491455f89052cba62c4e4f0c748af51265" + "reference": "a1dfa12c7165de0b731ae8074c4ba1f3ae733f89" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/41c7a9491455f89052cba62c4e4f0c748af51265", - "reference": "41c7a9491455f89052cba62c4e4f0c748af51265", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/a1dfa12c7165de0b731ae8074c4ba1f3ae733f89", + "reference": "a1dfa12c7165de0b731ae8074c4ba1f3ae733f89", "shasum": "" }, "require": { @@ -207,9 +207,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.285.0" + "source": "https://github.com/aws/aws-sdk-php/tree/3.288.1" }, - "time": "2023-11-07T19:33:47+00:00" + "time": "2023-11-22T19:35:38+00:00" }, { "name": "behat/mink", diff --git a/html/modules/custom/reliefweb_openai/reliefweb_openai.module b/html/modules/custom/reliefweb_openai/reliefweb_openai.module index 647b96b9a..57c9fc831 100644 --- a/html/modules/custom/reliefweb_openai/reliefweb_openai.module +++ b/html/modules/custom/reliefweb_openai/reliefweb_openai.module @@ -90,7 +90,7 @@ function reliefweb_openai_form_alter(array &$form, FormStateInterface $form_stat $form['aws_claude']['aws_do_suggest'] = [ '#type' => 'button', - '#value' => t('Suggest humanitarian theme(s) - AWS Comprehend'), + '#value' => t('Suggest humanitarian theme(s) - Claude'), '#limit_validation_errors' => [], '#ajax' => [ 'callback' => 'reliefweb_openai_content_node_suggest_aws_claude', @@ -414,11 +414,9 @@ function reliefweb_openai_content_node_suggest_aws_claude(array &$form, FormStat $access_key = $config->get('aws_access_key'); $secret_key = $config->get('aws_secret_key'); - $region = $config->get('aws_region'); - $endpoint = $config->get('aws_endpoint_theme_classifier'); $client = new BedrockRuntimeClient([ - 'region' => $region, + 'region' => 'us-east-1', 'version' => 'latest', 'credentials' => [ 'key' => $access_key, @@ -431,19 +429,22 @@ function reliefweb_openai_content_node_suggest_aws_claude(array &$form, FormStat $prompt = 'Extract the required years of job experience, career category, humanitarian theme (One of Agriculture, Camp Coordination and Camp Management, Climate Change and Environment, Contributions, Coordination, Disaster Management, Education, Food and Nutrition, Gender, Health, HIV/AIDS, Humanitarian Financing, Logistics and Telecommunications, Mine Action, Peacekeeping and Peacebuilding, Protection and Human Rights, Recovery and Reconstruction, Safety and Security, Shelter and Non-Food Items, Water Sanitation Hygiene) and country from the text below.' . "\n\n" . $body; } - $text = "\n\nHuman: $prompt\n\nAssistant:"; + $text = [ + 'prompt' => "\n\nHuman: $prompt\n\nAssistant:", + 'max_tokens_to_sample' => 4000, + 'temperature' => 0.1, + 'top_p' => 0.9, + ]; $result = $client->invokeModel([ - 'EndpointArn' => $endpoint, - 'Text' => $text, + 'modelId' => 'anthropic.claude-v2', + 'body' => json_encode($text), ]); - $text = ''; - $parts = []; - foreach ($result->get('Classes') as $class) { - $parts[] = $class['Name'] . ' (' . round(100 * $class['Score'], 1) . '%)'; - } - $text = implode(', ', $parts); + $text = $result->get('body') . ''; + $text = json_decode($text, TRUE); + $text = $text['completion']; + $text = str_replace("\n", '
', $text); $response = new AjaxResponse(); $response->addCommand(new HtmlCommand('#aws-claude-suggest-response', $text));