使用Meta家族模型构建 简介 本课程将涵盖: 探索两个主要的Meta家族模型——Llama 3.1和Llama 3.2 理解每个模型的使用场景 代码示例展示每个模型的独特功能 Meta家族模型 在这节课中,我们将探索来自Meta家族或“Llama群”中的两个模型——Llama 3.1和Llama 3.2。 这些模型有不同的变体,并且可以在GitHub模型市场中找到。有关如何使用GitHub模型进行原型设计的更多信息,请参阅相关文档。 模型变体: Llama 3.1 - 70B Instruct Llama 3.1 - 405B Instruct Llama 3.2 - 11B Vision Instruct Llama 3.
本课程将涵盖:
在这节课中,我们将探索来自Meta家族或“Llama群”中的两个模型——Llama 3.1和Llama 3.2。
这些模型有不同的变体,并且可以在GitHub模型市场中找到。有关如何使用GitHub模型进行原型设计的更多信息,请参阅相关文档。
模型变体:
注意:Llama 3也可以在GitHub模型中找到,但不会在此课程中涉及
拥有4050亿参数的Llama 3.1属于开源LLM类别。
该模型通过以下改进升级了之前的版本Llama 3:
这些改进使Llama 3.1能够处理更复杂的使用案例,包括构建GenAI应用时:
Llama 3.1经过微调,能够更有效地进行函数或工具调用。它还内置了两个工具,可以根据用户提示识别需要使用的工具。这些工具是:
您还可以创建自己的自定义工具供LLM调用。
在下面的代码示例中:
<|python_tag|>brave_search.call(query="Stockholm weather")注意:此示例仅演示工具调用,如果您想获取结果,请在Brave API页面上创建一个免费账户并定义函数本身
import os from azure.ai.inference import ChatCompletionsClient from azure.ai.inference.models import AssistantMessage, SystemMessage, UserMessage from azure.core.credentials import AzureKeyCredential token = os.environ["GITHUB_TOKEN"] endpoint = "https://models.inference.ai.azure.com" model_name = "meta-llama-3.1-405b-instruct" client = ChatCompletionsClient( endpoint=endpoint, credential=AzureKeyCredential(token), ) tool_prompt=f""" <|begin_of_text|><|start_header_id|>system<|end_header_id|> Environment: ipython Tools: brave_search, wolfram_alpha Cutting Knowledge Date: December 2023 Today Date: 23 July 2024 You are a helpful assistant<|eot_id|> """ messages = [ SystemMessage(content=tool_prompt), UserMessage(content="What is the weather in Stockholm?"), ] response = client.complete(messages=messages, model=model_name) print(response.choices[0].message.content)
尽管Llama 3.1是一个LLM,但它的一个限制是多模态性。这意味着能够使用不同类型输入(如图像作为提示)并提供响应的能力。这是Llama 3.2的主要功能之一。这些功能还包括:
多模态支持代表了开源模型领域的一大进步。下面的代码示例结合图像和文本提示,从Llama 3.2 90B中获取图像分析。
import os from azure.ai.inference import ChatCompletionsClient from azure.ai.inference.models import ( SystemMessage, UserMessage, TextContentItem, ImageContentItem, ImageUrl, ImageDetailLevel, ) from azure.core.credentials import AzureKeyCredential token = os.environ["GITHUB_TOKEN"] endpoint = "https://models.inference.ai.azure.com" model_name = "Llama-3.2-90B-Vision-Instruct" client = ChatCompletionsClient( endpoint=endpoint, credential=AzureKeyCredential(token), ) response = client.complete( messages=[ SystemMessage( content="You are a helpful assistant that describes images in details." ), UserMessage( content=[ TextContentItem(text="What's in this image?"), ImageContentItem( image_url=ImageUrl.load( image_file="https://www.aiknowledge.cn/images/面向初学者的生成式AI课程/sample.webp", image_format="jpg", detail=ImageDetailLevel.LOW) ), ], ), ], model=model_name, ) print(response.choices[0].message.content)
完成本课程后,请查看我们的生成式AI学习集合,继续提升您的生成式AI知识!
声明:
本文件灏天文库团队进行了翻译。尽管我们力求准确,但请注意,翻译可能包含错误或不准确之处。原文档以其原始语言为准。我们不对因使用此翻译而产生的任何误解或误译负责。