DEV Community

Ahirton Lopes
Ahirton Lopes

Posted on

AI-Powered Automation: Fine-tuning Gemma for Function Calling

Starting a new job always comes with a mix of excitement and challenges. As I joined Accenture as a Data & AI Senior Manager, I experienced firsthand the complexity of onboarding processes—countless forms, account setups, and access provisioning across multiple systems. This got me thinking:

"How can AI-powered automation streamline employee onboarding and make the experience seamless, for both, new hires and HR teams?"

This project explores how fine-tuning Gemma on Vertex AI can enhance its function-calling capabilities, enabling seamless API integration and workflow automation. By leveraging Gemma's ability to interpret function descriptions, we can dynamically trigger external actions such as fetching data, interacting with databases, and automating enterprise tasks.

This project fine-tunes Gemma to enhance its function-calling capabilities, enabling seamless API integration and workflow automation. Using Vertex AI, we optimize Gemma to interpret function descriptions and dynamically trigger external actions such as fetching data, interacting with databases, and automating enterprise tasks.

What is Function Calling?

Function calling allows language models to identify and execute functions based on user inputs. This is useful for automating workflows and integrating AI into real-world applications such as chatbots, virtual assistants, and enterprise process automation.

Automating the Employee Onboarding Process with AI

A practical use case for function calling is automating the onboarding of new employees. With a fine-tuned Gemma model, we can create an automated workflow that performs essential tasks such as:

  1. Registering the new employee in the CRM
  2. Creating accounts and provisioning access
  3. Sending a welcome email
  4. Scheduling initial training sessions

Setting Up the Environment on Vertex AI

Before we start, we need to configure our environment on Vertex AI. Make sure you have the Google Cloud SDK installed and authenticated:

pip install google-cloud-aiplatform

Then, initialize the Vertex AI client:

from google.cloud import aiplatform

aiplatform.init(project="my-project", location="us-central1")
Enter fullscreen mode Exit fullscreen mode

Creating a Dataset for Fine-Tuning

To train the model on executing onboarding functions, we create a JSONL dataset:

{"input": "Register new employee John Doe with email john@email.com and role Software Engineer", "function": "create_employee_record", "arguments": {"name": "John Doe", "email": "john@email.com", "role": "Software Engineer"}}

{"input": "Provision access for Mary Johnson to the ERP system", "function": "provision_access", "arguments": {"employee_name": "Mary Johnson", "system": "ERP"}}

{"input": "Send welcome email to Carla Smith", "function": "send_welcome_email", "arguments": {"recipient": "Carla Smith"}}

{"input": "Schedule security training for Mark Lewis", "function": "schedule_training", "arguments": {"employee": "Mark Lewis", "training": "Security"}}
Enter fullscreen mode Exit fullscreen mode

This dataset is uploaded to Cloud Storage for training:

bucket_name = "my-bucket"
dataset_path = f"gs://{bucket_name}/dataset.jsonl"

# Upload the dataset
aiplatform.gcs_upload_file("dataset.jsonl", dataset_path)
Enter fullscreen mode Exit fullscreen mode

Fine-Tuning Gemma on Vertex AI

Now, we initiate the fine-tuning of the Gemma model using Vertex AI's API:

tuning_job = aiplatform.CustomJob(
    display_name="fine-tuning-gemma",
    script_path="train.py",  # Training script
    container_uri="us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-8:latest",
    args=["--dataset", dataset_path]
)

tuning_job.run()
Enter fullscreen mode Exit fullscreen mode

The train.py script contains the logic for adjusting the model weights, utilizing LoRA (Low-Rank Adaptation) for efficient optimization.

Testing the Fine-Tuned Model

After training, we can deploy the model and test it:

endpoint = aiplatform.Endpoint.create(
    display_name="gemma-function-calling",
    model_name=tuning_job.model_name
)

response = endpoint.predict(instances=[{"input": "Register new employee John Doe with email john@email.com and role Software Engineer"}])
print(response)
Enter fullscreen mode Exit fullscreen mode

The model now automatically returns the correct function to be called with the appropriate arguments.

Conclusion

Fine-tuning Gemma on Vertex AI is an efficient way to enable function calling, allowing intelligent automation of tasks in real applications. In this example, we created an automated workflow for employee onboarding, demonstrating how AI can optimize enterprise processes.

Want to learn more? Drop your questions in the comments.

Let's go! 🚀

Top comments (0)