Qu’est-ce qu’AWS Bedrock

AWS Bedrock est un service managé qui donne accès à des modèles d’IA générative (Claude, Llama, Titan, Mistral) via une API unifiée. Pas besoin de gérer l’infrastructure ML : vous appelez une API, vous recevez une réponse.

Chez Lueur Externe, nous utilisons Bedrock pour la génération de contenu, les chatbots et l’automatisation intelligente.

Modèles disponibles

ModèleFournisseurUsage principal
Claude 3.5 SonnetAnthropicRaisonnement, code, analyse
Claude 3 HaikuAnthropicRéponses rapides, coût réduit
Llama 3MetaOpen source, personnalisable
Mistral LargeMistral AIMultilingue, européen
Titan TextAmazonEmbeddings, génération

Intégration TypeScript

Appel simple

import {
  BedrockRuntimeClient,
  InvokeModelCommand,
} from "@aws-sdk/client-bedrock-runtime";

const client = new BedrockRuntimeClient({ region: "eu-west-3" });

async function generateContent(prompt: string): Promise<string> {
  const command = new InvokeModelCommand({
    modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
    contentType: "application/json",
    accept: "application/json",
    body: JSON.stringify({
      anthropic_version: "bedrock-2023-05-31",
      max_tokens: 4096,
      messages: [{ role: "user", content: prompt }],
      temperature: 0.7,
    }),
  });

  const response = await client.send(command);
  const body = JSON.parse(new TextDecoder().decode(response.body));
  return body.content[0].text;
}

Streaming pour les chatbots

import { InvokeModelWithResponseStreamCommand } from "@aws-sdk/client-bedrock-runtime";

async function* streamResponse(prompt: string) {
  const command = new InvokeModelWithResponseStreamCommand({
    modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
    contentType: "application/json",
    body: JSON.stringify({
      anthropic_version: "bedrock-2023-05-31",
      max_tokens: 2048,
      messages: [{ role: "user", content: prompt }],
    }),
  });

  const response = await client.send(command);
  for await (const event of response.body!) {
    if (event.chunk?.bytes) {
      const chunk = JSON.parse(new TextDecoder().decode(event.chunk.bytes));
      if (chunk.type === "content_block_delta") {
        yield chunk.delta.text;
      }
    }
  }
}

RAG avec Knowledge Bases

Le Retrieval-Augmented Generation (RAG) permet d’enrichir les réponses de l’IA avec vos propres données :

  1. Indexez vos documents dans une Knowledge Base Bedrock
  2. À chaque requête, les documents pertinents sont récupérés
  3. Le modèle génère une réponse contextualisée
import {
  BedrockAgentRuntimeClient,
  RetrieveAndGenerateCommand,
} from "@aws-sdk/client-bedrock-agent-runtime";

const agentClient = new BedrockAgentRuntimeClient({ region: "eu-west-3" });

async function ragQuery(question: string): Promise<string> {
  const command = new RetrieveAndGenerateCommand({
    input: { text: question },
    retrieveAndGenerateConfiguration: {
      type: "KNOWLEDGE_BASE",
      knowledgeBaseConfiguration: {
        knowledgeBaseId: "KB_ID",
        modelArn: "arn:aws:bedrock:eu-west-3::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0",
      },
    },
  });

  const response = await agentClient.send(command);
  return response.output?.text || "";
}

Cas d’usage concrets

  • Génération de contenu SEO : articles de blog, fiches produits, FAQ
  • Chatbot intelligent : support client avec connaissance métier
  • Résumé de documents : synthèse automatique de rapports
  • Traduction contextuelle : traduction adaptée au domaine
  • Analyse de sentiment : monitoring des avis clients

Coûts

Bedrock facture à l’usage (tokens d’entrée et de sortie). Pour Claude 3.5 Sonnet :

  • Input : ~3 $ / million de tokens
  • Output : ~15 $ / million de tokens

Un article de blog de 1 500 mots coûte environ 0,05 $ à générer.

Conclusion

AWS Bedrock démocratise l’accès à l’IA générative pour les développeurs. Lueur Externe intègre Bedrock dans les applications de ses clients pour automatiser et enrichir leurs processus métier.