通义法睿是以通义千问为基座经法律行业数据和知识专门训练的法律行业大模型产品,综合运用了模型精调、强化学习、 RAG检索增强、法律Agent及司法专属小模型技术,具有回答法律问题、推理法律适用、推荐裁判类案、辅助案情分析、生成法律文书、检索法律知识、审查合同条款等功能。
模型具备的能力包括但不限于:
法律问答
要素抽取
案情摘要
文书生成
案由识别
法条预测
争议焦点识别
快速开始
前提条件
示例代码
说明
需要使用您的API-KEY替换示例中的YOUR_DASHSCOPE_API_KEY,代码才能正常运行。
python sdk version: dashscope>=1.10.0
java sdk version: >=2.5.0
设置API-KEY
export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
通过messages调用(推荐)
from http import HTTPStatus
import dashscope
def call_with_messages():
messages = [{'role': 'system',
'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': '我哥欠我10000块钱,给我生成起诉书。'}]
response = dashscope.Generation.call(
"farui-plus",
messages=messages,
result_format='message', # set the result to be "message" format.
)
if response.status_code == HTTPStatus.OK:
print(response)
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
if __name__ == '__main__':
call_with_messages()
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.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;
public class Example {
public static void callWithMessage()
throws NoApiKeyException, ApiException, InputRequiredException {
Generation gen = new Generation();
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("我哥欠我10000块钱,给我生成起诉书。")
.build();
msgManager.add(systemMsg);
msgManager.add(userMsg);
QwenParam param =
QwenParam.builder().model("farui-plus").messages(msgManager.get())
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.apiKey("xxx")
.build();
GenerationResult result = gen.call(param);
System.out.println(result);
}
public static void main(String[] args){
try {
callWithMessage();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
python调用成功,将输出如下结果
{
"status_code": 200,
"request_id": "0bcab0eb-ee6b-983d-9479-9814cff59096",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "【民事起诉状】\n\n原告:XXX,男/女,XXXX年XX月XX日出生,XXX族,住所地:XXX市XXX区XXX路XXX号,联系方式:XXX。\n委托诉讼代理人:XXX,(律所名称)。\n\n被告: XXX,男/女,XXXX年XX月XX日出生,XXX族,住所地:XXX市XXX区XXX路XXX号,联系方式:XXX。\n\n诉讼请求:\n一、要求被告归还原告借款10000元;\n二、由被告承担本案全部诉讼费用。\n\n事实与理由:\n原告与被告系兄弟关系。2019年9月10日,被告因急需用钱向原告借款10000元,并出具借条一份,约定借款期限为一个月。然而,借款期限届满后,被告并未按约定归还借款,原告多次催讨均无果。\n\n证据清单:\n1. 借条1份;\n2. 转账记录1份。\n\n此致\n\nXXX人民法院\n\n起诉人:(原告签名)\n\nXXXX年XX月XX日\n\n附:1.本诉状副本XXX份。\n 2.证据目录。\n\n请注意,这只是一个模板,具体情况可能需要根据实际情况进行调整。在实际操作中,建议您咨询专业律师或者法律工作者,以确保起诉书的准确性和合法性。"
}
}
]
},
"usage": {
"input_tokens": 56,
"output_tokens": 284,
"total_tokens": 340
}
}
通过prompt调用
# For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html
from http import HTTPStatus
import dashscope
def call_with_prompt():
response = dashscope.Generation.call(
model="farui-plus",
prompt='我哥欠我10000块钱,给我生成起诉书。'
)
# 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.
if __name__ == '__main__':
call_with_prompt()
package com.alibaba.judicial.ai;
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 Example8 {
private final static String PROMPT = "我哥欠我10000块钱,给我生成起诉书。";
public static void qwenQuickStart()
throws NoApiKeyException, ApiException, InputRequiredException {
Generation gen = new Generation();
QwenParam param = QwenParam.builder()
.model("farui-plus")
.apiKey("xxxx")
.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("farui-plus")
.apiKey("xxxxx")
.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);
}
}
调用成功后,将会返回如下示例结果。
{"text": "【民事起诉状】\n\n原告:(你的姓名、性别、年龄、民族、职业、工作单位、住址、联系方式)\n\n被告:(你哥哥的姓名、性别、年龄、民族、职业、工作单位、住址、联系方式)\n\n诉讼请求:\n一、判令被告归还原告借款本金10000元;\n二、判令被告支付自借款之日起至实际清偿之日止的利息(根据相关法律规定计算);\n三、由被告承担本案全部诉讼费用。\n\n事实与理由:\n原告与被告系兄弟关系。2021年1月1日,被告因个人需要向原告借款10000元,并出具借条一份,约定借款期限为6个月,月利率为1%。原告于当日通过银行转账方式将借款本金10000元交付给被告。然而,借款到期后,被告未按约定归还借款本金及利息。原告多次催讨未果,现借款已逾期,被告的行为已构成违约。\n\n证据清单:\n1. 借条原件1份;\n2. 银行转账记录1份。\n\n此致\n\nXXX人民法院\n\n起诉人:(你的签名)\n\nXXXX年XX月XX日\n\n附:1.本诉状副本XXX份。\n 2.证据目录。", "finish_reason": "stop", "choices": null}
{"input_tokens": 16, "output_tokens": 274, "total_tokens": 290}
了解更多
有关通义法睿大模型API的详细调用文档可前往API详情页面进行了解。
文档内容是否对您有帮助?