Reactive Machines

Mix AI products in Microsoft Office using Amazon Bedrock

Cercitative AI changes quickly in today's work, provides unprecedentable skills and text and data. In the Amazon Web Services (AWS), we see that many of our customers rely on Microsoft Office Suite, including the name, Excel, and Outlook, such as the travel backmane. In this blog study, we show a strong solution to the Ai Generative Aim of Ai Generative Ai power in the form of major languages ​​(LLMs) based on the Amazon Bedrock at office experiences. By adhering to the recent advancement in Generative AI, we enable workers to open new performance levels and art inside the tools that have already used every day. Whether it is written, analyzing information, or receiving a deeper understanding of information, which includes the production of AI with the Office Suite converting its work. We join us as we check how your organization can get the technology to convert new driving technology and improve the productivity of staff.

Looking for everything

Figure 1: Solution Architecture Overview

The solution structure in Figure 1 indicates how Office apps interact with the non-existing backend of AW cloud. This state allows users to use Amazon Bedrock's productivity AI power from within the Suite Office, enabling the Advanced Product and understanding within their applicable applications.

Elements deepen

Office Add-Ins

Office Add-Ins allows the extension of the Office Products to customization for ordinary web technology. Using AWS, organizations can handle and use Office Add-Ins to the worldwide users with a small infrastructure infrastructure.

The office supplement is two components:

The lower Code Snippet is indicating the work part that can work whenever the user draws the plugin, performing the following actions:

  1. Start application on Generative Ai Backend, providing institutional institution and available in the application body
  2. Mix the results from turning back to the word document using Microsoft's Office Apis. Note that these APIs use items as a name for words, and promote the need to import clear. Instead, we use the names of the world, such as WordRight access to appropriate APIs, as indicated in accordance with example.
// Initiate backend request (optional context)
const response = await sendPrompt({ user_message: prompt, context: selectedContext });

// Modify Word content with responses from the Backend
await Word.run(async (context) => {
  let documentBody;

  // Target for the document modifications
  if (response.location === 'Replace') {
    documentBody = context.document.getSelection(); // active text selection
  } else {
    documentBody = context.document.body; // entire document body
  }

  // Markdown support for preserving original content layout
  // Dependencies used: React markdown
  const content = renderToString({ response.content } < /Markdown>);
  const operation = documentBody.insertHtml(content, response.location);

  // set properties for the output content (font, size, color, etc.)
  operation.font.set({ name: 'Arial' });

  // flush changes to the Word document
  await context.sync();
});

Ai Backlend Infrastructure for AI

The AWNS Cloud Basenders contains three components:

  1. Amazon API Gateway works as an entry site, receiving requests from office requests'. API Gateway supports many ways to control and administer access to API.
  2. The AWS LAMKDA treats the combination of API rest, processing applications and provides relevant AWS services.
  3. Amazon Bedrock is a fully managed service that makes Baseline Modes (FMS) from starting AI Startups and Amazon available through FM, to select from FM Less to Find the appropriate model. With a Bedrock Service Service, you can start immediately, customize the FMS with your data, and combine it immediately to your requests using infrastructure.

Llm moves

Amazon Bedrock allows you to choose in a broad selection of the base models. Here, we use anthropic's Claude 3.5 Sonnet in Amazon Bedrock to get rid of. The immediate system used in this example is acting as follows:

You are an office assistant helping humans to write text for their documents.

[When preparing the answer, take into account the following text: {context}]
Before answering the question, think through it step-by-step within the  tags.
Then, detect the user's language from their question and store it in the form of an ISO 639-1 code within the  tags.
Then, develop your answer in the user’s language within the  tags.

In a hurry, we first give the human llm, indicating that it is a helper to help people. Second, the optional line contains user-selected text in the document and is given as a LLM context. We teach exactly the llm that begins to imitate the process of coming-by-step process (assuming thinking), an active development rate. Next, we teach them to find the user's language in their question so that they can later refer to. Finally, we teach the llm to improve its response using the user's language received within the response tags, are used as the final answer. While we are here, we use the default suspension of propensity parameters, which can quickly be prepared through all the fast-speed LLM. User installation and add as a user messaging to the Prompt and sent by Amazon Bedrock API messages in the LLM.

Details of Rental and Demo Setup in AWC ASC

As a requirement, we need to make sure we work in the AWS region by Amazon Bedrock support support (here, using Anthropic's Claude 3.5 Sonnet). Also, access to the required icon models of Amazon Bedrock Foundation requires additional additions. For this photo demo, it describes the action steps taken from AW Console. If necessary, this setup can be defined as infrastructure as the code.

To set integrated, follow these steps:

  1. Create an AWS Lambda work with Python Runtime and below code to be a Backend of API. Make sure we have PowerToolly AWS LAMBDA (Python) available during our running time, for example, by installing a layer of AlalaDa layer. Make sure the role of the lambda function of the Form is providing access to the required FM, for example:
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "bedrock:InvokeModel",
                "Resource": [
                    "arn:aws:bedrock:*::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0"
                ]
            }
        ]
    }
    

    The following code displays the implementation of the API Lambde compilation based on PowerTOLS LAMBDA (Python) Rest API Event Handler:

    import json
    import re
    from typing import Optional
    
    import boto3
    from aws_lambda_powertools import Logger
    from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig
    from aws_lambda_powertools.logging import correlation_paths
    from aws_lambda_powertools.utilities.typing import LambdaContext
    from pydantic import BaseModel
    
    logger = Logger()
    app = APIGatewayRestResolver(
        enable_validation=True,
        cors=CORSConfig(allow_origin="  # for testing purposes
    )
    
    bedrock_runtime_client = boto3.client("bedrock-runtime")
    
    
    SYSTEM_PROMPT = """
    You are an office assistant helping humans to write text for their documents.
    
    {context}
    Before answering the question, think through it step-by-step within the  tags.
    Then, detect the user's language from their question and store it in the form of an ISO 639-1 code within the  tags.
    Then, develop your answer in the user's language in markdown format within the  tags.
    """
    
    class Query(BaseModel):
        user_message: str  # required
        context: Optional[str] = None  # optional
        max_tokens: int = 1000  # default value
        model_id: str = "anthropic.claude-3-5-sonnet-20240620-v1:0"  # default value
    
    def wrap_context(context: Optional[str]) -> str:
        if context is None:
            return ""
        else:
            return f"When preparing the answer take into account the following text: {context}"
    
    def parse_completion(completion: str) -> dict:
        response = {"completion": completion}
        try:
            tags = ["thinking", "user_language", "response"]
            tag_matches = re.finditer(
                f"<(?P{'|'.join(tags)})>(?P.*?)(?P=tag)>",
                completion,
                re.MULTILINE | re.DOTALL,
            )
            for match in tag_matches:
                response[match.group("tag")] = match.group("content").strip()
        except Exception:
            logger.exception("Unable to parse LLM response")
            response["response"] = completion
    
        return response
    
    
    @app.post("/query")
    def query(query: Query):
        bedrock_response = bedrock_runtime_client.invoke_model(
            modelId=query.model_id,
            body=json.dumps(
                {
                    "anthropic_version": "bedrock-2023-05-31",
                    "max_tokens": query.max_tokens,
                    "system": SYSTEM_PROMPT.format(context=wrap_context(query.context)),
                    "messages": [{"role": "user", "content": query.user_message}],
                }
            ),
        )
        response_body = json.loads(bedrock_response.get("body").read())
        logger.info("Received LLM response", response_body=response_body)
        response_text = response_body.get("content", [{}])[0].get(
            "text", "LLM did not respond with text"
        )
        return parse_completion(response_text)
    
    @logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
    def lambda_handler(event: dict, context: LambdaContext) -> dict:
        return app.resolve(event, context)
    

  2. Create API Gateway Rest API for a lambda representative of the lambda function of a relaxing API. You can follow this lesson to make a lambda's recreation API through API Gateway Console. By creating a compilation of the lambda representative and the proxy resource, we can submit applications to the Lambda work resources. Follow the tutorial to use the API and give attention to an API URL. Ensure to schedule adequate access to an API for relaxation.

We can now ask and test our work with an API URL urges the URL. The following example uses curl Sending (Make sure to replace all the braces first as required), and the answer issued by the LLM:

$ curl --header "Authorization: {token}" 
     --header "Content-Type: application/json" 
     --request POST 
     --data '{"user_message": "Write a 2 sentence summary about AWS."}' 
      | jq .
{
 "completion": "nTo summarize AWS in 2 sentences:n1. AWS (Amazon Web Services) is a comprehensive cloud computing platform offering a wide range of services like computing power, database storage, content delivery, and more.n2. It allows organizations and individuals to access these services over the internet on a pay-as-you-go basis without needing to invest in on-premises infrastructure.nnnennnnnAWS (Amazon Web Services) is a cloud computing platform that offers a broad set of global services including computing, storage, databases, analytics, machine learning, and more. It enables companies of all sizes to access these services over the internet on a pay-as-you-go pricing model, eliminating the need for upfront capital expenditure or on-premises infrastructure management.nn",
 "thinking": "To summarize AWS in 2 sentences:n1. AWS (Amazon Web Services) is a comprehensive cloud computing platform offering a wide range of services like computing power, database storage, content delivery, and more.n2. It allows organizations and individuals to access these services over the internet on a pay-as-you-go basis without needing to invest in on-premises infrastructure.",
 "user_language": "en",
 "response": "AWS (Amazon Web Services) is a cloud computing platform that offers a broad set of global services including computing, storage, databases, analytics, machine learning, and more. It enables companies of all sizes to access these services over the internet on a pay-as-you-go pricing model, eliminating the need for upfront capital expenditure or on-premises infrastructure management."
} 

If required, the services created can be cleaned by 1) remove the API Gateway Pred API, and 2) to remove the API lambda resting work with the Related IAM role.

Example Use charges

Creating a practical experience, the office transmission meets the power of a revision cloud that uses the power of additional content restored to JavaScript API office.

Next, we show that two different cases are supported by the proposed solution, the generation of the Scriptures.

The generation of the text


Figure 2: A generation generation used for the text

In demo in Figure 2, we show how the plug-in output llm is to produce text from the beginning. The user logs in their question on a scenario in the Input of the Insert Input. When you send, the backend will move the llm to use the correct text, and return forward. From the Inggela, it is included in the text text in the cursor using the JavaScript API office.

Text refine


Figure 3: Analysis of the use of Demord Use

In Figure 3, the user highlighted part of the text in the workplace and quickly entered the installation center to replace text text. Also, the printing user and the highlighted text is set up by backend and is added, thus replacing the previous text.

Store

This blog post indicates how the Anni power can be produced in office processes. We have described the end-ending sample of consolidation products by an add-to-generation supplementary supply and glimpse of llMs. In our example, we used llms held at Amazon Bedrock to work for the generation of the text. Backend is held as totally defective application in AWS Cloud.

The generation of the text and office of the office supports employees by directing their writing process and improving productivity. Employees can gain the strength of producing AI to produce and plan quality quality content immediately, releases the time of other functions. Additionally, integration with a common tool as a word like the word provides a seamless user experience, reduce the inconvenience of the existing service.

To learn more about growing productivity, creating different experiences, and performing new items immediately with AWS Visit AWS AWS.


About the authors

Martin Maritsch You are the general AWA Prosvave AI key focused on AI and MLOPS. You help business customers to achieve business results by unlocking the full power of AI / ML Services on the AW Cloud.

Miguel Pestana The construction of the cloud in the AWS Professional Services team for more than 4 years of experience in the automotive industry in the CLoud Facilive solutions. Without work Miguel enjoyed spending their days on a beach or a padel racket in one hand and a glass of sangria.

Carlos Antonio Perea Gomez You are the builder with the AWS Professional Services. He gives power to customers to be good during their journey in the cloud. When he is not in the cloud you enjoy the deep scuba of the water.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button