diff --git a/workshops/Multi_lingual_Llama_3.1.ipynb b/workshops/Multi_lingual_Llama_3.1.ipynb new file mode 100644 index 0000000..73dda53 --- /dev/null +++ b/workshops/Multi_lingual_Llama_3.1.ipynb @@ -0,0 +1,856 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a611416f-45b7-4f5e-b7a5-fa1b1cb0b6a3", + "metadata": {}, + "source": [ + "# Llama 3.1: Using the Multilingual capabilities for real-world use cases" + ] + }, + { + "cell_type": "markdown", + "id": "7ddd2fe9-ded1-4682-9347-6486d1bf5dbe", + "metadata": { + "tags": [] + }, + "source": [ + "This notebook should work well with the Data Science 3.0 kernel in SageMaker Studio.\n", + "\n", + "This guide is designed to assist you in leveraging Llama 3.1's multilingual / translation capabilities with Bedrock Converse API for practical use cases for scenarios where English may not be needed. Our goal is to demonstrate how Llama 3.1 can be used for native lanugages to cover a broader expansion of regions globally. This notebook will provide a strong foundation for creating multilingual / translation applications.\n", + "\n", + "We will begin by reviewing how to leverage the Amazon Bedrock Converse API. Once we are familiarized with the Converse API, we will generate some sample prompts to be used to explore Llama 3.1's new capability to address multilingual scenarios." + ] + }, + { + "cell_type": "markdown", + "id": "6baf1453-083b-4001-8b0e-2eb53f4fd30d", + "metadata": { + "tags": [] + }, + "source": [ + "## Llama 3.1" + ] + }, + { + "cell_type": "markdown", + "id": "464111b1-8c95-4bce-9345-421a60af527f", + "metadata": { + "tags": [] + }, + "source": [ + "Llama 3.1 is a high-quality open-source language model developed by Meta. It is designed for a wide range of natural language processing tasks, including text generation, question answering, and more.\n", + "Llama 3.1 has the following key features:\n", + " \n", + "- Proficient in several languages, including English, French, Italian, German, Spanish, and others.\n", + "- Context window of up to 128k tokens, allowing for long-form text processing.\n", + "- Capable of handling various tasks, such as text generation, summarization, and question answering.\n", + "- Generates coherent and fluent responses." + ] + }, + { + "cell_type": "markdown", + "id": "3dd2c034-a9b7-4ba8-b4db-2eb03f54f99e", + "metadata": {}, + "source": [ + "## Multilingual Capabilities with Llama 3.1" + ] + }, + { + "cell_type": "markdown", + "id": "e9105c8a-0734-47a2-8e95-7e6671022f63", + "metadata": {}, + "source": [ + "Llama 3.1 offers robust multilingual capabilities, supporting a range of languages that enhance its utility for diverse applications. Specifically, Llama 3.1 has been trained to handle conversations in multiple languages including Spanish, Portuguese, Italian, German, Thai, French, and Hindi. This multilingual support makes it suitable for a wide array of uses across different regions. The model's multilingual abilities are part of its broader capabilities, which include state-of-the-art performance in translation tasks.\n", + "\n", + "In this notebook, we will go over a few practical real-world use cases (add one more sentences)" + ] + }, + { + "cell_type": "markdown", + "id": "61225d7f-b887-47ee-9f52-3455b4a5ba11", + "metadata": {}, + "source": [ + "## Prerequisites:\n", + "- AWS SDK for Python (Boto3): Ensure you have the Boto3 library installed.\n", + "- Amazon Bedrock Model ID: Obtain the model ID for the conversational AI model you wish to use.\n", + "- AWS Credentials: Configure your AWS credentials to authenticate API requests." + ] + }, + { + "cell_type": "markdown", + "id": "7488c400-9fbd-4ffc-812f-bbdd1d83b6f1", + "metadata": {}, + "source": [ + "## Import necessary libraries\n", + "\n", + "In the next cell, we will set up our environment by importing the boto3 library and necessary libraries that we will need to confiure our bedrock client to invoke our llama 3.1 model within the Amazon Bedrock Converse API." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d837fe60-6869-4430-8457-342ca9492bcb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import boto3\n", + "from boto3 import client\n", + "from botocore.config import Config\n", + "import json\n", + "import re\n", + "import logging\n", + "from botocore.exceptions import ClientError\n", + "logger = logging.getLogger(__name__)\n", + "logging.basicConfig(level=logging.INFO)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "eb76dfbe-83b8-4855-a197-5a1f0303e8d3", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:botocore.credentials:Found credentials from IAM Role: BaseNotebookInstanceEc2InstanceRole\n" + ] + } + ], + "source": [ + "config = Config(read_timeout=2000)\n", + "bedrock_client = boto3.client(service_name='bedrock-runtime', region_name=\"us-west-2\", config=config)" + ] + }, + { + "cell_type": "markdown", + "id": "f8dc6873-974e-498b-b7c0-bdb3bb29b01d", + "metadata": {}, + "source": [ + "## Instantiate llama 3.1 model " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "097393a5-c646-4102-9210-61e1b20eb9b9", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "meta_llama_3_1_8b = 'meta.llama3-1-8b-instruct-v1:0'\n", + "meta_llama_3_1_70b = 'meta.llama3-1-70b-instruct-v1:0'\n", + "\n", + "model_id = meta_llama_3_1_8b" + ] + }, + { + "cell_type": "markdown", + "id": "db6dd3d2-c7b9-4850-a65a-f63326506418", + "metadata": {}, + "source": [ + "## Prompting with Amazon Bedrock Converse API\n", + "\n", + "The Amazon Bedrock Converse API can be used to invoke large language models on Amazon Bedrock by extracting away the special stop tokens and facilitate the creation of conversational applications by enabling the exchange of messages between users and Amazon Bedrock models.\n", + "\n", + "**Key features include:**\n", + "- **Consistent Interface:**\n", + "The Converse API provides a uniform interface that works across all Amazon Bedrock models supporting messages. This consistency allows developers to write code once and use it with different models without needing to adjust for model-specific differences.\n", + "\n", + "- **Turn-Based Conversations:**\n", + "The API supports multi-turn conversations, where a series of messages are exchanged between the user (acting as the user role) and the model (acting as the assistant role). This enables the development of chatbots and other conversational agents that can maintain context over multiple interactions.\n", + "\n", + "- **Tool Use (Function Calling):**\n", + "The Converse API supports tool use, allowing models to request the invocation of external functions or tools. This is particularly useful for tasks that require interaction with external APIs or services. The model generates a JSON structure with the necessary parameters, which the calling application then uses to invoke the specified tool" + ] + }, + { + "cell_type": "markdown", + "id": "155dc769-4221-4355-b9fe-23f1ef468a70", + "metadata": { + "tags": [] + }, + "source": [ + "## Prompting with the Bedrock Converse API\n", + "\n", + "After setting your model ID as llama 3.1 8b model, to start interfacing with the converse API - you can put the prompt input inside the content section.\n", + "\n", + "Listed below is an example of how you can change / assign the different roles and add input to the role." + ] + }, + { + "cell_type": "markdown", + "id": "d4445564-13a7-4710-a206-a2a3f75246a5", + "metadata": { + "tags": [] + }, + "source": [ + "#### Prompting with Converse API on Bedrock\n", + "\n", + "```\n", + "{\n", + " \"role\": \"user | assistant\",\n", + " \"content\": [\n", + " {\n", + " \"text\": \"string\"\n", + " }\n", + " ]\n", + "}\n", + "```\n", + "\n", + "In the next cell, we will use llama 3.1 to generate a few questions that we will use to be allow us to have a conversation in French." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b13bd9c4-7dd1-4ca8-8008-807b7e380400", + "metadata": {}, + "outputs": [], + "source": [ + "# Define the message with content as a list\n", + "message = {\n", + " \"role\": \"user\",\n", + " \"content\": [\n", + " {\"text\": \"Can you provide me few example prompts of questions I would need to ask if I were to go on a trip to Paris.\"}\n", + " ]\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "6edcfac6-2df4-4343-bfe2-94995ba8e434", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "response = bedrock_client.converse(\n", + " modelId=model_id,\n", + " messages=[message], # Wrap the message in a list\n", + " inferenceConfig={\n", + " \"maxTokens\": 2000,\n", + " \"temperature\": 0,\n", + " \"topP\": .5\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6b9b3631-efbf-43d0-b6d5-b15122654623", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Here are some example prompts of questions you might want to ask if you were planning a trip to Paris:\n", + "\n", + "**Accommodation**\n", + "\n", + "* What are the best neighborhoods to stay in Paris for a first-time visitor?\n", + "* What are the prices like for hotels, hostels, and Airbnb apartments in Paris?\n", + "* Can you recommend any budget-friendly options for accommodation in Paris?\n", + "* How do I book a hotel or apartment in Paris, and what's the best way to ensure it's legitimate?\n", + "\n", + "**Transportation**\n", + "\n", + "* What are the best ways to get to Paris from the airport (CDG or ORY)?\n", + "* How does the Paris public transportation system work, and what are the best options for getting around the city?\n", + "* Can I buy a Paris Visite pass, and what does it include?\n", + "* Are there any bike-sharing programs or car rental options available in Paris?\n", + "\n", + "**Food and Drink**\n", + "\n", + "* What are some must-try foods and drinks in Paris, and where can I find them?\n", + "* Can you recommend any good restaurants or cafes in Paris for a budget-conscious traveler?\n", + "* How do I order food and drinks in a Parisian cafe or restaurant, and what are some common phrases to know?\n", + "* Are there any food markets or street food options in Paris that I shouldn't miss?\n", + "\n", + "**Attractions and Activities**\n", + "\n", + "* What are the top attractions to visit in Paris, and how can I skip the lines?\n", + "* Can you recommend any free or low-cost activities to do in Paris, such as visiting museums or parks?\n", + "* How do I buy tickets for popular attractions like the Eiffel Tower or Louvre Museum?\n", + "* Are there any guided tours or walking tours available in Paris that I can join?\n", + "\n", + "**Safety and Precautions**\n", + "\n", + "* What are the safety concerns I should be aware of in Paris, and how can I stay safe?\n", + "* Can you recommend any areas of Paris to avoid, and why?\n", + "* How do I report a crime or lost item in Paris, and what are the emergency services numbers?\n", + "* Are there any health concerns I should be aware of in Paris, such as vaccinations or medications?\n", + "\n", + "**Miscellaneous**\n", + "\n", + "* What are the best ways to communicate with locals in Paris, and what are some common phrases to know?\n", + "* Can you recommend any good shopping areas or markets in Paris?\n", + "* How do I navigate the Parisian bureaucracy, such as getting a SIM card or opening a bank account?\n", + "* Are there any cultural or historical events or festivals happening in Paris during my visit that I shouldn't miss?\n" + ] + } + ], + "source": [ + "# Extract the 'text' content from the response\n", + "text_content = response['output']['message']['content'][0]['text']\n", + "\n", + "# Replace newline escape sequences ('\\\\n') with actual newline characters\n", + "formatted_text = text_content.replace('\\\\n', '\\n')\n", + "\n", + "# Print the formatted text\n", + "print(formatted_text)" + ] + }, + { + "cell_type": "markdown", + "id": "3ef34616-04b2-4e7d-b715-aaa805050303", + "metadata": {}, + "source": [ + "In the cell above, we can see that Llama 3.1 was able to successfully generate some sample questions in English. We will use these questions later on in the notebook to prompt Llama 3.1 to have a full conversation in French. But first, let's go into a few of the multilingual translation basics." + ] + }, + { + "cell_type": "markdown", + "id": "db34a263-5afd-448a-8519-ff449e8d3347", + "metadata": {}, + "source": [ + "## Multi-lingual use case capabilities: Translation" + ] + }, + { + "cell_type": "markdown", + "id": "6259dfb4-bfa4-411e-95db-a11bf06e5895", + "metadata": {}, + "source": [ + "Llama 3.1 supports a variety of languages, allowing developers to build applications and services that cater to users from diverse linguistic backgrounds by offering multilingual capabilities that can be leveraged to create localized user interfaces and provide language-specific content. Specifically, Llama 3.1 supports languages such as English, French, German, Spanish, Italian, Portuguese, Hindi and Thai.\n", + "\n", + "For translating telephone conversations into different languages like Hindi, Arabic, Korean, and Japanese, Llama 3.1 can be utilized effectively. In the next cell, we will demonstrate how a bank teller and customer conversation that is held in English can be translated to various languages." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "07b6c958-4de1-4cb2-af51-83112137579d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "conversation = \"\"\"\n", + "Customer: \"Hi, I recently opened a new account with your bank and I love the online banking features! Can you guide me on how to set up different alerts for each type of transaction I make?\"\n", + "Teller: \"Hello! I'm glad to hear you're enjoying our services. Setting up transaction alerts is simple. You can customize them through our online banking portal. Let me walk you through the process.\"\n", + "Customer: \"I'm trying to use the mobile banking app, but it doesn't seem to be registering my login attempts. Could you help me figure out what might be going wrong?\"\n", + "Teller: \"Of course! Let's troubleshoot this together. First, ensure that your username and password are correct. If you're still having issues, try resetting your password or updating the app to the latest version.\" \n", + "Customer: \"I'm considering opening a savings account and I'm curious about the interest rates. What options are available and what are their main differences?\"\n", + "Teller: \"Great question! We offer several savings account options with varying interest rates. Our standard savings account has a competitive rate, while our high-yield account offers a higher rate for larger balances. I can provide more details on each.\"\n", + "Customer: \"I wanted to report a small issue where my debit card was a bit sticky. However, your quick-start guide was super helpful and I fixed it easily by following the cleaning tips. Just thought you might want to know!\"\n", + "Teller: \"Thanks for letting us know. I'm glad the guide was helpful. If you encounter any more issues, feel free to reach out, and we'll be happy to assist further.\" \n", + "Customer: \"My new debit card stopped working within a week of receiving it. None of the transactions go through, and I need a solution or a replacement as soon as possible.\"\n", + "Teller: \"I'm sorry to hear that. Let's resolve this quickly. Please check if the card is activated and try using a different ATM. If it still doesn't work, we'll issue a replacement card right away.\" \n", + "Customer: \"I've noticed that the numbers on my debit card are starting to fade after several months of use. Is this covered by the warranty?\"\n", + "Teller: \"Yes, card wear and tear is covered. Please bring your card to our branch, and we'll assist you with a replacement at no charge.\" \n", + "Customer: \"I had an issue where my account settings would reset every time I logged in. I figured out it was due to a browser conflict and resolved it by clearing my cache. Just wanted to ask if there are any new updates coming soon?\"\n", + "Teller: \"Good job on resolving the issue. We do roll out updates regularly to improve our online services. Keep an eye on our website or subscribe to our newsletter for the latest updates.\" \n", + "Customer: \"I've been having trouble with the online banking portal not saving my preferences, and it's starting to get frustrating. What can be done to ensure my settings are saved permanently?\"\n", + "Teller: \"I understand your frustration. Make sure you're using the latest version of your browser. Also, try adjusting your browser settings to allow cookies, which can help save your preferences.\"\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "id": "6664b865-9b41-49c1-b70c-4becdae5c1ae", + "metadata": {}, + "source": [ + "Here we will allow llama 3.1 to translate each of the following transcripted calls into different langauges by creating different prompts for Hindi, Spanish, german and italian. These prompts will all be used to ingest the conversation and translate into the native given language." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "9eec770a-5e60-47a3-8ec2-d962be30a3e7", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "#prompts for language tasks/ translation\n", + "\n", + "hindi_prompt = f\"\"\"\n", + "Translate the following conversation into Hindi. Your responses must be numbered, only in Hindi, and must adhere to only translating the conversation.\n", + "\n", + "{conversation}\n", + "\"\"\"\n", + "\n", + "spanish_prompt = f\"\"\"\n", + "Translate the following conversation into Spanish. Your responses must be numbered, only in Spanish, and must adhere to only translating the conversation.\n", + "\n", + "{conversation}\n", + "\"\"\"\n", + "\n", + "german_prompt = f\"\"\"\n", + "Translate the following conversation into German. Your responses must be numbered, only in German, and must adhere to only translating the conversation.\n", + "\n", + "{conversation}\n", + "\"\"\"\n", + "\n", + "italian_prompt = f\"\"\"\n", + "Translate the following conversation into Italian. Your responses must be numbered, only in Italian, and must adhere to only translating the conversation.\n", + "\n", + "{conversation}\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "e2827e8c-6122-47f3-a4ce-23148ab181a3", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "1. ग्राहक: \"नमस्ते, मैंने हाल ही में आपके बैंक में एक नया खाता खोला है और मैं ऑनलाइन बैंकिंग फीचर्स से बहुत प्यार करता हूँ! कृपया मुझे बताएं कि कैसे मैं प्रत्येक प्रकार के लेनदेन के लिए अलग-अलग अलर्ट सेट कर सकता हूँ?\"\n", + "2. टेलर: \"नमस्ते! मैं आपको यह सुनकर खुश हूँ कि आप हमारी सेवाओं से आनंद ले रहे हैं। लेनदेन अलर्ट सेट करना सरल है। आप उन्हें हमारे ऑनलाइन बैंकिंग पोर्टल के माध्यम से कस्टमाइज़ कर सकते हैं। मैं आपको प्रक्रिया के माध्यम से चलने में मदद करूंगा।\"\n", + "3. ग्राहक: \"मैं मोबाइल बैंकिंग ऐप का उपयोग करने की कोशिश कर रहा हूँ, लेकिन यह मेरे लॉगिन प्रयासों को रजिस्टर नहीं कर रहा है। कृपया मुझे यह स्पष्ट करने में मदद करें कि क्या गलत हो सकता है?\"\n", + "4. टेलर: \"बिल्कुल! आइए इसे साथ में हल करें। सबसे पहले, सुनिश्चित करें कि आपका यूजरनेम और पासवर्ड सही हैं। यदि आप अभी भी समस्याओं का सामना कर रहे हैं, तो अपना पासवर्ड रीसेट करें या ऐप को नवीनतम संस्करण में अपडेट करें।\"\n", + "5. ग्राहक: \"मैं एक बचत खाता खोलने की सोच रहा हूँ और मैं जानना चाहता हूँ कि क्या विकल्प उपलब्ध हैं और उनके मुख्य अंतर क्या हैं।\"\n", + "6. टेलर: \"उत्तम प्रश्न! हम कई बचत खाता विकल्प प्रदान करते हैं जिनमें विभिन्न ब्याज दरें हैं। हमारा मानक बचत खाता एक प्रतिस्पर्धी दर प्रदान करता है, जबकि हमारा उच्च-लाभ खाता बड़े शेष राशि के लिए उच्च दर प्रदान करता है। मैं प्रत्येक के बारे में अधिक विवरण प्रदान कर सकता हूँ।\"\n", + "7. ग्राहक: \"मैं एक छोटी समस्या की रिपोर्ट करना चाहता हूँ जहां मेरा डेबिट कार्ड थोड़ा चिपचिपा था। हालांकि, आपका क्विक-स्टार्ट गाइड बहुत मददगार था और मैं इसे आसानी से ठीक कर सका कि मैं साफिंग टिप्स का पालन करके इसे साफ कर सका। बस यह जानने के लिए कि आप क्या चाहते हैं!\"\n", + "8. टेलर: \"धन्यवाद आपका बताने के लिए। मैं आपको यह बताने में खुश हूँ कि गाइड आपके लिए उपयोगी था। यदि आप और भी समस्याओं का सामना करते हैं, तो कृपया हमसे संपर्क करें और हम आपकी मदद करने के लिए तैयार रहेंगे।\"\n", + "9. ग्राहक: \"मेरा नया डेबिट कार्ड एक सप्ताह के भीतर काम करना बंद कर दिया। कोई भी लेनदेन नहीं हो रहा है और मुझे एक समाधान या एक प्रतिस्थापन की आवश्यकता है।\"\n", + "10. टेलर: \"मैं आपको यह सुनकर दुखी हूँ। आइए इसे जल्दी से हल करें। कृपया यह जांचें कि कार्ड सक्रिय है और एक अलग एटीएम का उपयोग करने का प्रयास करें। यदि यह भी काम नहीं करता है, तो हम एक प्रतिस्थापन कार्ड जारी करेंगे।\"\n", + "11. ग्राहक: \"मैंने देखा है कि मेरे डेबिट कार्ड के नंबर कई महीनों के उपयोग के बाद धुंधले हो गए हैं। यह वारंटी के तहत कवर किया जाता है?\"\n", + "12. टेलर: \"हाँ, कार्ड का पहनावा वारंटी के तहत कवर किया जाता है। कृपया अपना कार्ड हमारे शाखा में लाएं और हम आपकी मदद करेंगे।\"\n", + "13. ग्राहक: \"मैं एक समस्या का सामना कर रहा था जहां मेरे खाता सेटिंग्स हर बार लॉगिन करने पर रीसेट हो जाते थे। मैंने यह पता लगाया कि यह एक ब्राउज़र के साथ संघर्ष के कारण था और मैंने इसे हल करने के लिए अपने कैश को साफ कर दिया। बस यह पूछने के लिए कि क्या जल्द ही कोई अपडेट आ रहा है।\"\n", + "14. टेलर: \"आपको समस्या हल करने के लिए धन्यवाद। हम ऑनलाइन सेवाओं को बेहतर बनाने के लिए नियमित रूप से अपडेट करते हैं। अपनी वेबसाइट पर या हमारे समाचार पत्र के लिए सदस्यता लेकर नवीनतम अपडेट की जांच करें।\"\n", + "15. ग्राहक: \"मैं ऑनलाइन बैंकिंग पोर्टल पर अपने पसंदीदा को सेव नहीं कर पा रहा हूँ और यह मुझे परेशान कर रहा है। क्या किया जा सकता है ताकि मेरे सेटिंग्स स्थायी रूप से सेव हो जाएं?\"\n", + "16. टेलर: \"मैं आपकी परेशानी को समझता हूँ। सुनिश्चित करें कि आप नवीनतम संस्करण का उपयोग कर रहे हैं। इसके अलावा, अपने ब्राउज़र सेटिंग्स में कुकीज़ को अनुमति देने का प्रयास करें, जो आपकी पसंदीदा को सेव करने में मदद कर सकता है।\"\n" + ] + } + ], + "source": [ + "def converse(prompt, inference_config):\n", + " messages = [{\"role\": \"user\", \"content\": [{\"text\": prompt}]}]\n", + " response = bedrock_client.converse(\n", + " messages=messages,\n", + " modelId=model_id,\n", + " inferenceConfig=inference_config\n", + " )\n", + " generated_text = response['output']['message']['content'][0]['text']\n", + " print(generated_text)\n", + " return generated_text, response\n", + "\n", + "inference_config = {\"temperature\": 0.0, \"maxTokens\": 2048, \"topP\": 0.1}\n", + "\n", + "#hindi prompt with llama 3.1\n", + "generated_text, response = converse(hindi_prompt, inference_config)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "4efee676-1c62-42e3-95d0-166e2914f029", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "1. Cliente: \"Hola, recientemente abrí una nueva cuenta en su banco y me encantan las características de banca en línea! ¿Puede guiarme sobre cómo configurar diferentes alertas para cada tipo de transacción que realice?\"\n", + "2. Teller: \"¡Hola! Me alegra saber que están disfrutando de nuestros servicios. Configurar alertas de transacciones es sencillo. Pueden personalizarlas a través de nuestra plataforma de banca en línea. Déjeme guiarlo a través del proceso.\"\n", + "3. Cliente: \"Estoy tratando de usar la aplicación de banca móvil, pero no parece registrar mis intentos de inicio de sesión. ¿Puede ayudarme a averiguar qué podría estar pasando mal?\"\n", + "4. Teller: \"Por supuesto! Vamos a resolver esto juntos. Primero, asegúrese de que su nombre de usuario y contraseña sean correctos. Si aún tiene problemas, intente restablecer su contraseña o actualizar la aplicación a la última versión.\"\n", + "5. Cliente: \"Estoy considerando abrir una cuenta de ahorros y estoy curioso sobre las tasas de interés. ¿Qué opciones están disponibles y cuáles son sus principales diferencias?\"\n", + "6. Teller: \"Excelente pregunta! Ofrecemos varias opciones de cuentas de ahorros con tasas de interés variables. Nuestra cuenta de ahorros estándar tiene una tasa competitiva, mientras que nuestra cuenta de ahorros de alto rendimiento ofrece una tasa más alta para saldos más grandes. Puedo proporcionar más detalles sobre cada una.\"\n", + "7. Cliente: \"Quería informar un pequeño problema donde mi tarjeta de débito estaba un poco pegajosa. Sin embargo, su guía de inicio rápido fue super útil y lo resolví fácilmente siguiendo las pautas de limpieza. Solo quería que lo supiera!\"\n", + "8. Teller: \"Gracias por informarnos. Me alegra que la guía fuera útil. Si encuentran más problemas, no dude en hacernos saber y estaremos encantados de ayudar más.\"\n", + "9. Cliente: \"Mi nueva tarjeta de débito dejó de funcionar dentro de una semana de recibirla. Ninguna de las transacciones funcionan, y necesito una solución o una reemplazo lo antes posible.\"\n", + "10. Teller: \"Lo siento mucho. Vamos a resolver esto rápidamente. Por favor, verifique si la tarjeta está activada y intente usar un cajero automático diferente. Si no funciona, emitiremos una nueva tarjeta de inmediato.\"\n", + "11. Cliente: \"He notado que los números de mi tarjeta de débito están empezando a desvanecerse después de varios meses de uso. ¿Esto está cubierto por la garantía?\"\n", + "12. Teller: \"Sí, el desgaste de la tarjeta está cubierto. Por favor, traiga su tarjeta a nuestra sucursal y asistiremos con una reemplazo sin cargo.\"\n", + "13. Cliente: \"Tengo un problema donde mis ajustes de cuenta se resetean cada vez que inicio sesión. Creo que lo resolví porque era un conflicto de navegador y lo resolví limpiando mi caché. Solo quería preguntar si hay actualizaciones nuevas en camino?\"\n", + "14. Teller: \"Bien hecho por resolver el problema. Hacemos actualizaciones regulares para mejorar nuestros servicios en línea. Manténgase al tanto de nuestro sitio web o suscríbase a nuestro boletín para obtener las últimas actualizaciones.\"\n", + "15. Cliente: \"He tenido problemas con la plataforma de banca en línea no guardando mis preferencias, y está empezando a ser frustrante. ¿Qué se puede hacer para asegurarme de que mis ajustes se guarden permanentemente?\"\n", + "16. Teller: \"Entiendo su frustración. Asegúrese de que esté utilizando la última versión de su navegador. También intente ajustar sus ajustes de navegador para permitir cookies, que pueden ayudar a guardar sus preferencias.\"\n" + ] + } + ], + "source": [ + "#arabic prompt with llama 3.1\n", + "generated_text, response = converse(spanish_prompt, inference_config)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "253b1ad1-29a6-422d-9f6e-f38c75cf30d0", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "1. Kunde: \"Hallo, ich habe kürzlich ein neues Konto bei Ihrer Bank eröffnet und liebe die Funktionen im Online-Banking! Könnten Sie mir bitte zeigen, wie ich verschiedene Benachrichtigungen für jede Art von Transaktion einrichten kann?\"\n", + "2. Teller: \"Hallo! Ich bin froh, dass Sie unsere Dienstleistungen genießen. Die Einrichtung von Transaktionsbenachrichtigungen ist einfach. Sie können sie durch unser Online-Banking-Portal anpassen. Lassen Sie mich Ihnen durch den Prozess führen.\"\n", + "3. Kunde: \"Ich versuche, die mobile Banking-App zu verwenden, aber sie registriert meine Anmeldeversuche nicht. Könnten Sie mir helfen, herauszufinden, was möglicherweise schief läuft?\"\n", + "4. Teller: \"Natürlich! Lassen Sie uns gemeinsam dieses Problem lösen. Zuerst stellen Sie sicher, dass Ihr Benutzername und Ihr Passwort korrekt sind. Wenn Sie immer noch Probleme haben, versuchen Sie, Ihr Passwort zu ändern oder die App auf die neueste Version zu aktualisieren.\"\n", + "5. Kunde: \"Ich überlege, ein Sparkonto zu eröffnen und bin neugierig auf die Zinssätze. Welche Optionen stehen zur Verfügung und wie unterscheiden sie sich voneinander?\"\n", + "6. Teller: \"Großartige Frage! Wir bieten mehrere Sparkonten mit unterschiedlichen Zinssätzen an. Unser Standard-Sparkonto hat einen wettbewerbsfähigen Zinssatz, während unser High-Yield-Konto einen höheren Zinssatz für größere Konten bietet. Ich kann Ihnen mehr Details über jede Option geben.\"\n", + "7. Kunde: \"Ich wollte eine kleine Angelegenheit melden, bei der mein Debitkarte ein bisschen klebrig war. Allerdings war die Schnellstartanleitung super hilfreich und ich habe es leicht durchgeführt, indem ich die Reinigungstipps befolgt habe. Ich dachte, Sie sollten es wissen!\"\n", + "8. Teller: \"Danke für die Information. Ich bin froh, dass die Anleitung hilfreich war. Wenn Sie weitere Probleme haben, zögern Sie nicht, sich an uns zu wenden, und wir werden Ihnen gerne weiterhelfen.\"\n", + "9. Kunde: \"Meine neue Debitkarte funktionierte innerhalb einer Woche nach Erhalt nicht mehr. Keine Transaktionen gehen durch, und ich brauche eine Lösung oder einen Ersatz so schnell wie möglich.\"\n", + "10. Teller: \"Ich entschuldige mich, dass Sie das erleben müssen. Lassen Sie uns dies schnell lösen. Bitte überprüfen Sie, ob die Karte aktiviert ist, und versuchen Sie, sie an einem anderen Geldautomaten zu verwenden. Wenn sie immer noch nicht funktioniert, erteilen wir Ihnen einen Ersatzkarten sofort.\"\n", + "11. Kunde: \"Ich habe bemerkt, dass die Ziffern auf meiner Debitkarte nach einigen Monaten des Gebrauchs anfangen zu verblassen. Ist dies durch die Garantie abgedeckt?\"\n", + "12. Teller: \"Ja, das Abnutzen der Karte ist abgedeckt. Bitte bringen Sie Ihre Karte in unser Filial, und wir werden Ihnen gerne einen Ersatzkarten zugeteilt.\"\n", + "13. Kunde: \"Ich hatte ein Problem, bei dem meine Kontoeinstellungen sich bei jedem Anmelden zurücksetzten. Ich habe herausgefunden, dass es aufgrund eines Browser-Konflikts war und habe es durch das Löschen meines Caches gelöst. Ich wollte fragen, ob es bald neue Updates gibt?\"\n", + "14. Teller: \"Gute Arbeit, das Problem zu lösen. Wir rollen regelmäßig Updates aus, um unsere Online-Dienste zu verbessern. Halten Sie die Augen auf unsere Website oder abonnieren Sie unseren Newsletter, um die neuesten Updates zu erhalten.\"\n", + "15. Kunde: \"Ich habe Schwierigkeiten mit dem Online-Banking-Portal, das meine Einstellungen nicht speichert. Es wird immer frustrierender. Was kann getan werden, um sicherzustellen, dass meine Einstellungen dauerhaft gespeichert werden?\"\n", + "16. Teller: \"Ich verstehe Ihre Frustration. Stellen Sie sicher, dass Sie die neueste Version Ihres Browsers verwenden. Versuchen Sie auch, Ihre Browser-Einstellungen anzuzeigen, um Cookies zuzulassen, die helfen können, Ihre Einstellungen zu speichern.\"\n" + ] + } + ], + "source": [ + "#german prompt with llama 3.1\n", + "generated_text, response = converse(german_prompt, inference_config)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "168c9a1b-ff1c-4bbe-99e8-e4770f6517b4", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "1. Cliente: \"Ciao, ho appena aperto un nuovo conto con la vostra banca e mi piacciono molto le funzionalità di banca online! Potreste guidarmi su come impostare diversi avvisi per ogni tipo di transazione che effettuo?\"\n", + "2. Teller: \"Ciao! Sono felice di sentire che stai godendo dei nostri servizi. Impostare gli avvisi di transazione è semplice. Puoi personalizzarli attraverso il nostro portale di banca online. Vi lascio guidare attraverso il processo.\"\n", + "3. Cliente: \"Sto cercando di utilizzare l'app di banca mobile, ma non sembra registrare i miei tentativi di accesso. Potreste aiutarmi a capire cosa potrebbe andare storto?\"\n", + "4. Teller: \"Certo! Lasciamo risolvere questo insieme. Prima assicurati che il tuo username e password siano corretti. Se hai ancora problemi, prova a resettare la password o aggiornare l'app alla versione più recente.\"\n", + "5. Cliente: \"Sto considerando di aprire un conto di risparmio e sono curioso sulle tariffe di interesse. Quali opzioni sono disponibili e quali sono le loro principali differenze?\"\n", + "6. Teller: \"Grande domanda! Offriamo diverse opzioni di conto di risparmio con tariffe di interesse diverse. Il nostro conto di risparmio standard ha una tariffe competitiva, mentre il nostro conto di risparmio ad alto rendimento offre una tariffe più alta per saldi più grandi. Posso fornire ulteriori dettagli su ciascuno.\"\n", + "7. Cliente: \"Volevo segnalare un piccolo problema dove la mia carta di debito era un po' appiccicosa. Tuttavia, il vostro manuale di avvio rapido era super utile e ho risolto facilmente seguendo le indicazioni di pulizia. Solo volevo farvi sapere!\"\n", + "8. Teller: \"Grazie per averci fatto sapere. Sono felice che il manuale sia stato utile. Se incontri altri problemi, non esitare a contattarci e saremo felici di aiutarti ulteriormente.\"\n", + "9. Cliente: \"La mia nuova carta di debito non funziona dopo una settimana di ricezione. Nessuna delle transazioni va a buon fine, e ho bisogno di una soluzione o una sostituzione il prima possibile.\"\n", + "10. Teller: \"Mi dispiace sentire questo. Lasciamo risolvere questo velocemente. Per favore, controlla se la carta è attivata e prova a utilizzare un ATM diverso. Se non funziona ancora, emetteremo una nuova carta immediatamente.\"\n", + "11. Cliente: \"Ho notato che i numeri sulla mia carta di debito iniziano a sbiadire dopo alcuni mesi di utilizzo. È questo coperto dalla garanzia?\"\n", + "12. Teller: \"Sì, il deterioramento della carta è coperto. Porta la tua carta alla nostra filiale e ti aiuteremo con una sostituzione gratuita.\"\n", + "13. Cliente: \"Ho avuto un problema dove le impostazioni del mio conto si resettavano ogni volta che mi accedevo. Ho risolto il problema scoprendo che era dovuto a un conflitto del browser e ho risolto il problema cancellando la cache. Volevo chiedere se ci sono aggiornamenti nuovi in arrivo?\"\n", + "14. Teller: \"Bravo per aver risolto il problema. Noi rilasciamo aggiornamenti regolarmente per migliorare i nostri servizi online. Tieni d'occhio il nostro sito web o iscriviti alla nostra newsletter per le ultime notizie.\"\n", + "15. Cliente: \"Ho avuto difficoltà con il portale di banca online non salvare le mie preferenze, e sta diventando frustrante. Cosa può essere fatto per assicurare che le mie impostazioni siano salvate permanentemente?\"\n", + "16. Teller: \"Capisco la tua frustrazione. Assicurati di utilizzare la versione più recente del tuo browser. Inoltre, prova ad aggiustare le impostazioni del tuo browser per consentire i cookie, che possono aiutare a salvare le tue preferenze.\"\n" + ] + } + ], + "source": [ + "# italian prompt with llama 3.1\n", + "generated_text_italian, response = converse(italian_prompt, inference_config)" + ] + }, + { + "cell_type": "markdown", + "id": "e9924e1e-df0c-4eef-9683-9bac3ba7580f", + "metadata": {}, + "source": [ + "## Translation evaluation with Larger 70b variant" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "e305f4aa-b506-4a2f-8e26-e1df8073fb7e", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "eval_model = meta_llama_3_1_70b" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "1e71a32f-77a7-439f-a8da-cabe637d6ef2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "# Evaluate the generated text using the 70B model\n", + "eval_prompt = f\"\"\"The {conversation} text was translated from English to italian \n", + "by converting the conversation into {generated_text_italian} text, is this an accurate translation? \n", + "Highlight any useful translations in English that could make the new language more accurate.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "e8fc4468-3fe5-49e3-84b1-f9283124b1a5", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "The translation is generally accurate, but there are some minor errors and improvements that can be made to make it more accurate and natural-sounding in Italian. Here are some highlights:\n", + "\n", + "1. \"Ciao, ho appena aperto un nuovo conto con la vostra banca e mi piacciono molto le funzionalità di banca online!\" - This is a good translation, but a more natural way to say it in Italian would be \"Ciao, ho appena aperto un nuovo conto con la vostra banca e sono molto soddisfatto delle funzionalità di banca online!\"\n", + "2. \"Impostare gli avvisi di transazione è semplice. Puoi personalizzarli attraverso il nostro portale di banca online.\" - This is a good translation, but a more natural way to say it in Italian would be \"Impostare gli avvisi di transazione è facile. Puoi personalizzarli attraverso il nostro portale di banca online.\"\n", + "3. \"Lasciamo risolvere questo insieme. Prima assicurati che il tuo username e password siano corretti.\" - This is a good translation, but a more natural way to say it in Italian would be \"Risolviamo questo insieme. Prima assicurati che il tuo username e password siano corretti.\"\n", + "4. \"Grande domanda! Offriamo diverse opzioni di conto di risparmio con tariffe di interesse diverse.\" - This is a good translation, but a more natural way to say it in Italian would be \"Ottima domanda! Offriamo diverse opzioni di conto di risparmio con tariffe di interesse diverse.\"\n", + "5. \"Sono felice che il manuale sia stato utile. Se incontri altri problemi, non esitare a contattarci e saremo felici di aiutarti ulteriormente.\" - This is a good translation, but a more natural way to say it in Italian would be \"Sono felice che il manuale sia stato utile. Se incontri altri problemi, non esitare a contattarci e saremo felici di aiutarti ulteriormente.\"\n", + "5. \"Mi dispiace sentire questo. Lasciamo risolvere questo velocemente.\" - This is a good translation, but a more natural way to say it in Italian would be \"Mi dispiace sentire questo. Risolviamo questo velocemente.\"\n", + "6. \"Sì, il deterioramento della carta è coperto. Porta la tua carta alla nostra filiale e ti aiuteremo con una sostituzione gratuita.\" - This is a good translation, but a more natural way to say it in Italian would be \"Sì, il deterioramento della carta è coperto. Porta la tua carta alla nostra filiale e ti aiuteremo con una sostituzione gratuita.\"\n", + "7. \"Bravo per aver risolto il problema. Noi rilasciamo aggiornamenti regolarmente per migliorare i nostri servizi online.\" - This is a good translation, but a more natural way to say it in Italian would be \"Bravo per aver risolto il problema. Noi rilasciamo aggiornamenti regolarmente per migliorare i nostri servizi online.\"\n", + "8. \"Capisco la tua frustrazione. Assicurati di utilizzare la versione più recente del tuo browser.\" - This is a good translation, but a more natural way to say it in Italian would be \"Capisco la tua frustrazione. Assicurati di utilizzare la versione più recente del tuo browser.\"\n", + "\n", + "Some useful translations in English that could make the new language more accurate are:\n", + "\n", + "* \"Ciao\" can be translated to \"Hello\" or \"Hi\" in English, but in Italian, it's more common to use \"Ciao\" as a greeting.\n", + "* \"Sono felice\" can be translated to \"I'm happy\" or \"I'm glad\" in English, but in Italian, it's more common to use \"Sono felice\" to express happiness or satisfaction.\n", + "* \"Lasciamo\" can be translated to \"Let's\" in English, but in Italian, it's more common to use \"Lasciamo\" to suggest doing something together.\n", + "* \"Risolviamo\" can be translated to \"Let's solve\" or \"Let's resolve\" in English, but in Italian, it's more common to use \"Risolviamo\" to suggest solving a problem together.\n", + "* \"Ottima\" can be translated to \"Great\" or \"Excellent\" in English, but in Italian, it's more common to use \"Ottima\" to express strong approval or admiration.\n", + "* \"Non esitare\" can be translated to \"Don't hesitate\" in English, but in Italian, it's more common to use \"Non esitare\" to encourage someone to take action without hesitation.\n", + "\n", + "Overall, the translation is good, but there are some minor errors and improvements that can be made to make it more accurate and natural-sounding in Italian.\n" + ] + } + ], + "source": [ + "def converse(prompt, inference_config):\n", + " messages = [{\"role\": \"user\", \"content\": [{\"text\": prompt}]}]\n", + " response = bedrock_client.converse(\n", + " messages=messages,\n", + " modelId=eval_model,\n", + " inferenceConfig=inference_config\n", + " )\n", + " generated_text = response['output']['message']['content'][0]['text']\n", + " print(generated_text)\n", + " return generated_text, response\n", + "\n", + "inference_config = {\"temperature\": 0.0, \"maxTokens\": 2048, \"topP\": 0.1}\n", + "\n", + "\n", + "generated_text, response = converse(eval_prompt, inference_config)" + ] + }, + { + "cell_type": "markdown", + "id": "c670b513-f970-4062-9d24-9ab155bb9cb2", + "metadata": {}, + "source": [ + "## Multilingual Chatbot functionality\n", + "\n", + "LLama 3.1's new multilingual capabilities not only allow developers to translate content from one language to another, but also enables for multilingual chatbots. This is useful for scenarios where developers want to expand globally and create a chatbot to be used to speak in entirely different native languages other than english.\n", + "\n", + "If you remember earlier in the notebook, we generated some sample questions that a tourist may have when they look to travel Paris. In the next cell, we will store the questions (in english) as a prompt, have Llama 3.1 translate the questions in French, and answer the questions in French." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e0cce7a1-a6ec-4832-b2e9-1beb412d0f46", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "questions = f\"\"\"\n", + "\n", + "{formatted_text}\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d53e3899-532b-401a-b9f8-1e71d89f1422", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "# Define the message to translate and answer the questions in French\n", + "translated_convo = {\n", + " \"role\": \"user\",\n", + " \"content\": [\n", + " {\"text\": f\"Please translate the following questions into French and provide the answers in French:\\n\\n{questions}\"}\n", + " ]\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "74c7a460-3202-4828-a751-29a920207ec2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "# Send the request to the model\n", + "response = bedrock_client.converse(\n", + " modelId=model_id,\n", + " messages=[translated_convo], # Wrap the message in a list\n", + " inferenceConfig={\n", + " \"maxTokens\": 2000,\n", + " \"temperature\": 0,\n", + " \"topP\": 0.5\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "ab94d12d-1790-498d-8008-7d1371fae51b", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Here are the translations of the questions into French, along with the answers:\n", + "\n", + "**Hébergement**\n", + "\n", + "* Quels sont les meilleurs quartiers pour séjourner à Paris pour un premier visiteur ?\n", + "* Quels sont les prix pour les hôtels, les auberges de jeunesse et les appartements Airbnb à Paris ?\n", + "* Puis-je vous recommander des options abordables pour l'hébergement à Paris ?\n", + "* Comment réserver un hôtel ou un appartement à Paris, et comment m'assurer qu'il est légitime ?\n", + "\n", + "**Transport**\n", + "\n", + "* Quels sont les meilleurs moyens de se rendre à Paris de l'aéroport (CDG ou ORY) ?\n", + "* Comment fonctionne le système de transport public à Paris, et quels sont les meilleurs options pour se déplacer dans la ville ?\n", + "* Puis-je acheter un Paris Visite pass, et qu'est-ce qu'il comprend ?\n", + "* Y a-t-il des programmes de location de vélos ou de location de voitures disponibles à Paris ?\n", + "\n", + "**Nourriture et Boissons**\n", + "\n", + "* Quels sont les plats et les boissons à essayer à Paris, et où les trouver ?\n", + "* Puis-je vous recommander des restaurants ou des cafés à Paris pour un voyageur à budget ?\n", + "* Comment commander de la nourriture et des boissons dans un café ou un restaurant parisien, et quels sont les phrases courantes à connaître ?\n", + "* Y a-t-il des marchés de nourriture ou des options de street food à Paris que je ne devrais pas manquer ?\n", + "\n", + "**Attractions et Activités**\n", + "\n", + "* Quels sont les principaux attractions à visiter à Paris, et comment éviter les files d'attente ?\n", + "* Puis-je vous recommander des activités gratuites ou à bas coût à faire à Paris, comme visiter des musées ou des parcs ?\n", + "* Comment acheter des billets pour les attractions populaires comme la Tour Eiffel ou le Musée du Louvre ?\n", + "* Y a-t-il des visites guidées ou des visites à pied disponibles à Paris que je peux rejoindre ?\n", + "\n", + "**Sécurité et Précautions**\n", + "\n", + "* Quels sont les préoccupations de sécurité que je devrais être consciente à Paris, et comment rester en sécurité ?\n", + "* Puis-je vous recommander des quartiers de Paris à éviter, et pourquoi ?\n", + "* Comment signaler un crime ou un objet perdu à Paris, et quels sont les numéros d'urgence ?\n", + "* Y a-t-il des préoccupations de santé que je devrais être consciente à Paris, comme des vaccinations ou des médicaments ?\n", + "\n", + "**Divers**\n", + "\n", + "* Quels sont les meilleurs moyens de communiquer avec les locaux à Paris, et quels sont les phrases courantes à connaître ?\n", + "* Puis-je vous recommander des zones de shopping ou des marchés à Paris ?\n", + "* Comment naviguer la bureaucratie parisienne, comme obtenir un forfait de téléphone ou ouvrir un compte bancaire ?\n", + "* Y a-t-il des événements culturels ou historiques ou des festivals à Paris pendant mon séjour que je ne devrais pas manquer ?\n" + ] + } + ], + "source": [ + "# Extract the 'text' content from the response\n", + "text_content = response['output']['message']['content'][0]['text']\n", + "\n", + "# Replace newline escape sequences ('\\\\n') with actual newline characters\n", + "formatted_text_2 = text_content.replace('\\\\n', '\\n')\n", + "\n", + "# Print the formatted text\n", + "print(formatted_text_2)" + ] + }, + { + "cell_type": "markdown", + "id": "f0d9c86d-ad45-498b-8503-7070cf911a29", + "metadata": {}, + "source": [ + "## Conclusion\n", + "\n", + "In conclusion, Llama 3.1 represents a significant advancement in multilingual capabilities, enabling the creation of sophisticated multilingual chatbots and translation services. The model supports a wide array of languages, including English, French, German, Hindi, Italian, Portuguese, Spanish, and Thai, making it a versatile tool for global applications. Its ability to handle complex tasks with a context length of up to 128K tokens allows it to manage long conversations and provide accurate translations, which are crucial for developing multilingual chatbots.\n", + "\n", + "Overall, Llama 3.1's multilingual capabilities not only facilitate effective translation across different languages but also enable the development of intelligent conversational agents that can interact seamlessly with users worldwide. This makes it an invaluable resource for businesses and developers looking to expand their reach in diverse linguistic markets." + ] + }, + { + "cell_type": "markdown", + "id": "5f2cb635-c9d0-46d4-bbae-bb0f673a1257", + "metadata": {}, + "source": [ + "---\n", + "## Distributors\n", + "- Amazon Web Services\n", + "- Meta" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "conda_tensorflow2_p310", + "language": "python", + "name": "conda_tensorflow2_p310" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}