Auto-dev Sketch 返回的diff经常会错乱,如图:
通过日志查看LLM返回的大模型:
### 第二步. 在 `BlogController.java` 中添加 `deleteBlog` 的 API 接口
我已经在 `BlogController.java` 中添加了一个 `@DeleteMapping` 注解的方法 `deleteBlog`,该方法接受一个路径变量 `id`,并调用 `blogService.deleteBlog(id)` 来执行删除操作。
<devin>
/patch:src/main/java/com/phodal/shire/demo/controller/BlogController.java
```patch
Index: src/main/java/com/phodal/shire/demo/controller/BlogController.java
--- src/main/java/com/phodal/shire/demo/controller/BlogController.java
+++ src/main/java/com/phodal/shire/demo/controller/BlogController.java
@@ -24,6 +24,12 @@
}
/**
+ *
+ * @param id The id of the blog post to delete
+ */
+ @DeleteMapping("/{id}")
+ public void deleteBlog(@PathVariable Long id) {
+ blogService.deleteBlog(id);
+ }
+
+ /**
* Create a new blog post by receiving a request with blog post details.
怀疑是返回的行号存在问题,反正IDEA不识别,所以采用严格行号这种patch方式失败率会比较高。
虽然 Auto-dev 会自动修复,但因为通过IDEA PatchReader读取数据已经失败了,自动修复发送的prompt也存在问题,导致无法自动修复,发送的prompt如下:
- Add all necessary import statements, dependencies, and endpoints required to run the code.
- NEVER generate an extremely long hash or any non-textual code, such as binary. These are not helpful to the USER and are very expensive.
- Unless you are appending some small easy to apply edit to a file, or creating a new file, you MUST read the the contents or section of what you're editing before editing it.
User origin intention: 为Blog新增删除API
Here is the original code: package com.phodal.shire.demo.service;
import com.phodal.shire.demo.entity.BlogPost;
import com.phodal.shire.demo.repository.BlogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BlogService {
@Autowired
BlogRepository blogRepository;
public BlogPost createBlog(BlogPost blogDto) {
return blogRepository.save(blogDto);
}
public BlogPost getBlogPostById(Long id) {
return blogRepository.findById(id).orElse(null);
}
public BlogPost updatePost(Long id, BlogPost blogDto) {
return blogRepository.findById(id).map(blog -> {
blog.setTitle(blogDto.getTitle());
blog.setContent(blogDto.getContent());
return blogRepository.save(blog);
}).orElse(null);
}
public void deleteBlog(Long id) {
blogRepository.deleteById(id);
}
}
Here is the failed patched context: