开源模型的又一里程碑!Mistral Large 2 正式上线 Amazon Bedrock

876bf4ef95ed8441c29e8df844537027.gif

Mistral AI 的Mistral Large 2(24.07)基础模型现已在 Amazon Bedrock 上正式可用!Mistral Large 2 是 Mistral Large 的最新版本。据 Mistral AI 称,Mistral Large 2 在多语种能力、数学、推理、编码等多个方面都有显著提升。

在这篇文章中,我们将通过一些实例讨论这个新模型的优势和能力。

eacd80832545d6cb9eef1e9abef5ff50.png

Amazon Bedrock 

扫码了解更多

Mistral Large 2概览

据 Mistral AI 称,Mistral Large 2 作为一款先进的大型语言模型(LLM),具有极为先进的推理、知识和编码能力。它从设计上就是多语种的,支持数十种语言,包括英语、法语、德语、西班牙语、意大利语、中文、日语、韩语、葡萄牙语、荷兰语、波兰语、阿拉伯语和印地语。Mistral AI 表示,他们还致力于增强该模型的推理能力。

在训练过程中的一个关键重点是,减少模型产生听起来合理但事实上不正确或无关的信息(即幻觉)的倾向。这是通过对模型进行微调来实现的,使其在回答时更加谨慎和有识别力,从而提供可靠和准确的输出。此外,新的Mistral Large 2还被训练为在无法找到解决方案或缺乏足够信息以提供有把握的答复时,承认这一点。

该模型在编码方面的表现也很强大,接受过超过80种编程语言的训练,如Python、Java、C、C++、JavaScript、Bash、Swift和Fortran。凭借其一流的主动能力,它可以原生调用函数并输出JSON,从而实现与外部系统、API和工具的无缝交互。另外,Mistral Large 2(24.07) 还拥有先进的推理和数学能力,可以成为解决复杂逻辑和计算挑战的强大助手。

Mistral Large 2 还提供了增加到128,000个 tokens 的上下文窗口。在撰写本文时,该模型(mistral.mistral-large-2407-v1:0)可在 us-west-2 的亚马逊云科技上使用。

在 Amazon Bedrock 上

开始使用 Mistral Large 2

如果您是第一次使用 Mistral AI 模型,可以在 Amazon Bedrock 控制台上请求模型访问权限。更多详细信息,请参阅管理对 Amazon Bedrock 基础模型的访问权限。

要在 Amazon Bedrock 控制台上测试 Mistral Large 2,请在导航窗格中选择“Playgrounds”,然后选择“Text”或“Chat”。接下来选择“Select model”,将类别选择为“Mistral”并将模型选择为“Mistral Large 24.07”。

df30fab1bb904e484aa43dfa56edd5b5.png

Amazon Bedrock

基础模型的访问权限

扫码了解更多

8e99f31c8acc65a6d31fec40cdbf2d32.jpeg

通过选择“View API request”选项,您也可以使用亚马逊云科技命令行界面(Amazon CLI)和  Amazon SDK  中的代码示例来访问该模型。您可以使用诸如 mistral.mistral-large-2407-v1:0 这样的模型ID,如下面的代码所示:

7c3aadb6c519d2a4dbdebfbd2e262b31.png

亚马逊云科技

命令行界面(Amazon CLI) 

扫码了解更多

$ aws bedrock-runtime invoke-model \ 
--model-id mistral.mistral-large-2407-v1:0 \
--body "{\"prompt\":\"<s>[INST] this is where you place your input text [/INST]\", \"max_tokens\":200, \"temperature\":0.5, \"top_p\":0.9, \"top_k\":50}" \ 
--cli-binary-format raw-in-base64-out \
--region us-west-2 \ 
invoke-model-output.txt

左右滑动查看更多

在接下来的部分,我们将深入探讨 Mistral Large 2 的能力。

增加的上下文窗口

与支持32,000个 tokens 上下文窗口的 Mistral Large (24.02)相比,Mistral Large 2 支持128,000个 tokens 的上下文窗口。这个更大的上下文窗口对开发者来说很重要,因为它允许模型处理和理解更长的文本,如整个文档或代码文件,而不会丢失上下文或连贯性。这对于诸如代码生成、文档分析或任何需要理解和处理大量文本数据的应用程序等任务非常有用。

生成 JSON 和工具使用

Mistral Large 2 现在提供了原生的 JSON 输出模式。这个功能允许开发人员以结构化、易读的格式接收模型的响应,可以很容易地集成到各种应用程序和系统中。由于 JSON 是广泛采用的数据交换标准,这种能力简化了与模型输出合作的过程,使其对不同领域和用例的开发人员来说更加易于访问和实用。要了解如何使用 Converse API 生成 JSON,请参阅使用 Amazon Bedrock Converse API 生成 JSON。

要使用 Converse API 生成 JSON ,需要定义一个 toolSpec。在下面的代码中,我们展示了一个旅行社公司的示例,它将接收乘客信息和请求,并将它们转换为 JSON:

# Define the tool configuration
import json
tool_list = [
    {
        "toolSpec": {
            "name": "travel_agent",
            "description": "Converts trip details as a json structure.",
            "inputSchema": {
                "json": {
                    "type": "object",
                    "properties": {
                        "origin_airport": {
                            "type": "string",
                            "description": "Origin airport (IATA code)"
                        },
                        "destination_airport": {
                            "type": "boolean",
                            "description": "Destination airport (IATA code)"
                        },
                        "departure_date": {
                            "type": "string",
                            "description": "Departure date",
                        }, 
                        "return_date": {
                            "type": "string",
                            "description": "Return date",
                        }
                    },
                    "required": [
                        "origin_airport",
                        "destination_airport",
                        "departure_date",
                        "return_date"
                    ]
                }
            }
        }
    }
]
content = """
I would like to book a flight from New York (JFK) to London (LHR) for a round-trip.
The departure date is June 15, 2023, and the return date is June 25, 2023.


For the flight preferences, I would prefer to fly with Delta or United Airlines. 
My preferred departure time range is between 8 AM and 11 AM, and my preferred arrival time range is between 9 AM and 1 PM (local time in London). 
I am open to flights with one stop, but no more than that.
Please include non-stop flight options if available.
"""


message = {
    "role": "user",
    "content": [
        { "text": f"<content>{content}</content>" },
        { "text": "Please create a well-structured JSON object representing the flight booking request, ensuring proper nesting and organization of the data. Include sample data for better understanding. Create the JSON based on the content within the <content> tags." }
    ],
}
# Bedrock client configuration
response = bedrock_client.converse(
    modelId=model_id,
    messages=[message],
    inferenceConfig={
        "maxTokens": 500,
        "temperature": 0.1
    },
    toolConfig={
        "tools": tool_list
    }
)


response_message = response['output']['message']
response_content_blocks = response_message['content']
content_block = next((block for block in response_content_blocks if 'toolUse' in block), None)
tool_use_block = content_block['toolUse']
tool_result_dict = tool_use_block['input']


print(json.dumps(tool_result_dict, indent=4))

左右滑动查看更多

我们会得到如下回复:

{"origin_airport": "JFK","destination_airport": "LHR","departure_date": "2023-06-15","return_date": "2023-06-25"}

左右滑动查看更多

Mistral Large 2 能够正确地获取我们的用户查询并将相应的信息转换为 JSON。

Mistral Large 2 还支持 Converse API 和工具使用。您可以使用 Amazon Bedrock API 为模型提供可以帮助它为您发送给模型的消息生成响应的工具。例如,您可能有一个聊天应用程序,让用户找到在电台播放的最受欢迎的歌曲。为了回答最受欢迎歌曲的请求,模型需要一个可以查询和返回歌曲信息的工具。以下代码显示了获取正确列车时刻表的示例:

# Define the tool configuration
toolConfig = {
    "tools": [
        {
            "toolSpec": {
                "name": "shinkansen_schedule",
                "description": "Fetches Shinkansen train schedule departure times for a specified station and time.",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "station": {
                                "type": "string",
                                "description": "The station name."
                            },
                            "departure_time": {
                                "type": "string",
                                "description": "The departure time in HH:MM format."
                            }
                        },
                        "required": ["station", "departure_time"]
                    }
                }
            }
        }
    ]
}
# Define shikansen schedule tool
def shinkansen_schedule(station, departure_time):
    schedule = {
        "Tokyo": {"09:00": "Hikari", "12:00": "Nozomi", "15:00": "Kodama"},
        "Osaka": {"10:00": "Nozomi", "13:00": "Hikari", "16:00": "Kodama"}
    }
    return schedule.get(station, {}).get(departure_time, "No train found")
def prompt_mistral(prompt):
    messages = [{"role": "user", "content": [{"text": prompt}]}]
    converse_api_params = {
        "modelId": model_id,
        "messages": messages,
        "toolConfig": toolConfig,  
        "inferenceConfig": {"temperature": 0.0, "maxTokens": 400},
    }


    response = bedrock_client.converse(**converse_api_params)
    
    if response['output']['message']['content'][0].get('toolUse'):
        tool_use = response['output']['message']['content'][0]['toolUse']
        tool_name = tool_use['name']
        tool_inputs = tool_use['input']


        if tool_name == "shinkansen_schedule":
            print("Mistral wants to use the shinkansen_schedule tool")
            station = tool_inputs["station"]
            departure_time = tool_inputs["departure_time"]
            
            try:
                result = shinkansen_schedule(station, departure_time)
                print("Train schedule result:", result)
            except ValueError as e:
                print(f"Error: {str(e)}")


    else:
        print("Mistral responded with:")
        print(response['output']['message']['content'][0]['text'])
prompt_mistral("What train departs Tokyo at 9:00?")

左右滑动查看更多

我们会得到如下回复:

Mistral wants to use the shinkansen_schedule tool
Train schedule result: Hikari

左右滑动查看更多

由上可见,Mistral Large 2 能够正确识别新干线工具并演示其使用方法。

多语言支持

Mistral Large 2 现在支持大量基于字符的语言,如中文、日语、韩语、阿拉伯语和印地语。这种扩展的语言支持使开发人员能够构建可为来自不同语言背景的用户提供服务的应用程序和服务。凭借多语言能力,开发人员可以创建本地化的用户界面,提供特定语言的内容和资源,并为用户提供无缝体验,而不受其母语的限制。

在以下示例中,我们将作者生成的客户电子邮件翻译成不同语言,如印地语和日语:

emails= """
"I recently bought your RGB gaming keyboard and absolutely love the customizable lighting features! Can you guide me on how to set up different profiles for each game I play?"
"I'm trying to use the macro keys on the gaming keyboard I just purchased, but they don't seem to be registering my inputs. Could you help me figure out what might be going wrong?"
"I'm considering buying your gaming keyboard and I'm curious about the key switch types. What options are available and what are their main differences?"
"I wanted to report a small issue where my keyboard's space bar is a bit squeaky. However, your quick-start guide was super helpful and I fixed it easily by following the lubrication tips. Just thought you might want to know!"
"My new gaming keyboard stopped working within a week of purchase. None of the keys respond, and the lights don't turn on. I need a solution or a replacement as soon as possible."
"I've noticed that the letters on the keys of my gaming keyboard are starting to fade after several months of use. Is this covered by the warranty?"
"I had an issue where my keyboard settings would reset every time I restarted my PC. I figured out it was due to a software conflict and resolved it by updating the firmware. Just wanted to ask if there are any new updates coming soon?"
"I've been having trouble with the keyboard software not saving my configurations, and it's starting to get frustrating. What can be done to ensure my settings are saved permanently?"
"""def converse(prompt, inference_config):
    messages = [{"role": "user", "content": [{"text": prompt}]}]
    response = bedrock_client.converse(
        messages=messages,
        modelId=model_id,
        inferenceConfig=inference_config
    )
    generated_text = response['output']['message']['content'][0]['text']print(generated_text)return generated_text


prompt=f"""


emails={emails}


Translate the following customer emails into these languages:


1. Hindi
2. Japanese


Label each language section accordingly""".format(emails=emails)


inference_config = {"temperature": 0.0, "maxTokens": 4000, "topP": 0.1}


response = converse(prompt, inference_config)

左右滑动查看更多

我们会得到如下回复:

"मैंने हाल ही में आपका RGB गेमिंग कीबोर्ड खरीदा और कस्टमाइजेबल लाइटिंग फीचर्स से बहुत प्रेम करता हूँ! क्या आप मुझे बता सकते हैं कि मैं हर गेम के लिए अलग-अलग प्रोफाइल कैसे सेट कर सकता हूँ?"
2. "मैं अपने नए गेमिंग कीबोर्ड पर मैक्रो कीज का उपयोग करने की कोशिश कर रहा हूँ, लेकिन वे मेरे इनपुट्स को रजिस्टर नहीं कर रहे हैं। क्या आप मुझे बता सकते हैं कि क्या गलत हो सकता है?"
3. "मैं आपका गेमिंग कीबोर्ड खरीदने के बारे में सोच रहा हूँ और मुझे की स्विच टाइप्स के बारे में जानना है। क्या विकल्प उपलब्ध हैं और उनके मुख्य अंतर क्या हैं?"
4. "मैं यह रिपोर्ट करना चाहता था कि मेरे कीबोर्ड का स्पेस बार थोड़ा सा चरमरा रहा है। हालाँकि, आपका क्विक-स्टार्ट गाइड बहुत मददगार था और मैंने लुब्रिकेशन टिप्स का पालन करके इसे आसानी से ठीक कर दिया। बस यह जानना चाहता था कि शायद आपको पता चलना चाहिए!"
5. "मेरा नया गेमिंग कीबोर्ड खरीद के एक सप्ताह के भीतर काम करना बंद हो गया। कोई भी की जवाब नहीं दे रहा है, और लाइट्स भी नहीं चालू हो रहे हैं। मुझे एक समाधान या एक रिप्लेसमेंट जितनी जल्दी हो सके चाहिए।"
6. "मैंने नोट किया है कि मेरे गेमिंग कीबोर्ड के कीज पर अक्षर कुछ महीनों के उपयोग के बाद फेड होने लगे हैं। क्या यह वारंटी के तहत कवर है?"
7. "मेरे कीबोर्ड सेटिंग्स हर बार मेरे पीसी को रीस्टार्ट करने पर रीसेट हो जाती थीं। मैंने पता लगाया कि यह एक सॉफ्टवेयर कॉन्फ्लिक्ट के कारण था और फर्मवेयर अपडेट करके इसे सुलझा दिया। बस पूछना चाहता था कि क्या कोई नए अपडेट आने वाले हैं?"
8. "मेरे कीबोर्ड सॉफ्टवेयर मेरी कॉन्फ़िगरेशन को सेव नहीं कर रहे हैं, और यह अब परेशान करने लगा है। मेरे सेटिंग्स को स्थायी रूप से सेव करने के लिए क्या किया जा सकता है?"


### Japanese


1. "最近、あなたのRGBゲーミングキーボードを購入し、カスタマイズ可能なライティング機能が大好きです! 各ゲームごとに異なるプロファイルを設定する方法を教えていただけますか?"
2. "新しく購入したゲーミングキーボードのマクロキーを使おうとしていますが、入力が認識されません。何が問題か教えていただけますか?"
3. "あなたのゲーミングキーボードを購入しようと考えていますが、キースイッチの種類について知りたいです。どのようなオプションがあり、その主な違いは何ですか?"
4. "キーボードのスペースバーが少しきしむようになりました。ただし、クイックスタートガイドが非常に役立ち、潤滑のヒントに従って簡単に修理できました。ただ、知っておいてほしいと思いました!"
5. "新しいゲーミングキーボードが購入後1週間で動作しなくなりました。どのキーも反応せず、ライトも点きません。できるだけ早く解決策や交換をお願いします。"
6. "ゲーミングキーボードのキーの文字が数ヶ月の使用後に消え始めました。これは保証に含まれますか?"
7. "キーボードの設定がPCを再起動するたびにリセットされていました。ソフトウェアの競合が原因であることがわかり、ファームウェアを更新して解決しました。新しいアップデートが近々来るのか教えていただけますか?"
8. "キーボードソフトウェアが設定を保存しないため、非常に困っています。設定を永続的に保存するために何ができますか?"

左右滑动查看更多

编码任务

Mistral Large 2 已经在超过80种编码语言上接受过训练,包括流行的 Python、Java、C、C++、JavaScript 和 Bash,以及更专业的语言,如 Swift 和 Fortran。这种全面的语言支持使开发人员能够应对各种领域和平台的广泛编码任务和项目。无论您是从事网络开发、移动应用程序、科学计算还是系统编程,Mistral Large 2 都可以为您提供代码生成、调试、重构和其他与编码相关的任务的协助。例如,以下代码要求模型生成一个 Python 函数:

prompt = """
Write a Python function called palindrome_prime_finder that finds all prime numbers within a given range that are also palindromes when written in base 10 (decimal system).
"""


inference_config = {"temperature": 0.0, "maxTokens": 1000, "topP": 0.1}


response = converse(prompt, inference_config)

左右滑动查看更多

我们会得到如下回复:

Certainly! Below is a Python function called `palindrome_prime_finder` that finds all prime numbers within a given range that are also palindromes when written in base 10.


```python
def is_prime(n):
    """Check if a number is prime."""
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True


def is_palindrome(n):

左右滑动查看更多

总结

Mistral AI 的 Mistral Large 2 基础模型现已在美国西部(俄勒冈州)地区的 Amazon Bedrock 上提供。要在 Amazon Bedrock 上开始使用 Mistral Large 2,请访问 Amazon Bedrock 控制台。

您还可以查看 Mistral-on-Amazon 存储库,以进行深入了解。有关 Mistral AI 在 Amazon Bedrock 上的更多信息,请查看以下文章。

310afe1613c279a099bdaa3dd8c913ad.png

Amazon Bedrock控制台

扫码了解更多

316891027694ec06ce600679a2d3cfd8.png

Amazon Bedrock 

扫码了解更多

左右滑动查看更多

本篇作者

e4aa724f5301537b41d6e1759c0c6e64.jpeg

Niithiyn Vijeaswaran

亚马逊云科技解决方案架构师。专注生成式 AI 和亚马逊云科技 AI 加速器。他拥有计算机科学和生物信息学学士学位,并与生成式 AI GTM 团队密切合作,在多个领域为亚马逊云科技客户提供支持,加速他们采用生成式 AI技术。

9dffd3c485483fa06b7d93feaad0b4fe.jpeg

Armando Diaz

亚马逊云科技解决方案架构师。他专注于生成式 AI、人工智能与机器学习和数据分析。在亚马逊云科技,帮助客户将前沿的生成式 AI 功能整合到他们的系统中,促进创新和获得竞争优势。

6f67ff82fa64d9e516070a4b94111f84.jpeg

Preston Tuggle

高级专家解决方案架构师,从事生成式 AI 领域。

642fb08f1d34c4c2237467057213e89e.png

709b3d9567607606352e2602fee4ea18.gif

星标不迷路,开发更极速!

关注后记得星标「亚马逊云开发者」

点击阅读原文查看博客,获得更详细内容

听说,点完下面4个按钮

就不会碰到bug了!

40e12e49460f83ab259e43c654d447ad.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值