#best way to fine tune/make a AI response in a specific way while utilising functions
1 messages · Page 1 of 1 (latest)
Hi @fervent vine. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Fine-tuning an AI model to respond in a specific way while utilizing functions involves several steps. Here's a general guide based on the information from OpenAI:
-
Function Definitions: Start by improving your function definitions. Make them clear and distinct from one another. This can help the model to call the correct function (source (https://cookbook.openai.com/examples/fine_tuning_for_function_calling)).
-
Prompt Engineering: Experiment with prompt engineering. A more detailed prompt can help the model call the correct function. If this doesn't improve function calling to a satisfactory level, then you can try fine-tuning (source (https://cookbook.openai.com/examples/fine_tuning_for_function_calling)).
-
Fine-tuning: Fine-tuning a model with function calling examples can allow you to get similarly formatted responses even when the full function definition isn't present and get more accurate and consistent outputs. You can format your examples as shown in the source (https://platform.openai.com/docs/guides/fine-tuning). If you want to use less tokens, some useful techniques are to omit function and parameter descriptions, omit parameters, or omit the function entirely.
-
Creating Fine-tuning Job: Once you have your training data ready, you can create a fine-tuning job. Here's an example of how to do it in Python:
def fine_tune_model(self): self.create_openai_file() self.wait_for_file_processing() self.create_fine_tuning_job() self.wait_for_fine_tuning() return self.retrieve_fine_tuned_model()
fine_tuner = OpenAIFineTuner(
training_file_path="local_cache/100_train.jsonl",
model_name="gpt-3.5-turbo",
suffix="100trn20230907"
)
model_id = fine_tuner.fine_tune_model()
model_id
```
(source (https://cookbook.openai.com/examples/fine-tuned_qa/ft_retrieval_augmented_generation_qdrant#42-fine-tune-openai-model))
- Evaluation: After fine-tuning, evaluate the performance of your model. This can be done by assessing the function calling performance of the model (source (https://cookbook.openai.com/examples/fine_tuning_for_function_calling#overview)).
Remember, fine-tuning requires a careful investment of time and effort. It's recommended to first attempt to get good results with prompt engineering, prompt chaining, and function calling before resorting to fine-tuning (source (https://platform.openai.com/docs/guides/fine-tuning)).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@fervent vine kapa.ai is still learning and improving, please let us know how it did by reacting below
Can i finetune how functions should be called/ @lethal geode
Let me check the knowledge base for you. One moment! :books:
Yes, you can fine-tune how functions should be called. Fine-tuning a model can improve performance at function calling for your use case, especially if you have a large number of functions, or complex, nuanced, or similar functions (source (https://platform.openai.com/docs/guides/function-calling)).
Here are some steps you can follow:
-
Assess Baseline Performance: Evaluate the performance of an out-of-the-box model on your given function. This will give you a baseline to compare with after fine-tuning (source (https://cookbook.openai.com/examples/fine_tuning_for_function_calling#overview)).
-
Generate Synthetic Data: Use a model to create a 'golden' set of prompts and function invocations to use as training data (source (https://cookbook.openai.com/examples/fine_tuning_for_function_calling#overview)).
-
Fine-tuning: Run the fine-tuning job, and evaluate the fine-tuned model. If your goal is to maximize the correctness of the function calling output, it's recommended to use the same function definitions for both training and querying the fine-tuned model (source (https://platform.openai.com/docs/guides/fine-tuning)).
-
Customize Model's Response: Fine-tuning on function calling can also be used to customize the model's response to function outputs. To do this, you can include a function response message and an assistant message interpreting that response (source (https://platform.openai.com/docs/guides/fine-tuning)).
Remember, if you want to use less tokens, some useful techniques are to omit function and parameter descriptions, omit parameters, or omit the function entirely (source (https://platform.openai.com/docs/guides/fine-tuning)).