V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
stimw
V2EX  ›  程序员

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

  •  1
     
  •   stimw · 41 天前 · 981 次点击
    这是一个创建于 41 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    2 条回复    2024-08-19 17:14:32 +08:00
    vacuitym
        1
    vacuitym  
       41 天前
    好像 claude 有个专门写 prompt 的服务
    gitignore
        2
    gitignore  
       41 天前
    似乎你也没告诉 llm 要做什么事啊😧让 llm 从的给定的代码上下文推测代码需要实现的功能不靠谱,好歹得让用户描述一下业务逻辑不是,或许从交互上改一下,比如用户写一段注释描述逻辑,再调用 llm
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2304 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:39 · PVG 23:39 · LAX 08:39 · JFK 11:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.