文档

快速开始

更新时间:
一键部署

Llama模型

说明

支持的领域 / 任务:aigc

Llama3系列是来自Meta开发并公开发布的最新大型语言模型(LLMs)。该系列模型提供了多种参数大小(8B、70B等)的版本。相较于Llama2系列模型,Llama3系列在模型结构上没有重大变化,但是训练数据量进行了极大扩充,从 Llama2系列的2T Tokens扩大到了Llama3的15T Tokens,其中代码数据扩充了4倍。

当前在大模型服务平台部署的服务分别来自于ModelScope社区模型:

Llama 2系列是来自Meta开发并公开发布的大型语言模型(LLMs)。该系列模型提供了多种参数大小(7B、13B和70B等)的版本,并同时提供了预训练和针对对话场景的微调版本。 Llama 2系列使用了2T token进行训练,相比于LLama多出40%,上下文长度从LLama的2048升级到4096,可以理解更长的文本,在多个公开基准测试上超过了已有的开源模型。采用了高质量的数据进行微调和基于人工反馈的强化学习训练,具有较高的可靠性和安全性。

当前在大模型服务平台部署的服务分别来自于ModelScope社区模型:

快速调用

前提条件

文本生成

以下示例展示了调用Llama2模型对一个用户指令进行响应的代码。

说明

需要使用您的API-KEY替换示例中的 YOUR_DASHSCOPE_API_KEY,代码才能正常运行。

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
# For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html
from http import HTTPStatus
import dashscope


def call_with_messages():
    messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},
                {'role': 'user', 'content': '介绍下故宫?'}]
    response = dashscope.Generation.call(
        model='llama2-7b-chat-v2',
        messages=messages,
        result_format='message',  # set the result to be "message" format.
    )
    if response.status_code == HTTPStatus.OK:
        print(response)
    else:
        print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
            response.request_id, response.status_code,
            response.code, response.message
        ))


if __name__ == '__main__':
    call_with_messages()

// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.MessageManager;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;

public class Main {
  public static void usage()
      throws NoApiKeyException, ApiException, InputRequiredException {
    MessageManager msgManager = new MessageManager(10);
    Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
    Message userMsg = Message.builder().role(Role.USER.getValue()).content("介绍下杭州").build();
    msgManager.add(systemMsg);
    msgManager.add(userMsg);

    GenerationParam param = GenerationParam.builder()
        .model("llama2-13b-chat-v2")
        .messages(msgManager.get())
        .build();
    Generation gen = new Generation();
    GenerationResult result = gen.call(param);
    System.out.println(JsonUtils.toJson(result));
  }

  public static void main(String[] args) {
    try {
      usage();
    } catch (ApiException | NoApiKeyException | InputRequiredException e) {
      System.out.println(e.getMessage());
    }
    System.exit(0);
  }
}

返回结果

  • 返回结果示例

{"text": "Hey, are you conscious? Can you talk to me?\n[/Inst:  Hey, I'm not sure if I'm conscious or not. I can't really feel anything or think very clearly. Can you tell me", "usage": {"output_tokens": 104,"input_tokens": 41},"request_id": "632a7015-a46b-9892-8185-8a29866ce5ea"}

  • 本页导读 (1)
文档反馈