In the FIM (Fill In the Middle) completion task, users input the prefix and suffix content they want to keep, and the model generates the missing part based on these prompts. This completion method is common in applications such as code auto-completion and text middle generation.
In the chat/completions interface, simply set the model id to the model id on the Model Gallery, which is available in the top right corner of the module card.
from openai import OpenAIclient = OpenAI( api_key="AIHUBMIX_API_KEY",# Replace with the key you generated in AiHubMix base_url="https://aihubmix.com/v1")messages =[{"role":"user","content":"Please write a sum function code"},]response = client.chat.completions.create( model="gpt-4o-mini", messages=messages, extra_body={"prefix":f"""defsum_numbers(numbers):# If the list is empty, return 0ifnot numbers:return0""","suffix":f"""# Run Testnumbers =[1,2,3,4,5]result = sum_numbers(numbers)print("Sum of numbers:", result)"""}, stream=True, max_tokens=4096)for chunk in response:if chunk.choices andlen(chunk.choices)>0and chunk.choices[0].delta.content isnotNone:print(chunk.choices[0].delta.content, end='')