需求是:提取 word 文档内容,翻译成多个语种
目前的实现方式是把 word 文档里的 xml 内容提取出来,整理成一个 list ,结构如下:
["待翻译的文本一", "待翻译的文本二"]
使用的 prompt 如下:
system prompt
你是一个{industry}行业的{language}翻译专家,请将用户输入的文字翻译成{language},翻译结果需要严格按照用户输入的 JSON 内容进行翻译,翻译后返回的 JSON 结构与用户输入的 JSON 结构需要完全一致。请参考用户输入的术语库翻译 JSON 数组内容,翻译结果输出 JSON 格式。
下面是一个用户输入内容示例:
术语库:
{"你好": "hello", "什么": "what"}
需翻译的 JSON 内容:
{"filename": "这是文件名", "items": ["你好", "这是什么", "你好"]}
请严格按照下面的要求输出翻译结果:
1. 翻译结果为合法的标准的 JSON 对象字符串(不要输出 markdown 格式),不要过度转义,输出稳定的合法的标准的 JSON 对象字符串
2. 翻译结果 JSON 包含 filename 和 items 两个 key ,并保证 items 数组元素数量和待翻译的 items 数组元素数量一致
3. 翻译结果需要严格按照用户输入的 JSON 内容进行翻译,翻译后返回的 JSON 结构与用户输入的 JSON 结构需要完全一致,并保证 items 数组元素数量和待翻译的 items 数组元素数量严格保持一致。
4. 输出示例:{"filename": "this is filename", "items": ["hello", "what is it", "hello"]}
user prompt
术语库:
xxxxxxxxxx
需翻译的 JSON 内容:
xxxxxxxxxx
但是 AI 的响应结果,有时是 json 格式,有时是 markdown 格式,有时返回的 json 里面,items 的数量和待翻译的数量又不一致
2. 受限解码,大致思想是要求 LLM 的 output 必须符合某个语法结构,如果不行就重新采样。好处是可以保证一定不会出现格式错误,但是这样做的问题是会影响本身的性能,不推荐;
```
export type PageConfig = {
filters: {
component: string;
/**
* @description 翻译成英文,驼峰格式
* @type {string}
*/
key: string;
/**
* @description 保持原始内容,不要翻译
* @type {string}
*/
label: string;
/**
* @description 保持原始内容,不要翻译
* @type {string}
*/
placeholder: string;
}[];
columns: {
slot: boolean;
/**
* @description 保持原始内容,不要翻译
* @type {string}
*/
title: string;
/**
* @description 翻译成英文,驼峰格式
* @type {string}
*/
dataIndex: string;
/**
* @description 翻译成英文,驼峰格式
* @type {string}
*/
key: string;
}[];
pagination: {
show: boolean;
page: string;
size: string;
total: string;
};
includeModifyModal: boolean;
fetchName: string;
result: string;
serviceName: string;
};
```
以下是用户请求:
"""
{"filters":[{"component":"range-picker","key":"transactionTime","label":"成交时间"},{"component":"input","key":"planName","label":"提成方案名称","placeholder":"提成方案名称(个人/店组/片区)"}],"columns":[{"slot":false,"title":"成交时间","dataIndex":"成交时间","key":"成交时间"},{"slot":false,"title":"申佣时间","dataIndex":"申佣时间","key":"申佣时间"},{"slot":false,"title":"业绩来源","dataIndex":"业绩来源","key":"业绩来源"},{"slot":false,"title":"所属片区","dataIndex":"所属片区","key":"所属片区"},{"slot":false,"title":"当前组织","dataIndex":"当前组织","key":"当前组织"},{"slot":false,"title":"提成类型","dataIndex":"提成类型","key":"提成类型"},{"slot":false,"title":"员工姓名","dataIndex":"员工姓名","key":"员工姓名"},{"slot":false,"title":"成交编号","dataIndex":"成交编号","key":"成交编号"},{"slot":false,"title":"分成角色","dataIndex":"分成角色","key":"分成角色"},{"slot":false,"title":"本次申佣业绩","dataIndex":"本次申佣业绩","key":"本次申佣业绩"},{"slot":false,"title":"提成","dataIndex":"提成","key":"提成"},{"slot":false,"title":"已算提成业绩","dataIndex":"已算提成业绩","key":"已算提成业绩"},{"slot":false,"title":"当月总提成业绩","dataIndex":"当月总提成业绩","key":"当月总提成业绩"},{"slot":false,"title":"提成方案名称","dataIndex":"提成方案名称","key":"提成方案名称"},{"slot":false,"title":"方案计算类型","dataIndex":"方案计算类型","key":"方案计算类型"}],"pagination":{"show":true,"page":"page","size":"size","total":"result.total"},"includeModifyModal":false,"fetchName":"fetchTableList","result":"[\"result\"][\"records\"]","serviceName":"getTableList"}
"""
The following is the user request translated into a JSON object with 2 spaces of indentation and no properties with the value undefined:
其次,使用 langfun