Finetuning GPT 3.5 for Assistants API and Code Interpreter

The Assistants API now supports fine-tuned models.

Has anyone done this yet, and can you share how you formatted your fine-tuning dataset?

I’d ideally like to “teach” the model how to write code for code interpreter, and how to deal with errors (e.g. runtime errors).

1 Like

You can name it something like:

finetuning.jsonl

Here is the default formatting that you would use to train a model:

{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters."}]}

Remember that you need at least ten training examples to create a fine-tuned model.


Interesting project. If you have any problems or questions please feel free to reply to this message or send me a PM.

thanks for the reply ~

i’ve finetuned models before and am aware of the default formatting - but wanted to know if there’s any special format for the code interpreter input and output

1 Like

Ah, thanks for the clarification.

I am not sure, maybe @Diet would know.

I don’t really mess with any of those things because I think they’re a waste of money. @_j or @jr.2509 would be much better authorities on this :laughing:

That said, my understanding is that code interpreter is a tool, and you’d fine tune for that. Here’s an example for function calls: openai-cookbook/examples/Fine_tuning_for_function_calling.ipynb at main · openai/openai-cookbook · GitHub - but I don’t know how applicable that still is. I imagine we’d have to reverse-engineer or extract the code interpreter call (unless that’s visible from the assistant api) and go from there.

I’d just tweak the cot instruction to ensure the model can find the correct solution on its own :thinking:

1 Like

So I don’t have a complete answer here but in addition to the link from @Diet, here’s a link to specific formatting requirements for fine-tuning for function calling:

https://platform.openai.com/docs/guides/fine-tuning/fine-tuning-examples

One point specifically is that OpenAI writes:

function_call and functions have been deprecated in favor of tools , however, the fine-tuning API still requires the legacy format at this time.

Given that legacy formatting is required and given that code interpreter is a tool type and not a function, it sounds to me that fine-tuning for code interpreter is currently not supported.

All eyes now on @_j to see if there is anything we are missing here :slight_smile:

2 Likes

You have a correct observation.

The hierarchy one might see upon system message dump:

# Tools

## Python

## Functions

where Python emits raw code to the tool recipient without any JSON.

1 Like

thanks for the suggestions! i’ll try this out soon :slight_smile: