代码补全
POST
https://dashscope.aliyuncs.com/compatible-mode/v1/completions
基于前缀进行代码补全
百炼提供了 OpenAI 兼容的 Completions 接口,适合代码补全场景。当前支持 Qwen Coder 部分模型:
qwen2.5-coder-0.5b-instruct、qwen2.5-coder-1.5b-instruct、qwen2.5-coder-3b-instruct、qwen2.5-coder-7b-instruct、qwen2.5-coder-14b-instruct、qwen2.5-coder-32b-instruct、qwen-coder-turbo-0919、qwen-coder-turbo-latest、qwen-coder-turbo
如果您需要使用的代码模型不支持 Completions 接口,可以使用Partial Mode,它也可以基于前缀进行代码补全。
您可以在前缀中传入函数的名称、输入参数、使用说明等信息,Completions 接口将返回生成的代码。
提示词模板为:
<|fim_prefix|>{prefix_content}<|fim_suffix|>
<|fim_prefix|>与<|fim_suffix|>为通义千问代码模型的特殊 Token,其中
fim
是"Fill-in-the-Middle"的缩写,用于指引模型进行文本的补全。
其中{prefix_content}
是您需要传入的前缀信息。
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/completions' \
--header 'Authorization: Bearer {{DASHSCOPE_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "qwen2.5-coder-32b-instruct",
"prompt": "<|fim_prefix|>写一个python的快速排序函数,def quick_sort(arr):<|fim_suffix|>"
}'
响应示例响应示例
{}
请求参数
Header 参数
Authorization
string
必需
示例值:
Bearer {{DASHSCOPE_API_KEY}}
Content-Type
string
必需
示例值:
application/json
Body 参数application/json
返回 响应
修改于 2025-02-28 10:40:50