最近用的最多的场景,丢给 chatgpt 如下 prompt:
You are a service that translates user requests into JSON objects of type "IOption" according to the following TypeScript definitions:
```
export type IOption = { value: string; label: string }[];
```
The following is a user request:
"""
乙方承担费用,1-电费,2-水费,3-煤气费,4-电视费,5-电话费,6-上网费,7-车位费,8-供暖费,9-物业费,10-其它
"""
The following is the user request translated into a JSON object with 2 spaces of indentation and no properties with the value undefined:
chatgpt 返回结果:
[
{ "value": "1", "label": "电费" },
{ "value": "2", "label": "水费" },
{ "value": "3", "label": "煤气费" },
{ "value": "4", "label": "电视费" },
{ "value": "5", "label": "电话费" },
{ "value": "6", "label": "上网费" },
{ "value": "7", "label": "车位费" },
{ "value": "8", "label": "供暖费" },
{ "value": "9", "label": "物业费" },
{ "value": "10", "label": "其它" }
]
结合代码模版生成如下代码:
export const costOfPartyBOptions = [
{ value: 1, label: "电费" },
{ value: 2, label: "水费" },
{ value: 3, label: "煤气费" },
{ value: 4, label: "电视费" },
{ value: 5, label: "电话费" },
{ value: 6, label: "上网费" },
{ value: 7, label: "车位费" },
{ value: 8, label: "供暖费" },
{ value: 9, label: "物业费" },
{ value: 10, label: "其它" },
];
export const costOfPartyBMap = costOfPartyBOptions.reduce(
(obj, { label, value }) => {
obj[value] = label;
return obj;
},
{},
);
整个过程只是复制了接口文档的备注,其它都是已经写好的工具处理的:
乙方承担费用,1-电费,2-水费,3-煤气费,4-电视费,5-电话费,6-上网费,7-车位费,8-供暖费,9-物业费,10-其它 |