真实对比kimi、通义千问、文心一言的写代码能力,到底谁强?

🤖AI改变生活:最近都在说月之暗面的kimi的各项能力吊打国内其他大模型,今天我们真实感受下 kimi、通义千问、文心一言的根据需求写代码的能力。

测评结果让人震惊!

kimi

kimi编程过程

我们先看一下热捧的月之暗面的kimi模型。

第一次运行有错误,很正常,我们继续把错误发给kimi,让他修复。



kimi仿佛进入了错误死循环,始终无法修复错误,我认为他可能上下文理解错乱,所以重新描述了自己的需求,让他重新作答。结果依然无法使用。

而且错误变得很离谱,连包都没有导入。

又经过多轮对话,我发现他始终无法修复自己的错误。
最终我放弃和他的对话。

最终代码:

kimi的代码越改越复杂,使用canvas更复杂,有大部分错误发生在canvas绘制和字体选择上,没编程基础,都无法调试。

import os  
from tkinter import Tk, Button, Label, Entry, filedialog, messagebox  
from PIL import Image  
from reportlab.pdfbase import pdfmetrics  
from reportlab.pdfbase.ttfonts import TTFont  
from reportlab.pdfgen import canvas  
from reportlab.lib.pagesizes import A4  
  
# 注册字体  
def register_font(font_name, font_path):  
    try:  
    pdfmetrics.registerFont(TTFont(font_name, font_path))  
    except IOError as e:  
    print("Error registering font:", e)  
  
# 合并图片到PDF  
def merge_images_to_pdf(folder_path, output_pdf_path):  
    register_font('SimSun', r'C:\Windows\Fonts\simsun.ttc')  # 确保提供正确的字体文件路径  
    pdf = canvas.Canvas(output_pdf_path, pagesize=A4)  
    current_page = 1  
    page_height = pdf._pagesize[1]  
  
    images = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp'))]  
  
    for img_path in images:  
    img = Image.open(img_path).convert('RGB')  # 确保图像为RGB模式  
    width, height = img.size  
    if height > page_height:  
    # 如果图片高度大于页面高度,需要创建新页面  
    pdf.showPage()  
    current_page += 1  
    page_height = pdf._pagesize[1]  
    pdf.drawImage(img, width, height, x=(A4[0] - width) / 2, y=page_height - height)  
  
    pdf.save()  
    messagebox.showinfo("Success", "PDF Created Successfully!")  
  
# 选择文件夹  
def select_folder(entry):  
    folder_path = filedialog.askdirectory()  
    entry.delete(0, 'end')  
    entry.insert(0, folder_path)  
  
# GUI应用程序的主函数  
def main():  
    root = Tk()  
    root.title("Image to PDF Converter")  
  
    Label(root, text="Select the folder containing images:").pack()  
    folder_path_entry = Entry(root, width=50)  
    folder_path_entry.pack()  
  
    Button(root, text="Browse", command=lambda: select_folder(folder_path_entry)).pack()  
    Button(root, text="Run", command=lambda: merge_images_to_pdf(folder_path_entry.get(), "merged.pdf")).pack()  
  
    root.mainloop()  
  
if __name__ == "__main__":  
    main()

结论:kimi代码编写失败。

通义千问

通义千问编码过程

无一例外第一次都会报错。

很惊喜,通义千问修改代码后,代码就运行成功。

我们看下生成的pdf效果。

pdf内容是出来了,我们再让他优化下程序,将UI调大,pdf中图片调成一样大小。

有一个错误,让他修复,修复后成功。

最终UI效果:

最终PDF内容:

最终代码:

通义千问给的代码更少,选择的库img2pdf比较合适。

import os  
import tkinter as tk  
from tkinter import filedialog  
import img2pdf  
  
''' 
模型:通义千问
需求:把一个文件夹中的图片转换成pdf文件,要求有一个界面,可以选择图片所在路径,然后点击运行,可以生产pdf文件,然后输出pdf所在路径。请保证相关的包都导入,如果用到字体,使用宋体常规。
UI大小适中,pdf内容图片一样大小。
''' 
def select_folder():  
    folder_path = filedialog.askdirectory()  
    if folder_path:  
	    pdf_output_path = os.path.join(folder_path, "output.pdf")  
	    images_list = [os.path.join(folder_path, img) for img in os.listdir(folder_path) if img.endswith(('.png', '.jpg', '.jpeg'))]  
	  
	    # 按照文件名排序,确保顺序正确  
	    images_list.sort()  
	  
	    with open(pdf_output_path, "wb") as f:  
		    pdf_bytes = img2pdf.convert(images_list)  
		    f.write(pdf_bytes)  
	  
	    print(f"PDF文件已生成并保存至:{pdf_output_path}")  
	  
  
def main():  
    root = tk.Tk()  
    root.title("图片转PDF工具")  
  
    browse_button = tk.Button(root, text="选择图片文件夹", command=select_folder)  
    browse_button.pack(pady=10)  
  
    root.mainloop()  
  
  
if __name__ == "__main__":  
    main()

结论:通义千问代码编写成功。

上面还有一个小问题,是通义千问给的UI并没有“运行”按钮,如果需要,可以继续让他添加按钮,但是已经很好了。

文心一言

文心一言编码过程

文心一言给的这段代码连编译都错误,很明显下面代码中少了一个右括号

img = img.resize((int(img_width * 0.75), int(img_height * 0.75)), Image.ANTIALIAS  


经过我的提示,它好像明白了,但是给的修正后的代码依然没有添加右括号🙄。
算了,原谅它的无知,我手动添加括号试试。

文心一言后面就和kimi一样,进入了错误循环。
大概又经过4次调试,代码终于调通,能够生成pdf,但是文件内容不完整。

最终代码

文心一言和kimi给的代码非常多,使用canvas库,复杂度更高,更难以调试。

from tkinter import Tk, filedialog, Label, Button, Entry, mainloop  
from PIL import Image  
from reportlab.pdfgen import canvas  
from reportlab.lib.pagesizes import letter  
import os  
  
  
def resize_image(image_path, max_width=None, max_height=None):  
    """  
    Resize an image to fit within the given maximum width and height.  
    Aspect ratio is preserved.  
    """  
    with Image.open(image_path) as img:  
    orig_width, orig_height = img.size  
    if max_width is None and max_height is None:  
    # No resizing needed if no max width or height is specified  
    return img  
    if max_width is None:  
    max_width = orig_width  
    if max_height is None:  
    max_height = orig_height  
  
    # Calculate the scaling factor to fit the image  
    width_ratio = max_width / float(orig_width)  
    height_ratio = max_height / float(orig_height)  
    ratio = min(width_ratio, height_ratio)  
  
    # Resize the image  
    new_size = (int(orig_width * ratio), int(orig_height * ratio))  
    resized_img = img.resize(new_size, Image.ANTIALIAS)  
    return resized_img  
  
  
def convert_images_to_pdf(image_folder, output_pdf):  
    images = [img for img in os.listdir(image_folder) if  
    img.lower().endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif"))]  
    if not images:  
    print("No images found in the folder.")  
    return  
  
    c = canvas.Canvas(output_pdf, pagesize=letter)  
    height = letter[1] - 72  # 72 is the margin at the top  
  
    for img_name in images:  
    img_path = os.path.join(image_folder, img_name)  
  
    # Resize the image to fit the page width (or a specified maximum size)  
    resized_img = resize_image(img_path, max_width=letter[0] - 72)  # 72 is for the left and right margins  
  
    # Calculate the new height based on the resized width to preserve aspect ratio  
    new_height = int((resized_img.size[1] * (letter[0] - 72) / resized_img.size[0])  
  
    # Draw the resized image onto the canvas  
    c.drawImage(resized_img, 36, height - new_height, width=resized_img.size[0], height=new_height)  
  
    # Update the current height for the next image  
    height -= new_height + 12  # 12 is the gap between images  
  
    if height < 36:  # Add a new page if needed  
    c.showPage()  
    height = letter[1] - 72  
  
    # Save the PDF and close the canvas  
    c.save()  
    print(f"PDF saved to: {output_pdf}")  
  
  
def select_directory():  
    directory = filedialog.askdirectory()  
    entry_image_folder.delete(0, 'end')  
    entry_image_folder.insert(0, directory)  
  
  
# 创建GUI界面  
root = Tk()  
root.title('Image to PDF Converter')  
  
# 图片文件夹输入  
label_image_folder = Label(root, text='Select Image Folder:')  
label_image_folder.pack()  
entry_image_folder = Entry(root, width=50)  
entry_image_folder.pack()  
  
# 选择文件夹按钮  
button_select_folder = Button(root, text='Select Folder', command=select_directory)  
button_select_folder.pack()  
  
# 转换按钮  
button_convert = Button(root, text='Convert to PDF',  
                        command=lambda: convert_images_to_pdf(entry_image_folder.get(), 'output.pdf'))  
button_convert.pack()  
  
# 运行GUI主循环  
mainloop()

我想让他继续优化pdf内容,但是接下来再调试,也无法调试成功。放弃吧~

结论:文心一言代码编写失败。

总结

按照编码运行结果排序:通义千问 > 文心一言 > kimi。

按照编码纠错效率排序:通义千问 > 文心一言 > kimi。

按照代码质量排序:通义千问> kimi / 文心一言 。

如果您对测评结果有疑问,欢迎交流,更多大模型案例在公众号首发。

#AIGC #kimi #通义千问 #文心一言 #大模型

  • 15
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我很乐意为您编一个贪吃蛇代码,包含所有代码。以下是代码:#include <stdio.h> #include <stdlib.h> #include <windows.h>int main() { // 初始化游戏 int i, j; int score = 0; int level = 1; int speed = 200; int food_x = 0; int food_y = 0; int size = 3; int snake_x[60] = {0}; int snake_y[60] = {0}; int dir = 0; // 初始化屏幕 system("cls"); for (i = 0; i < 20; i++) { for (j = 0; j < 30; j++) { printf(" "); } printf("\n"); } // 初始化蛇的位置 snake_x[0] = 15; snake_y[0] = 10; for (i = 1; i < size; i++) { snake_x[i] = snake_x[i - 1] - 1; snake_y[i] = snake_y[i - 1]; } // 生成食物 food_x = rand() % 20; food_y = rand() % 30; // 开始游戏 while (1) { // 画出屏幕 system("cls"); for (i = 0; i < 20; i++) { for (j = 0; j < 30; j++) { if (i == 0 || i == 19 || j == 0 || j == 29) { printf("*"); } else { int flag = 0; for (int k = 0; k < size; k++) { if (i == snake_x[k] && j == snake_y[k]) { printf("@"); flag = 1; break; } } if (flag == 0) { if (i == food_x && j == food_y) { printf("$"); } else { printf(" "); } } } } printf("\n"); } // 获取用户输入 if (kbhit()) { char ch = getch(); if (ch == 'a' && dir != 2) { dir = 1; } else if (ch == 'd' && dir != 1) { dir = 2; } else if (ch == 'w' && dir != 4) { dir = 3; } else if (ch == 's' && dir != 3) { dir = 4; } } // 游戏逻辑 for (i = size - 1; i > 0; i--) { snake_x[i] = snake_x[i - 1]; snake_y[i] = snake_y[i - 1]; } switch (dir) { case 1: snake_y[0]--; break; case 2: snake_y[0]++; break; case 3: snake_x[0]--; break; case 4: snake_x[0]++; break; } // 判断游戏是否结束 if (snake_x[0] == 0 || snake_x[0] == 19 || snake_y[0] == 0 || snake_y[0] == 29) { printf("游戏结束,您的得分为:%d\n", score); break; } for (i = 1; i < size; i++) { if (snake_x[0] == snake_x[i] && snake_y[0] == snake_y[i]) { printf("游戏结束,您的得分为:%d\n", score); break; } } // 判断蛇是否吃到食物 if (snake_x[0] == food_x && snake_y[0] == food_y) { size++; food_x = rand() % 20; food_y = rand() % 30; score += 10; if (score % 50 == 0) { level++; speed -= 50; } } Sleep(speed); } return 0; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值