import torchfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom peft import PeftModel base = "microsoft/Phi-3-mini-4k-instruct"tok = AutoTokenizer.from_pretrained(base)model = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.bfloat16, device_map="auto")model = PeftModel.from_pretrained(model, "Bhuvandesai/phi3-text-to-sql-adapter") SCHEMA = """You are a Text-to-SQL generator. Given a database schema and a natural languagequestion, write a valid SQLite query. Output only the raw SQL. Database Schema:Table departments(id, name, manager_id)Table employees(id, name, department_id, salary, hire_date, manager_id)Table products(id, name, category, price)Table sales(id, employee_id, product_id, amount, quantity, sale_date)""" msgs = [{"role": "user", "content": f"{SCHEMA}\n\nQuestion: What is the average salary by department?"}]prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)out = model.generate(**tok(prompt, return_tensors="pt").to(model.device), max_new_tokens=128, do_sample=False)print(tok.decode(out[0], skip_special_tokens=True))