Fine-tuned Llama 3.1 8B model specialized in function calling and JSON mode for visitor request handling
A fine-tuned version of Meta-Llama-3.1-8B-Instruct specialized for function calling with JSON mode output, optimized for visitor request handling scenarios.
This model is based on Meta-Llama-3.1-8B-Instruct and has been fine-tuned using supervised fine-tuning (SFT) to excel at structured function calling and JSON generation. It's particularly suited for applications that need to process visitor requests, extract structured information, and generate API calls or database queries in JSON format.
The model achieves a validation loss of 0.7127 after 2 epochs of training, demonstrating strong convergence on the task.
The model is a PEFT (Parameter-Efficient Fine-Tuning) adapter that requires the base Llama 3.1 8B Instruct model:
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
base_model = "meta-llama/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
base_model,
device_map="auto",
torch_dtype="auto"
)
model = PeftModel.from_pretrained(
model,
"mg11/Meta-Llama-3.1-8B-Instruct-function-calling-json-mode-VisitorRequests"
)
tokenizer = AutoTokenizer.from_pretrained(base_model)
```
Define the functions you want the model to call in your visitor management system:
```python
functions = [
{
"name": "create_visitor_request",
"description": "Create a new visitor request in the system",
"parameters": {
"type": "object",
"properties": {
"visitor_name": {"type": "string", "description": "Name of the visitor"},
"company": {"type": "string", "description": "Company the visitor represents"},
"host_name": {"type": "string", "description": "Name of the employee hosting the visitor"},
"visit_date": {"type": "string", "format": "date", "description": "Date of visit"},
"purpose": {"type": "string", "description": "Purpose of the visit"}
},
"required": ["visitor_name", "host_name", "visit_date"]
}
}
]
```
Structure your prompt to include the function definitions and user request:
```python
prompt = f"""You are a helpful assistant that can call functions to help with visitor management.
Available functions:
{functions}
User request: "Schedule a visit for John Smith from Acme Corp to meet with Sarah Johnson on March 15th for a product demo"
Generate the appropriate function call in JSON format."""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
```
Use the model to generate structured JSON function calls:
```python
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.1, # Low temperature for structured output
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```
Extract the JSON function call from the model's output and execute it:
```python
import json
import re
json_match = re.search(r'\{.*\}', response, re.DOTALL)
if json_match:
function_call = json.loads(json_match.group())
# Execute the function
if function_call["name"] == "create_visitor_request":
result = create_visitor_request(**function_call["parameters"])
print(f"Visitor request created: {result}")
```
**Input:**
```
"Register Alex Chen from TechStart visiting Mike Brown tomorrow for a partnership meeting"
```
**Expected Output:**
```json
{
"name": "create_visitor_request",
"parameters": {
"visitor_name": "Alex Chen",
"company": "TechStart",
"host_name": "Mike Brown",
"visit_date": "2024-03-16",
"purpose": "partnership meeting"
}
}
```
**Input:**
```
"Schedule Dr. Emily Watson from Stanford University to visit our research lab on April 1st. She'll be meeting with Prof. David Lee to discuss the AI collaboration project"
```
**Expected Output:**
```json
{
"name": "create_visitor_request",
"parameters": {
"visitor_name": "Dr. Emily Watson",
"company": "Stanford University",
"host_name": "Prof. David Lee",
"visit_date": "2024-04-01",
"purpose": "discuss the AI collaboration project"
}
}
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/llama-31-function-calling-for-visitor-requests/raw