Llama 3.1 拥有 4050 亿个参数,属于开源 LLM 类别。
该模式是对早期发布的 Llama 3 的升级,提供了:
•更大的上下文窗口 - 128k 个 tokens vs 8k 个 tokens•更大的最大输出 Tokens - 4096 vs 2048•更好的多语言支持 - 由于训练 tokens 的增加
这些使 Llama 3.1 能够在构建 GenAI 应用程序时处理更复杂的用例,包括:
•本地函数调用 - 调用 LLM 工作流程之外的外部工具和函数的能力•更好的 RAG 性能 - 由于更高的上下文窗口•合成数据生成 - 创建有效数据以用于微调等任务的能力
Llama 3.1 经过微调,可以更有效地进行函数或工具调用。它还具有两个内置工具,模型可以根据用户的提示识别出需要使用这些工具。这些工具是:
•Brave Search- 可以通过执行网络搜索来获取最新信息,例如天气•Wolfram Alpha- 可用于更复杂的数学计算,因此不需要编写自己的函数。
你还可以创建自己的 LLM 可以调用的自定义工具。
在下面的代码示例中:
•我们在系统提示中定义了可用的工具 (brave_search, wolfram_alpha)。•发送一个询问特定城市天气情况的用户提示。•LLM 将回复一个对 Brave Search 工具的工具调用,如下所示
<|python_tag|>brave_search.call(query="Stockholm weather")
注意:此示例仅进行工具调用,如果想获得结果,您需要在 Brave API 页面上创建一个免费帐户并定义函数本身。
import osfrom azure.ai.inference import ChatCompletionsClientfrom azure.ai.inference.models import AssistantMessage, SystemMessage, UserMessagefrom azure.core.credentials import AzureKeyCredentialtoken = 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: ipythonTools: brave_search, wolfram_alphaCutting Knowledge Date: December 2023Today Date: 23 July 2024You 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 的主要功能之一。这些功能还包括:
•多模态 - 能够评估文本和图像提示•中小型变体(11B 和 90B) - 这提供了灵活的部署选项•纯文本变体(1B 和 3B) - 这允许模型部署在边缘/移动设备上,并提供低延迟
多模态支持代表了开源模型领域的一大步。下面的代码示例同时采用图像和文本提示,以从 Llama 3.2 90B 获得图像分析。
importosfromazure.ai.inferenceimportChatCompletionsClientfromazure.ai.inference.modelsimport(SystemMessage,UserMessage,TextContentItem,ImageContentItem,ImageUrl,ImageDetailLevel,)fromazure.core.credentialsimportAzureKeyCredentialtoken = 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="sample.jpg",image_format="jpg",detail=ImageDetailLevel.LOW)),],),],model=model_name,)print(response.choices[0].message.content)
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |