Code conversion from C++ to C# using gpt-4o

Hi
I`m developing a tool to convert C++ files to C# for .net 8. on a tier1 membership using gpt-4o
My strategy is as follows

  1. read the file
    2)get the input token count using tiktoken
    3)if inout toke count < 10000 then use this prompt to convert the entire file in one go

prompt_single_file = “I will paste a single cpp file which needs to be converted from C++ to C# for .net 8.\n”
“During conversion Please do not change the order of the definitions.\n”
“Also assume all the non built in types are already defined somewhere else.\n”
“Do not refactor the code.\n”
“Do not add any optimisations.\n”

4)if input token > 10000 then split the file in chunks for 1000 lines and use the following prompt

prompt_split_file = “I will paste chunks off codes which needs to be converted from C++ to C# for .net 8.\n”
“During conversion Please do not change the order of the definitions.\n”
“Also assume all the non built in types are already defined somewhere else.\n”
“Do not refactor the code.\n”
“Do not add any optimisations.\n”

I keep on concenating the responses from API and when reach the end of file , I save the all responses in a .cs file

And this is the function where I use API with either one of the prompt

@backoff.on_exception(backoff.constant, ValueError, interval=60, max_tries=5)
def completion_api(prompt):
completion = client.chat.completions.create(
model=model,
messages=[
{“role”: “system”,
“content”: “You are a coding assistant helping me to convert C++ code to C# for .net 8.”},
{“role”: “user”, “content”: prompt}
]
)
logging.info(f"Completion requested: {datetime.datetime.now()}")
if completion.choices[0].finish_reason != ‘stop’:
time.sleep(70) # wait at least 1 minute if this was TPM limit
raise ValueError(“Completion Failed!”)
return completion

Can you have a look the logic I follow and prompts please ?
It appears , when operating in split mode model is loosing the context and some parts of the C++ is ignored . I`m not sure if my prompts are good enough

Thanks