FIM (Fill In the Middle) completion allows users to provide both the preceding and following content, enabling the model to fill in the middle content. This is typically used in scenarios such as code completion and filling in missing text within a document.
4.2 Using FIM completion with the OpenAI completions API:
Copy
client = OpenAI( api_key="Your API KEY", # get from https://dash.horay.ai/account/ak base_url="https://api.horay.ai/v1")response = client.completions.create( model="deepseek-ai/DeepSeek-V2.5", prompt=f"""def quick_sort(arr): # If the array length is less than or equal to 1, return the array. 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='')