文档

快速使用

更新时间:

ChatYuan

说明

支持的领域 / 任务:aigc

ChatYuan模型是由元语智能出品的大规模语言模型,它在灵积平台上的模型名称为"chatyuan-large-v2"。ChatYuan-large-v2是一个支持中英双语的功能型对话语言大模型,是继ChatYuan系列中ChatYuan-large-v1开源后的又一个开源模型。ChatYuan-large-v2使用了和 v1版本相同的技术方案,在微调数据、人类反馈强化学习、思维链等方面进行了优化。

ChatYuan-large-v2是ChatYuan系列中以轻量化实现高质量效果的模型之一,用户可以在消费级显卡、 PC甚至手机上进行推理(INT4 最低只需 400M )。

在chatyuan-large-v1的原有功能的基础上,给模型进行了如下优化:

  • 增强了基础能力。原有上下文问答、创意性写作能力明显提升。

  • 新增了拒答能力。对于一些危险、有害的问题,学会了拒答处理。

  • 新增了代码生成功能。对于基础代码生成进行了一定程度优化。

  • 新增了表格生成功能。使生成的表格内容和格式更适配。

  • 增强了基础数学逻辑运算能力。

  • 最大长度token数扩展到4096。

  • 增强了模拟情景能力。

  • 新增了中英双语对话能力。

当前在灵积平台部署服务时使用的ModelScope社区模型id:ClueAI/ChatYuan-large-v2,模型版本:v1.0.0。

更多信息可以参考ModelScope上ChatYuan的开源repo

快速开始

前提条件

示例代码

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

说明

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

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
重要

ChatYuan模型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='chatyuan-large-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
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.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
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 {
    Generation gen = new Generation();
    String prompt="翻译成英文:春天来了,花朵都开了。";
    GenerationParam param = GenerationParam
    .builder()
    .model("chatyuan-large-v2")
    .prompt(prompt)
    .build();
    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": "Spring is coming, flowers are open."}

了解更多

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

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