代码补全的 prompt 应该怎么写?

41 天前
 stimw

目前自己写的效果不是很好,模型是通义千问,经常重复补全(就是把光标后面已有的代码重复了一遍)或者胡言乱语。社区有开源的效果比较好 prompt 吗?

看了一下 continue 的 template,感觉没什么参考价值。其中 starcoder 等是专门训练的 code 补全模型,不需要特别的 prompt 。

以下是自己写的 prompt:

I am calling you in a code completion plugin for an editor. I need you to complete the code based on the context provided below, only providing the completion content.

# Code Context

Here is the beginning part of the ${language} code (before the cursor):

```

${input.prefix}

```

Here is the suffix part (after the cursor):

```

${input.suffix}

```

Do not explain, just return the code between the prefix part and the suffix part, and do not include the prefix part or the suffix part. Your completion should be concise and accurate. You need to note that brackets, etc. I may have provided them to you in suffix.

980 次点击
所在节点    程序员
2 条回复
vacuitym
41 天前
好像 claude 有个专门写 prompt 的服务
gitignore
41 天前
似乎你也没告诉 llm 要做什么事啊😧让 llm 从的给定的代码上下文推测代码需要实现的功能不靠谱,好歹得让用户描述一下业务逻辑不是,或许从交互上改一下,比如用户写一段注释描述逻辑,再调用 llm

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1066147

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX