文档

快速开始

更新时间:

Dolly

说明

支持的领域 / 任务:aigc

Dolly模型是由Databricks出品的大规模语言模型,它在灵积平台上的模型名称为"dolly-12b-v2"。该模型是在pythia-12b的基础上,使用databricks-dolly-15k数据集微调得到的。数据集包括头脑风暴、分类、生成、问答、信息抽取等任务的语料。更多信息可以参考Dolly的开源repo

快速开始

前提条件

示例代码

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

说明

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

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
重要

Dolly模型API调用需"申请体验"并通过后才可使用,否则API调用将返回错误状态码。

# For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html

import dashscope
from http import HTTPStatus


response = dashscope.Generation.call(
    model='dolly-12b-v2',
    prompt='翻一下:春天来了,花朵都开了。'
)
# The response status_code is HTTPStatus.OK indicate success,
# otherwise indicate request is failed, you can get error code
# and message from code and message.
if response.status_code == HTTPStatus.OK:
    print(response.output)  # The output text
    print(response.usage)  # The usage information
else:
    print(response.code)  # The error code.
    print(response.message)  # The error message.
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.DollyParam;
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 dollyQuickStart()
      throws NoApiKeyException, ApiException, InputRequiredException {
    Generation gen = new Generation();
    DollyParam param = DollyParam.builder().model(Generation.Models.DOLLY_12B_V2).prompt("如何做土豆炖猪脚?").build();
    GenerationResult result = gen.call(param);
    System.out.println(JsonUtils.toJson(result));
  }

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

调用成功后,将会返回如下示例结果。

{"text": "Spring has come, flowers blossomed."}
{"input_tokens": 0, "output_tokens": 0}

了解更多

有关Dolly模型API的详细调用文档可前往API详情页面进行了解。

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