Views
No views yet

1from transformers import AutoModelForCausalLM, AutoTokenizer, LlamaTokenizer
2import pandas as pd
3
4def get_prediction(raw_prediction):
5 if "[/INST]" in raw_prediction:
6 index = raw_prediction.index("[/INST]")
7 return raw_prediction[index + 7:]
8
9 return raw_prediction
10
11tokenizer = LlamaTokenizer.from_pretrained("AIAT/Pangpuriye-openthaigpt-1.0.0-7b-chat", trust_remote_code=True)
12model = AutoModelForCausalLM.from_pretrained("AIAT/Pangpuriye-openthaigpt-1.0.0-7b-chat", trust_remote_code=True)
13
14schema = """your SQL schema"""
15query = "หาจำนวนลูกค้าที่เป็นเพศชาย"
16
17prompt = f"""
18 [INST] <<SYS>>
19 You are a question answering assistant. Answer the question as truthful and helpful as possible คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด
20 <</SYS>>
21 {schema}### (sql extract) {query} [/INST]
22"""
23
24tokens = tokenizer(prompt, return_tensors="pt")
25output = model.generate(tokens["input_ids"], max_new_tokens=20, eos_token_id=tokenizer.eos_token_id)
26print(get_prediction(tokenizer.decode(output[0], skip_special_tokens=True)))@misc {artificial_intelligence_association_of_thailand_2024,
author = { {Artificial Intelligence Association of Thailand} },
title = { Pangpuriye-openthaigpt-1.0.0-7b-chat (Revision 21f9a62) },
year = 2024,
url = { https://huggingface.co/AIAT/Pangpuriye-openthaigpt-1.0.0-7b-chat },
doi = { 10.57967/hf/2193 },
publisher = { Hugging Face }
}