←新闻详情

Ollama Blog更新于 10月14日 12:43

Ollama 博客:如何为 Code Llama 编写提示词

How to prompt Code Llama · Ollama Blog

AI 导读

Meta 发布的 Code Llama 包含 Instruct、代码补全和 Python 三个版本,本文介绍针对不同版本编写提示词的方法。示例使用 7B 参数 4-bit 量化模型,13B 和 34B 版本也已提供,并借助开源项目 Ollama 下载和调用。代码补全版本支持 fill-in-the-middle(infill)特殊提示格式,可在已有代码块之间插入代码;Python 版本额外在 100B Python token 上微调。

正文

当前显示原文,中文全文译文尚未就绪。

September 9, 2023

Two weeks ago the Code Llama model was released by Meta with three variations:

Instruct; Code completion; Python

This guide walks through the different ways to structure prompts for Code Llama for its different variations and features.

Examples below use the 7 billion parameter model with 4-bit quantization, but 13 billion and 34 billion parameter models were made available as well. This guide uses the open-source Ollama project to download and prompt Code Llama, but these prompts will work in other model providers and runtimes too.

Instruct

The instruct model was trained to output human-like answers to questions. This model variation is the easiest to use and will behave closest to ChatGPT, with answer questions including both natural language and code:

Code reviews can often be time consuming for teams. Code Llama can help by providing a second set of eyes on a commit or pull request for simple bugs:

Writing unit tests often requires quite a bit of boilerplate code. Code Llama can help:

The standard code completion model will simply continue to generate subsequent tokens based on the provided prompt. This variation works best if you’re only looking to generate code, such as having the model write a function after seeing the function signature or comment:

Fill-in-the-middle (FIM), or more briefly, infill is a special prompt format supported by the code completion model can complete code between two already written code blocks. This is especially effective for inserting code within an existing function such as below:

With Code Llama, infill prompts require a special format that the model expects.

To use this with existing code, split the code before and after in the example above the into parts: the prefix, and the suffix. For example, for our LCM example above:

Prompt

While results will vary, you should get something like this:

Response

Note: the model may return at the end of the result. This is a special token in the response that represents the end of the response similar to , and

Python

As a thank you to the community and tooling that created the model, the authors of Code Llama included a Python variation which is fine-tuned on 100B additional Python tokens, making it a good model to use when working on machine learning-related tooling, or any other Python code:

Cody has an experimental version that uses Code Llama with infill support; Continue supports Code Llama as a drop-in replacement for GPT-4; Fine-tuned versions of Code Llama from the Phind and WizardLM teams; Open interpreter can use Code Llama to generate functions that are then run locally in the terminal

来源

Ollama Blog