文档

快速开始

更新时间:

零一模型

说明

支持的领域 / 任务:aigc

目前在灵积平台上对外提供的零一模型服务主要包含Yi-6B-Chat /Yi-34B-Chat 模型,均是由01.AI出品的大规模语言模型。

Yi 系列模型是由 01.AI 从头开始训练的下一代开源大型语言模型,其作为一个双语言模型,在 3T 多语言语料库上训练,Yi 系列模型成为全球最强大的大型语言模型之一,在语言理解、常识推理、阅读理解等方面展现出巨大的潜力。例如:

  • Yi-34B-Chat 模型在 AlpacaEval 排行榜上排名第二(仅次于 GPT-4 Turbo),超越了其他大型语言模型(如 GPT-4, Mixtral, Claude)(基于截至 2024 年 1 月的数据)。

  • Yi-34B 模型在包括 Hugging Face Open LLM Leaderboard(预训练)和 C-Eval(基于截至 2023 年 11 月的数据)在内的各种基准测试中,在英语和中文方面都排名所有现有开源模型(如 Falcon-180B, Llama-70B, Claude)之首。

ps:更多信息可以参考ModelScope上Yi-6B-ChatYi-34B-Chat

快速开始

前提条件

示例代码

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

说明

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

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY

from dashscope import Generation


def call_with_messages():
    messages = [
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': '介绍下杭州'}]
    gen = Generation()
    response = gen.call(
        'yi-34b-chat',
        messages=messages,
        result_format='message',  # set the result is message format.
    )
    print(response)


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("yi-34b-chat")
        .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);
  }
}

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

{
    "status_code": 200,
    "request_id": "0b9c2a71-89cf-963b-8eb4-2786ba88dfbf",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": "\n 杭州是中华人民共和国浙江省的省会,位于中国东南沿海地区,地处长江三角洲南翼。杭州拥有悠久的历史和灿烂的文化,自古以来就是著名的历史文化名城。杭州的地理位置优越,交通便捷,是长江三角洲地区的重要城市之一。\n\n杭州的气候属于亚热带季风气候,四季分明,温暖湿润,雨量充沛。全年气候温和,无霜期长,湿度适中。杭州的春天湿润多雨,夏天炎热多雨,秋天气候宜人,冬天干燥寒冷。\n\n杭州是中国著名的旅游胜地,拥有许多著名的旅游景点,如西湖、灵隐寺、宋城、西溪湿地等。此外,杭州还有许多美食,如龙井虾仁、西湖醋鱼、东坡肉等,是中国著名的美食城市之一。\n\n杭州是中国的互联网科技产业发达的城市之一,拥有阿里巴巴、网易等知名互联网公司。此外,杭州还是中国的金融中心之一,拥有许多金融机构和保险公司。\n\n杭州是一个历史悠久、文化底蕴深厚的城市,同时也是中国经济发展迅速的城市之一,拥有广阔的发展前景。"
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 10,
        "output_tokens": 225
    }
}

了解更多

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

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