文档

快速开始

更新时间:

DeepSeek模型

说明

支持的领域 / 任务:aigc

目前在灵积平台上对外提供的DeepSeek模型服务主要包含DeepSeek-7B-Chat 模型,是由deepseek-ai 出品的大规模语言模型。

DeepSeek系列模型是由 deepseek-ai 从头开始训练的一代开源大型语言模型,作为一个双语言模型其最大版本包含了670亿参数,在一个包含2万亿个的英文和中文的语料库上训练。

ps:更多信息可以参考ModelScope上DeepSeek-7B-Chat

快速开始

前提条件

示例代码

以下示例展示了调用DeepSeek模型 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(
        'deepseek-7b-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("deepseek-7b-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
    }
}

了解更多

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

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