在這一篇網路訊息中提到,Phind Model這是一種基於CodeLlama-34B的人工智慧模型,可以用來回答技術問題。它擁有高速、高容量和高準確度的特點,並且可以利用網路資源來增強其能力。作者聲稱在HumanEval這個測試中超越了GPT-4,並且在實際問題中也比GPT-4更有幫助。此外,Phind Model還比GPT-4快五倍,並且可以支援最多16k個字元的輸入。
不過,也有其缺點,就是作者認為在一些困難的問題上可能不夠一致,需要多次生成才能得到正確的答案。而且,還沒有經過同行評審或其他研究者的驗證。
因此我也好奇使用Phind 與GPT-4之間進行程式碼的比較,我所使用的prompt如下,我就比較OrderController.java的差異直接擷取他們各自產生的檔案:
Could you create a project of spring boot, to call a api resource that name is ‘/v1/orders/ and the json format is ‘{“order_no”:”123″, “total_price”:123}, and then respose json format is ‘{“status”:”done”}. We need update status field in order table, the table pk column is order_no. please provide group, java code, jave file name,… all files what we need.
- Phind
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/v1/orders")
public class OrderController {
@Autowired
private OrderService orderService;
@PutMapping
public ResponseEntity<String> updateOrderStatus(@RequestBody Order order) {
orderService.updateOrderStatus(order.getOrderNo(), order.getStatus());
return ResponseEntity.ok("{\"status\":\"done\"}");
}
}
- GPT-4
package com.example.demo.controller;
import com.example.demo.service.OrderService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/v1/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService) {
this.orderService = orderService;
}
@PutMapping("/{orderNo}")
public ResponseEntity<?> updateOrder(@PathVariable String orderNo,
@RequestParam Double totalPrice) {
orderService.updateOrderStatus(orderNo, totalPrice);
return ResponseEntity.ok().body(new StatusResponse("done"));
}
private static class StatusResponse {
private String status;
public StatusResponse(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
}
GPT-4 代碼使用了更多Spring推薦的做法,如構造函數注入和靈活的返回類型。它還通過@PathVariable和@RequestParam更細緻地處理了URL參數。
Phind 代碼則更為簡單直接,但使用了字段注入並手動創建了返回的JSON字符串。它還通過@RequestBody一次性獲取了整個請求體。
選擇哪一種實現方式取決於具體需求和個人喜好。如果你需要更靈活的錯誤處理或參數處理,GPT-4可能更合適。如果你喜歡簡單直觀的代碼,Phind可能更合適。
另外補充一下,GPT-4在OrderService.java中,多了一段Transactional,我認為在嚴僅性,似乎GPT-4是高了一點
package com.example.demo.service;
import com.example.demo.model.Order;
import com.example.demo.repository.OrderRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class OrderService {
private final OrderRepository orderRepository;
public OrderService(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
@Transactional
public void updateOrderStatus(String orderNo, Double totalPrice) {
Order order = orderRepository.findById(orderNo)
.orElseThrow(() -> new IllegalArgumentException("訂單不存在"));
order.setTotalPrice(totalPrice);
order.setStatus("done");
orderRepository.save(order);
}
}
你們喜歡哪一種呢?




發表迴響