|
11 | 11 | "\n",
|
12 | 12 | "We will also be integrating Qdrant and Few-Shot Learning to boost the model's performance and reduce hallucinations. This could serve as a practical guide for ML practitioners, data scientists, and AI Engineers interested in leveraging the power of OpenAI models for specific use-cases. 🤩\n",
|
13 | 13 | "\n",
|
| 14 | + "Note: This notebook uses the gpt-3.5-turbo model. Fine-tuning on the SQuAD dataset with this setup yields only minimal gains for more advanced models such as gpt-4o or gpt-4.1. As such, this notebook is primarily intended as a guide for fine-tuning workflows and retrieval-augmented generation (RAG) practices\n", |
| 15 | + "\n", |
14 | 16 | "## Why should you read this blog?\n",
|
15 | 17 | "\n",
|
16 | 18 | "You want to learn how to \n",
|
|
559 | 561 | "\n",
|
560 | 562 | " def create_openai_file(self):\n",
|
561 | 563 | " self.file_object = client.files.create(\n",
|
562 |
| - " file=open(self.training_file_path, \"r\"),\n", |
| 564 | + " file=open(self.training_file_path, \"rb\"),\n", |
563 | 565 | " purpose=\"fine-tune\",\n",
|
564 | 566 | " )\n",
|
565 | 567 | "\n",
|
|
571 | 573 | "\n",
|
572 | 574 | " def create_fine_tuning_job(self):\n",
|
573 | 575 | " self.fine_tuning_job = client.fine_tuning.jobs.create(\n",
|
574 |
| - " training_file=self.file_object[\"id\"],\n", |
| 576 | + " training_file=self.file_object.id,\n", |
575 | 577 | " model=self.model_name,\n",
|
576 | 578 | " suffix=self.suffix,\n",
|
577 | 579 | " )\n",
|
578 | 580 | "\n",
|
579 | 581 | " def wait_for_fine_tuning(self, sleep_time=45):\n",
|
580 |
| - " while self.fine_tuning_job.status != 'succeeded':\n", |
| 582 | + " while True:\n", |
| 583 | + " # Retrieve the latest fine-tuning job status\n", |
| 584 | + " self.fine_tuning_job = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id)\n", |
| 585 | + " print(\"Job Status:\", self.fine_tuning_job.status)\n", |
| 586 | + " if self.fine_tuning_job.status in {'succeeded', 'failed', 'cancelled'}:\n", |
| 587 | + " break\n", |
581 | 588 | " time.sleep(sleep_time)\n",
|
582 |
| - " self.fine_tuning_job.refresh()\n", |
583 |
| - " print(\"Job Status: \", self.fine_tuning_job.status)\n", |
584 | 589 | "\n",
|
585 | 590 | " def retrieve_fine_tuned_model(self):\n",
|
586 |
| - " self.model_id = client.fine_tuning.jobs.retrieve(self.fine_tuning_job[\"id\"]).fine_tuned_model\n", |
| 591 | + " self.model_id = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id).fine_tuned_model\n", |
587 | 592 | " return self.model_id\n",
|
588 | 593 | "\n",
|
589 | 594 | " def fine_tune_model(self):\n",
|
|
0 commit comments