FIM (Fill In the Middle) completion allows users to provide the desired prefix and suffix content, enabling the model to complete the content in between. This is typically used in scenarios such as code completion and filling in missing content in text.
4.2 Using FIM Completion with OpenAI’s completions Interface:
Copy
client = OpenAI( api_key="Your APIKEY", # Obtain from 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): # Base case: if the array length is less than or equal to 1, return the array if len(arr) <= 1: return arr else:""", suffix=f"""# Test the quick_sort functionarr = [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='')