import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
peft_model_id = "AhmedSSoliman/Mistral-Instruct-SQL-Generation"
config = PeftConfig.from_pretrained(peft_model_id)
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, trust_remote_code=True, return_dict=True, load_in_4bit=True, device_map='auto')
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
# Load the Lora model
model = PeftModel.from_pretrained(model, peft_model_id)
defpredict_SQL(table, question):
pipe = pipeline('text-generation', model = base_model, tokenizer = tokenizer)
prompt = f"[INST] Write SQL query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: {table} Question: {question} [/INST] Here is the SQL query to answer to the question: {question}: ``` "#prompt = f"### Schema: {table} ### Question: {question} # "
ans = pipe(prompt, max_new_tokens=200)
generatedSql = ans[0]['generated_text'].split('```')[2]
return generatedSql
table = "CREATE TABLE Employee (name VARCHAR, salary INTEGER);"
question = 'Show names for all employees with salary more than the average.'
generatedSql=predict_SQL(table, question)
print(generatedSql)
Runs of AhmedSSoliman Mistral-Instruct-SQL-Generation on huggingface.co
15
Total runs
0
24-hour runs
1
3-day runs
3
7-day runs
9
30-day runs
More Information About Mistral-Instruct-SQL-Generation huggingface.co Model
Mistral-Instruct-SQL-Generation huggingface.co
Mistral-Instruct-SQL-Generation huggingface.co is an AI model on huggingface.co that provides Mistral-Instruct-SQL-Generation's model effect (), which can be used instantly with this AhmedSSoliman Mistral-Instruct-SQL-Generation model. huggingface.co supports a free trial of the Mistral-Instruct-SQL-Generation model, and also provides paid use of the Mistral-Instruct-SQL-Generation. Support call Mistral-Instruct-SQL-Generation model through api, including Node.js, Python, http.
Mistral-Instruct-SQL-Generation huggingface.co is an online trial and call api platform, which integrates Mistral-Instruct-SQL-Generation's modeling effects, including api services, and provides a free online trial of Mistral-Instruct-SQL-Generation, you can try Mistral-Instruct-SQL-Generation online for free by clicking the link below.
AhmedSSoliman Mistral-Instruct-SQL-Generation online free url in huggingface.co:
Mistral-Instruct-SQL-Generation is an open source model from GitHub that offers a free installation service, and any user can find Mistral-Instruct-SQL-Generation on GitHub to install. At the same time, huggingface.co provides the effect of Mistral-Instruct-SQL-Generation install, users can directly use Mistral-Instruct-SQL-Generation installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
Mistral-Instruct-SQL-Generation install url in huggingface.co: