js json 生成 字段注释
D:\proj\tool\my_util_private\jsObjDocGen.js
let obj = {
"id": "0a92e7d9",
"conversationId": "81f8f396",
"personId": "ea38108e",
"text": "b6f5f494",
"audioFileToken": "69f3e515",
"translationResult": "2ba14003",
"createTime": {
"date": {
"year": -829233272,
"month": 433736398,
"day": -1093198240
},
"time": {
"hour": "0",
"minute": "0",
"second": "0",
"nano": -2067186232
}
},
"deleted": false,
"insertTime": 648848170,
"updateTime": 2049751701,
"deleteTime": -1846444143
}
obj = {
"creator": "4fb67f4d",
"topic": "b06b8336",
"id": "95e0d834",
"deleted": false,
"insertTime": 950660558,
"updateTime": 2075673529,
"deleteTime": 1124049122
}
obj= { id:"id",
conversationId:"conversationId",
personId:"personId",
// 这个是后端根据token会拿到的 所以save的时候 前端不用传递
text:"hello", audioFileToken:"audioFileToken",
// 文件token(可选)
translationResult:"你好",
deleted:false,
// (前端不用传递,这个是后端自动生成的)
insertTime:1692020262222,
// (前端不用传递,这个是后端自动生成的)
updateTime:1692020262223,
// (前端不用传递,这个是后端自动生成的)
deleteTime:1692020262223,
// (前端不用传递,这个是后端自动生成的)
}
function nowMs() {
return Date.now()
}
function strWarp(key) {
return `"${key}"`
}
function getShowVal(key) {
let mapToShowVal = {
insertTime: nowMs(),
deleteTime: nowMs(),
updateTime: nowMs(),
createTime: "" + new Date(),
topic: "一个主题",
creator: "school001",
"deleted": false,
text: "hello",
translationResult: "你好",
}
let showVal = mapToShowVal[key]
if (key == 'deleted') {
return false
}
if (showVal) {
if (typeof showVal === 'string' || showVal instanceof String) {
return strWarp(showVal)
}
return showVal
}
return `"${key}"`
}
function getShowCmt(key) {
let mapToCmt = {
insertTime: "(不用传递)插入时间,插入数据的时候默认不传递,后端自动设置.修改数据的时候一般也不传递,因为插入时间是固定的",
deleteTime: "(不用传递),后端处理",
updateTime: "(不用传递),后端处理",
createTime: "(不用传递),后端处理",
conversationId: "会话id(必须)-消息需要关联",
"id":"插入的时候前端传递null,因为数据库会自动生成,update的时候要根据id来指定",
topic: "一个主题",
creator: "createorId--后端根据token获取-save时候前端不需要传递",
"deleted": "如果是插入数据,默认不用传递,后端会设置为false,认为他新建的时候是没有被删除的",
text: "原文",
max_new_tokens :"(可选) AI在每个响应中最多生成的新token数。",
conversation_id: "对话ID,(可选)由客户端生成。必须是UUID的格式。(这个是mongo生成,前端先创建一个会话,后端会返回这个会话id,于是前端就可以用这个会话id来调用这个接口)",
user_id :"应用的用户ID(可选),用于审查。",
translationResult: "翻译结果字符串(可选)",
audioFileToken:"文件token(可选)",
"model":"选择的模型名称。(非必填 可选值:openbuddy-llama-30b-v7.1-bf16)",
messages:"messages (必须): 会话消息数组,每个元素是一个对象,包含角色(role,可以是“user”或“assistant”)和内容(content)。"
// translationResult:"文件token(可选)"
}
let showVal = mapToCmt[key]
if (showVal) {
if (typeof showVal === 'string' || showVal instanceof String) {
return strWarp(showVal)
}
return showVal
}
return `"${key}"`
}
// @apiParam {String} conversation.id ID (不需要传递,后端生成)
function desp_apiParam(key, value) {
// let showVal = getShowVal(key)
let entityName="conversation"
row = `${entityName}.${key} ${ getShowCmt(key)}`
// console.log(row);
return row
}
function desp(key, value) {
let showVal = getShowVal(key)
row = `${key}:${showVal}, // ${ getShowCmt(key)}`
console.log(row);
}
let desp_apiParamRowList=[]
for (let key in obj) {
// @apiParam {String} conversation.id ID (不需要传递,后端生成)
let val=obj[key]
desp(key, obj[key])
let desp_apiParamRow=desp_apiParam(key, val)
desp_apiParamRowList.push(desp_apiParamRow)
}