文档

API详情

更新时间:

重要

智海三乐教育大模型现处于内部测试阶段,暂不支持外部访问!

智海三乐教育大模型

说明

支持的领域 / 任务:aigc

智海三乐教育大模型,取名于孟子所言“天下英才而教育之,三乐也”喻意,由浙江大学联合高等教育出版社、阿里云和华院计算等单位共同研制。该模型以阿里云通义千问70亿参数通用模型为基座,通过继续预训练和微调等技术手段,利用核心教材、领域论文和学位论文等教科书级高质量语料和专业指令数据集打造的一款专注于人工智能专业领域教育的大模型。实现教育领域的知识强化和教育场景中的能力升级。此外,智海三乐还加入了搜索引擎、计算引擎和本地知识库等功能,以进一步提升模型的性能和使用体验。

用户以文本形式输入的指令(prompt)以及不定轮次的对话历史(history)作为输入,返回模型生成的回复作为输出。在这一过程中,文本将被转换为语言模型可以处理的token序列。Token是模型用来表示自然语言文本的基本单位,可以直观的理解为“字”或“词”。对于中文文本来说,1个token通常对应一个汉字;对于英文文本来说,1个token通常对应3至4个字母或1个单词。例如,中文文本“你好,我是智海三乐”会被转换成序列['你', '好', ',', '我', '是', '智', '海', '三', '乐'],而英文文本"Nice to meet you."则会被转换成['Nice', ' to', ' meet', ' you', '.']。

由于模型调用的计算量与token序列长度相关,输入或输出token数量越多,模型的计算时间越长,我们将根据模型输入和输出的token数量计费。可以从API返回结果的 usage 字段中了解到您每次调用时使用的token数量。

模型概览

模型名

模型简介

sanle-v1

智海三乐教育大模型

SDK使用

前提条件

单轮问答

以下示例展示了调用智海三乐教育大模型对一个用户指令进行响应的代码。

说明

需要使用您的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

import dashscope
from dashscope import Generation
from http import HTTPStatus

response = Generation.call(
    model='sanle-v1',
    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 java.util.concurrent.Semaphore;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.ResultCallback;
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 {
  private static final String model="sanle-v1";
  private static final String prompt="请简要介绍一下浙江大学";
  public static void qwenQuickStart()
      throws NoApiKeyException, ApiException, InputRequiredException {
    Generation gen = new Generation();
    QwenParam param = QwenParam
    .builder()
    .model(model)
    .prompt(prompt)
    .build();
    GenerationResult result = gen.call(param);
    System.out.println(JsonUtils.toJson(result));
  }

  public static void qwenQuickStartCallback()
      throws NoApiKeyException, ApiException, InputRequiredException, InterruptedException {
    Generation gen = new Generation();
    QwenParam param = QwenParam
    .builder()
    .model(model)
    .prompt(prompt)
    .build();
    Semaphore semaphore = new Semaphore(0);
    gen.call(param, new ResultCallback<GenerationResult>() {

      @Override
      public void onEvent(GenerationResult message) {
        System.out.println(message);
      }
      @Override
      public void onError(Exception ex){
        System.out.println(ex.getMessage());
        semaphore.release();
      }
      @Override
      public void onComplete(){
        System.out.println("onComplete");
        semaphore.release();
      }
      
    });
    semaphore.acquire();
  }

  public static void main(String[] args) {
    try {
      qwenQuickStart();
      qwenQuickStartCallback();
    } catch (ApiException | NoApiKeyException | InputRequiredException | InterruptedException e) {
      System.out.println(String.format("Exception %s", e.getMessage()));
    }
    System.exit(0);
  }
}

多轮会话

您也可以通过history参数传入对话历史,以达到与模型进行多轮交互的目的。

对话历史是以列表的形式,按时间正序组织的。列表中的一个元素为字典形式记录的人机交互的一轮对话记录,用户的输入用“user”表示,模型生成的输出用“bot”。

# coding=utf-8
# For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html

import dashscope
from dashscope import Generation
from http import HTTPStatus
import json

response=Generation.call(
    model='sanle-v1',
    prompt='请简要介绍一下浙江大学',
    history=[
        {
            "bot": "我当然知道浙江大学",
            "user": "你知道浙江大学么",
        }
     ]
  )

if response.status_code==HTTPStatus.OK:
    print(json.dumps(response.output, indent=4, ensure_ascii=False))
else:
    print('Code: %d, status: %s, message: %s' % (response.status_code, response.code, response.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.QwenParam;
import com.alibaba.dashscope.common.History;
import com.alibaba.dashscope.common.HistoryManager;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class Main {
  private static final String model="qwen-7b-chat-v1";
  public static void qwenQuickStart()
      throws NoApiKeyException, ApiException, InputRequiredException {
    Generation gen = new Generation();
    String prompt="请简要介绍一下浙江大学";
    HistoryManager historyManager = new HistoryManager(10);
    History his = History.builder()
    .bot("我当然知道浙江大学")
    .user("你知道浙江大学么")
    .build();
    historyManager.add(his);
    QwenParam param = QwenParam
    .builder()
    .model(model)
    .prompt(prompt)
    .history(historyManager.get())
    .topP(0.8)
    .build();
    GenerationResult result = gen.call(param);
    System.out.println(result.getOutput().getText());
  }

  public static void main(String[] args) {
    try {
      qwenQuickStart();
    } catch (ApiException | NoApiKeyException | InputRequiredException e) {
      System.out.println(String.format("Exception %s", e.getMessage()));
    }
    System.exit(0);
  }
}

流式输出

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

import json
import dashscope
from dashscope import Generation
from http import HTTPStatus

responses = Generation.call(
    model='sanle-v1',
    prompt='请简要介绍一下浙江大学',
    stream=True,
)
# 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.
for response in responses:
    if response.status_code==HTTPStatus.OK:
        print(json.dumps(response.output, indent=4, ensure_ascii=False))
    else:
        print('Code: %d, status: %s, message: %s' % (response.status_code, response.code, response.message))
// Copyright (c) Alibaba, Inc. and its affiliates.

import java.util.concurrent.Semaphore;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.ResultCallback;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import io.reactivex.Flowable;

public class Main {
  private static final String model="sanle-v1";
  private static final String prompt="请简要介绍一下浙江大学";
  public static void streamCall()
      throws NoApiKeyException, ApiException, InputRequiredException {
    Generation gen = new Generation();
    QwenParam param = QwenParam.builder().model(model)
        .prompt(prompt).topP(0.8).build();
    Flowable<GenerationResult> result = gen.streamCall(param);
    result.blockingForEach(message -> {
      System.out.println(JsonUtils.toJson(message));
    });
  }

  public static void streamCallWithCallback()
      throws NoApiKeyException, ApiException, InputRequiredException,InterruptedException {
    Generation gen = new Generation();
    QwenParam param = QwenParam.builder().model(model)
        .prompt(prompt).topP(0.8).build();
    Semaphore semaphore = new Semaphore(0);
    gen.streamCall(param, new ResultCallback<GenerationResult>() {

      @Override
      public void onEvent(GenerationResult message) {
        System.out.println(message);
      }
      @Override
      public void onError(Exception err){
        System.out.println(String.format("Exception: %s", err.getMessage()));
        semaphore.release();
      }

      @Override
      public void onComplete(){
        System.out.println("Completed");
        semaphore.release();
      }
      
    });
    semaphore.acquire();

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

参数配置

参数

类型

默认值

说明

model

string

-

指定用于对话的智海三乐教育大模型名,sanle-v1.

prompt

string

-

用户当前输入的期望模型执行指令。

history (可选)

list[dict]

[]

用户与模型的对话历史,list中的每个元素是形式为{"user":"用户输入","bot":"模型输出"}的一轮对话,多轮对话按时间正序排列。

top_p (可选)

float

0.8

生成过程中核采样方法概率阈值,例如,取值为0.8时,仅保留概率加起来大于等于0.8的最可能token的最小集合作为候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的确定性越高。

stream (可选)

bool

False

是否使用流式输出。当以stream模式输出结果时,接口返回结果为generator,需要通过迭代获取结果,每个输出为当前生成的整个序列,最后一次输出为最终全部生成结果。

top_k

float

100.0

生成时,采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。注意:如果top_k的值大于100,top_k将采用默认值100

seed

int

1234

生成时,随机数的种子,用于控制模型生成的随机性。如果使用相同的种子,每次运行生成的结果都将相同;当需要复现模型的生成结果时,可以使用相同的种子。seed参数支持无符号64位整数类型。默认值 1234

返回结果

  • 返回结果示例

{
    "status_code": 200,
    "request_id": "39a41abe-1bed-430a-b9b5-277130c7eb82",
    "code": "",
    "message": "",
    "output": {
        "text": "浙江大学是一所位于中国浙江省杭州市的著名高校,创建于1897年 ... ... 是中国顶尖的综合性大学之一。",
    		"finish_reason": "stop"
    },
    "usage": {
        "input_tokens": 72,
        "output_tokens": 63
    }
}
  • 返回参数说明

返回参数

类型

说明

status_code

int

200(HTTPStatus.OK)表示请求成功,否则表示请求失败,可以通过code获取错误码,通过message字段获取错误详细信息。

request_Id

string

系统生成的标志本次调用的id。

code

string

表示请求失败,表示错误码,成功忽略。

message

string

失败,表示失败详细信息,成功忽略。

output

dict

调用结果信息,对于千智海三乐教育大模型,包含输出text。

usage

dict

计量信息,表示本次请求计量数据。

text

string

模型生成回复。

finish_reason

string

有三种情况:正在生成时为null,生成结束时如果由于停止token导致则为stop,生成结束时如果因为生成长度过长导致则为length。

input_tokens

int

用户输入文本转换成Token后的长度。

output_tokens

int

模型生成回复转换为Token后的长度。

HTTP调用接口

功能描述

智海三乐教育大模型同时支持 HTTP 调用来完成客户的响应,目前提供普通 HTTP 和 HTTP SSE 两种协议,您可根据自己的需求自行选择。

前提条件

提交接口调用

POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation

入参描述

传参方式

字段

类型

必选

描述

示例值

Header

Content-Type

String

请求类型:application/json

application/json

Accept

String

*/*,选择text/event-stream则会开启 SSE 响应,默认无设置

text/event-stream

Authorization

String

API-Key,例如:Bearer d1**2a

Bearer d1**2a

X-DashScope-SSE

String

跟Accept: text/event-stream 二选一即可启用SSE响应

enable

Body

model

String

指明需要调用的模型,此处选择sanle-v1

sanle-v1

input.prompt

String

用户当前输入的期望模型执行指令,支持中英文。

sanle-v1 prompt字段支持 6.5k Tokens 长度

请介绍一下浙江大学

input.history

List

用户与模型的对话历史,list中的每个元素是形式为{"user":"用户输入","bot":"模型输出"}的一轮对话,多轮对话按时间正序排列。

"history":[

{

"user":"你知道浙江大学么",

"bot":"我当然知道浙江大学"

}]

parameters.top_p

Float

生成时,核采样方法的概率阈值。例如,取值为0.8时,仅保留累计概率之和大于等于0.8的概率分布中的token,作为随机采样的候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的随机性越低。默认值 0.8。注意,取值不要大于等于1

0.8

parameters.top_k

Integer

生成时,采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。注意:如果top_k的值大于100,top_k将采用默认值100

50

parameters.seed

Integer

生成时,随机数的种子,用于控制模型生成的随机性。如果使用相同的种子,每次运行生成的结果都将相同;当需要复现模型的生成结果时,可以使用相同的种子。seed参数支持无符号64位整数类型。默认值 1234

65535

出参描述

字段

类型

描述

示例值

output.text

String

本次请求的算法输出内容。

浙江大学是一所位于中国浙江省杭州市的著名高校

output.finish_reason

String

有三种情况:正在生成时为null,生成结束时如果由于停止token导致则为stop,生成结束时如果因为生成长度过长导致则为length。

stop

usage.output_tokens

Integer

本次请求算法输出内容的 token 数目。

380

usage.input_tokens

Integer

本次请求输入内容的 token 数目。在打开了搜索的情况下,输入的 token 数目因为还需要添加搜索相关内容支持,所以会超出客户在请求中的输入。

633

request_id

String

本次请求的系统唯一码

7574ee8f-38a3-4b1e-9280-11c33ab46e51

请求示例(SSE 关闭)

以下示例展示通过CURL命令来调用智海三乐教育大模型的脚本(SSE 关闭)。

说明

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

curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json' \
--data '{
    "model": "sanle-v1",
    "input": {
        "prompt": "请简要介绍一下浙江大学",
        "history":[
            {
                "user": "你知道浙江大学么",
                "bot": "我当然知道浙江大学"
            }
        ]
    },
    "parameters": {
        "top_p": 0.8,
        "top_k": 50,
        "seed": 42
    }
}'

响应示例(SSE关闭)

{
    "output": {
        "finish_reason": "stop",
        "text": "浙江大学是一所位于中国浙江省杭州市的著名高校,创建于1897年 ... ... 是中国顶尖的综合性大学之一。"
    },
    "usage": {
        "output_tokens": 72,
        "input_tokens": 63
    },
    "request_id": "6ec483a3-0e95-93f1-bb1c-de545bfdc904"
}

请求示例(SSE开启

以下示例展示通过CURL命令来调用智海三乐教育大模型的脚本(SSE 开启)。

说明

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

curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json' \
--header 'X-DashScope-SSE: enable' \
--data '{
    "model": "sanle-v1",
    "input": {
        "prompt": "请简要介绍一下浙江大学",
        "history":[
            {
                "user":"你知道浙江大学么",
                "bot":"我当然知道浙江大学"
            }
        ]
    },
    "parameters": {
        "top_p": 0.8,
        "top_k": 50,
        "seed": 42, 
        "enable_search": false
    }
}'

响应示例(SSE开启

id:1
event:result
data:{"output":{"finish_reason":"null","text":"浙江大学是一所"},"usage":{"output_tokens":3,"input_tokens":85},"request_id":"1117fb64-5dd9-9df0-a5ca-d7ee0e97032d"}

id:2
event:result
data:{"output":{"finish_reason":"null","text":"浙江大学是一所位于中国浙江省杭州市的著名高校"},"usage":{"output_tokens":11,"input_tokens":85},"request_id":"1117fb64-5dd9-9df0-a5ca-d7ee0e97032d"}

... ... ... ...
... ... ... ...

id:10
event:result
data:{"output":{"finish_reason":"stop","text":"浙江大学是一所位于中国浙江省杭州市的著名高校,创建于1897年 ... ... 是中国顶尖的综合性大学之一。"},"usage":{"output_tokens":51,"input_tokens":85},"request_id":"1117fb64-5dd9-9df0-a5ca-d7ee0e97032d"}

异常响应示例

在访问请求出错的情况下,输出的结果中会通过 code 和 message 指明出错原因。

{
    "code":"InvalidApiKey",
    "message":"Invalid API-key provided.",
    "request_id":"fb53c4ec-1c12-4fc4-a580-cdb7c3261fc1"
}

状态码说明

DashScope灵积模型服务通用状态码请查阅:返回状态码说明

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