> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siliconflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Completions 接口

## 1. 使用场景

FIM (Fill In the Middle) 补全中，用户提供希望输入的前后内容，模型来补全中间的内容，典型用于代码补全、文本中间内容补全等场景中。

## 2. 使用方式

### 2.1 在 chat/completions 接口中使用

```json theme={null}
{   
    "model": "model info",
    "messages": "prompt message",
    "params": "params",
    <span style={{ color: 'red' }}>"extra_body": {"prefix":"前缀内容", "suffix":"后缀内容"}</span>
}
```

### 2.2 在 completions 接口中使用

```json theme={null}
{
    "model": "model info",
    "prompt": "前缀内容",
    <span style={{ color: 'red' }}>"suffix": "后缀内容"</span>
}
```

## 3. 支持模型列表

* Deepseek 系列：
  * deepseek-ai/DeepSeek-V3
  * deepseek-ai/DeepSeek-V2.5
  * deepseek-ai/DeepSeek-Coder-V2-Instruct

* Qwen 系列：
  * Qwen/Qwen2.5-Coder-7B-Instruct

<Note>注意：支持的模型列表可能会发生变化，请查阅 [本文档](/features/fim) 了解最新支持的模型列表。</Note>

## 4. 使用示例

下面是基于 OpenAI 的 chat.completions 接口使用前缀续写的例子：

```python theme={null}
client = OpenAI(
    api_key="您的 APIKEY", # 从 https://cloud.siliconflow.com/account/ak 获取
    base_url="https://api.siliconflow.com/v1"
)
 
messages = [
    {"role": "user", "content": "Please write quick sort code"},
]

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V2.5",
    messages=messages,
    extra_body={
            "prefix": f"""
def quick_sort(arr):
    # 基本情况，如果数组长度小于等于 1，则返回数组
    if len(arr) <= 1:
        return arr
    else:
""", 
            "suffix": f"""
# 测试 quick_sort 函数
arr = [3, 6, 8, 10, 1, 2, 1]
sorted_arr = quick_sort(arr)
print("Sorted array:", sorted_arr)
"""
    },
    stream=True,
    max_tokens=4096
)

for chunk in response:
    print(chunk.choices[0].delta.content, end='')
```

```python theme={null}
client = OpenAI(
    api_key="您的 APIKEY", # 从 https://cloud.siliconflow.com/account/ak 获取
    base_url="https://api.siliconflow.com/v1"
)
 
response = client.completions.create(
    model="deepseek-ai/DeepSeek-V2.5",
    prompt=f"""
def quick_sort(arr):
    # 基本情况，如果数组长度小于等于 1，则返回数组
    if len(arr) <= 1:
        return arr
    else:
""",
    suffix=f"""
# 测试 quick_sort 函数
arr = [3, 6, 8, 10, 1, 2, 1]
sorted_arr = quick_sort(arr)
print("Sorted array:", sorted_arr)
""",
    stream=True,
    max_tokens=4096
)

for chunk in response:
    print(chunk.choices[0].text, end='')
```
