ToB企服应用市场:ToB评测及商务社交产业平台

标题: 基于FastGPT和芋道源码挑战一句话生成代码 [打印本页]

作者: 王海鱼    时间: 2024-2-28 07:53
标题: 基于FastGPT和芋道源码挑战一句话生成代码
芋道源码相信很多朋友都很了解了,今天我们试着基于FastGPT实现芋道框架的代码生成。芋道的代码生成,是基于数据库表字段实现的,那我们的思路就是看看如何使用GPT帮我们生成数据库表结构,只要数据库表字段有了,代码也就生成好了。实现这个需求我们就需要用到FastGPT的高级编排功能。编排的整体思路如下:

FastGPT应用编排














附:芋道自定义接口示例(供参考)

  1.     @PermitAll
  2.     @PostMapping("busi/{busiType}")
  3.     public FastCommonRespVO busi(@PathVariable("busiType") String busiType, @RequestBody Map<String, Object> reqMap) {
  4.         log.info("请求参数: {}", JSONUtil.toJsonStr(reqMap));
  5.         FastCommonRespVO fastCommonRespVO = new FastCommonRespVO();
  6.         fastCommonRespVO.setResponse("\\n失败了");
  7.         FastBusiTypeEnum fastBusiTypeEnum = FastBusiTypeEnum.getByBusiCode(busiType);
  8.         if (fastBusiTypeEnum != null) {
  9.             FastService fastService = SpringUtil.getBean("fast".concat(fastBusiTypeEnum.getBusiCode()).concat("ServiceImpl"));
  10.             try {
  11.                                                     // doBusi方法会返回一个完整的代码下载地址
  12.                 fastCommonRespVO.setResponse("\\n".concat(fastService.doBusi(reqMap)));
  13.             } catch (Exception e) {
  14.                 log.error("执行业务逻辑失败,异常原因:{}", ExceptionUtils.getStackTrace(e));
  15.                 fastCommonRespVO.setResponse("\\n执行业务逻辑失败:".concat(e.getMessage()));
  16.             }
  17.         } else {
  18.             fastCommonRespVO.setResponse("\\n非法的业务类型(busiType参数)");
  19.         }
  20.         log.info("响应结果: {}", JSONUtil.toJsonStr(fastCommonRespVO));
  21.         return fastCommonRespVO;
  22.     }
复制代码
  1.     @PermitAll
  2.     @GetMapping("/download/codegen/{codegenId}")
  3.     public void downloadCodegen(@PathVariable("codegenId") String codegenId,
  4.                                 HttpServletResponse response) throws IOException {
  5.         log.info("请求参数: codegenId={}", codegenId);
  6.         // 根据生成代码记录ID查询相关表记录ID
  7.         Set<String> tableIds = stringRedisTemplate.opsForSet().members(codegenId);
  8.         if (CollectionUtils.isEmpty(tableIds)) {
  9.             throw exception(ErrorCodeConstants.AIGC_FAST_NOT_FOUND_RECORD);
  10.         }
  11.         // 生成代码
  12.         Map<String, String> codes = new HashMap<>();
  13.         for (String tableId : tableIds) {
  14.             codes.putAll(codegenApi.generationCodes(Long.valueOf(tableId)));
  15.         }
  16.         // 构建 zip 包
  17.         String[] paths = codes.keySet().toArray(new String[0]);
  18.         ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);
  19.         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  20.         ZipUtil.zip(outputStream, paths, ins);
  21.         // 输出
  22.         ServletUtils.writeAttachment(response, "codegen.zip", outputStream.toByteArray());
  23.     }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4