openrouter Meta- Llama 3.1 405B Instruct免费调用指南

24 min read

Meta最新发布的Llama 3.1模型,特别是405B Instruct版本,已经成为开源LLM领域的一大亮点。这个模型拥有4050亿参数,并经过Instruct微调,特别适合高质量对话场景。

Llama 3.1系列中的405B版本被誉为开源模型中的佼佼者,在多项评估中表现出色,尤其在与一些闭源模型的人类评估对比中表现出了竞争力。这款模型支持128K的上下文窗口,意味着它能够处理超长对话或复杂任务。Meta AI团队凭借这一版本,继续引领大型语言模型的技术前沿。

用户可以通过OpenRouter平台以API形式调用Llama 3.1 405B Instruct模型。使用过程中需要遵守Meta的可接受使用政策,尤其是在免费端点下有一定的速率限制。

下面提供了一个基本的API调用示例:

管理后台地址: https://openrouter.ai/models/meta-llama/llama-3.1-405b-instruct:free/api

API 调用示例

  1. 使用curl调用
curl https://openrouter.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -d '{
  "model": "meta-llama/llama-3.1-405b-instruct:free",
  "messages": [
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
}'
  1. 使用JavaScript(Node.js)调用
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://openrouter.ai/api/v1",
  apiKey: process.env.OPENROUTER_API_KEY,
  defaultHeaders: {
    "HTTP-Referer": process.env.YOUR_SITE_URL, // 可选,用于在openrouter.ai排名中展示您的应用
    "X-Title": process.env.YOUR_SITE_NAME, // 可选,显示在openrouter.ai上的排名中
  }
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: "meta-llama/llama-3.1-405b-instruct:free",
    messages: [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  });

  console.log(completion.choices[0].message);
}
main();

用户可以通过上述代码轻松上手,利用Meta最新的LLM技术处理各种对话场景和生成任务。