chatgpt 开发中的使用

170 阅读1分钟

通过copy api文档字段prompts chatgpt生成 typescript代码

前端很多时候需要把API接口文档中response数据结构转换成.ts文件,写起来简单但是繁琐,可以通过chatgpt帮忙完成。
需要生成typescriptAPI接口文档结构:

image.png

用鼠标选中copy api文档后的结构sources

  companyId string 必须 主体id 
  entityName string 必须 主体名称
  ....

输入先让chatgpt记录一段 "template 1" 代码:

Remember this code template 1:
 sources:
 
 entityName string 必须 主体名称
 
 
 Ignore “必须” and output typescript code:
 interface RowInfo{ 
    /**
    * 主体名称 
    */ 
    entityName?: string
    ....
    (The rest of the code is write here) 
 } 

输入"sources"要求chatgpt按照"template 1" 生成代码:

  sources: 
  
  companyId string 必须 主体id 
  entityName string 必须 主体名称
  
  Create a TypeScript definition based on these sources by template 1

chatgpt输出:

image.png