Blog

Blog

PHODAL

AutoDev 1.1 更新:自定义大模型、自定义 prompt 行为项、自定义规范

在过去的半个月里,我们为开源辅助编程工具 AutoDev 添加了更强大的自定义能力,现在你可以:

  • 使用自己部署的开源大模型
  • 自己配置 Intellij IDEA 中的行为
  • 自定义开发过程中的规范

当然了,如果您自身拥有开发能力的话,建议您自己基于 AutoDev 定制。毕竟,为 AutoDev 添加太多的自定义能力,会导致架构的复杂性螺旋上升。

AutoDev 现在已支持多语言(不同语言能力有所差异)、多 IDE,因此只在 JetBrains 任何一个本地 IDE 的插件市场里,搜索 AutoDev 并安装 即可。

自定义大语言模型

我们通过 Thoughtworks 正在的开源底层模型平台 Gluon Meson,构建了一个统一的大语言模型接口。随后,我们测试了切换几个开源模型:清华大学 ChatGLM2-6B、阿里云通义千问 Qwen-7B 等,均可以流畅使用 —— 模型太小,在诸如需要上下文补全的能力没有那么强。

考虑到提供更好的开发者体验,现在的 AutoDev 只支持服务端的流式返回,为此我们在源码中提供了一个 FastAPI + EventSourceResponse 的示例作为参考。

请求结构

我们发送给服务端的接口将类似于:

{
  "messages": [
     { "role": "user", "message": "I'm Nihillum." },
     { "role": "assistant", "message": "OK" },
     { "role": "user", "message": "What did I just say?" }
  ]
}

根据现有的 #25 issue 设计情况,我们也将在未来提供更多的可配置的 headers 等

响应结果

对于结果来说,为了方便支持不同的模型,我们使用了 JSON Path 来处理返回结果。如下是一个简单的 JSON Path 的配置示例。

$.choices[0].content

随后,将从 content 中取值,并处理。

详细见 README.md 中的 Custom LLM Server 部分。

自定义 prompt 行为项

为了配合不同大模型的能力差异,我们参考了 JetBrains AI Assistant 的设计,也在 AutoDev 中引入了自定义行为的方式,即你可以自定义自己的行为,并配置 prompt 的上下文。诸如于,你可以自定义一个将 Rust 转为 Kotlin 语言的行为项。

为此,只需要添加一个对应的 JSON 配置即可:

{
  "prompts": [
    {
      "title": "\uD83C\uDDE8\uD83C\uDDF3 翻译成 Kotlin",
      "autoInvoke": false,
      "matchRegex": ".*",
      "priority": 1000,
      "template": "Translate the following code to Kotlin.\n${SIMILAR_CHUNK}\nCompare these snippets:\n${METHOD_INPUT_OUTPUT}\nHere is the code:\n${SELECTION}"
    }
  ]
}

其中的 priority 是用来配置在菜单中的顺序,template 则是发送给 LLM 的 prompt。除此,在 template 中,为了更好的支持一些高级的特征,我们配置了一些上下文变量:

  • ${SELECTION}:所选代码
  • ${SIMILAR_CHUNK}:相似的代码片段
  • ${METHOD_INPUT_OUTPUT}:方法的输入与输出

规范变量:

  • ${SPEC_*}:从配置文件的规范部分加载规范,比如${SPEC_controller}将会从配置中加载spec.controller

详细见 README.md 中的 Custom Action 部分。

自定义规范

在自定义操作项中,我们会定义一些不同任务的配置规则,诸如于 SPEC_controller 便会从 spec 中读取对应的内容,作为配置 prompt 的一部分:

{
  "spec": {
    "controller": "- Use BeanUtils.copyProperties in the Controller for DTO to Entity conversion.\n- Avoid using Autowired.\n- Use Swagger Annotations to indicate API meanings.\n- Controller methods should capture and handle business exceptions, rather than throwing system exceptions.",
    "service": "- Service layer should use constructor injection or setter injection; avoid using the @Autowired annotation.",
    "entity": "- Entity classes should use JPA annotations for database mapping.\n- The entity class name should match the corresponding database table name. Entity classes should use annotations to mark primary keys and table names, for example: @Id, @GeneratedValue, @Table, etc.",
    "repository": "- Repository interfaces should extend the JpaRepository interface to inherit basic CRUD operations.",
    "ddl": "- Fields should be constrained with NOT NULL constraints to ensure data integrity."
  }
}

然后,你就可以愉快地进行 AI 辅助编程了。

小结

如果大家遇到什么问题或者有什么好玩的新需求,欢迎来 GitHub 讨论:https://github.com/unit-mesh/auto-dev

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签