Views
No views yet
1
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "SeanJIE250/chatbot_LAW"
5
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForCausalLM.from_pretrained(
8 model_path,
9 device_map="auto",
10 torch_dtype='auto'
11).eval()
12
13# Prompt content: "hi"
14messages = [
15 {"role": "user", "content": "杀了人在中国判多少年?"}
16]
17
18input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
19outputs = model.generate(input_ids.to('cuda'),max_new_tokens=200)//you can adjust the max_new_tokens as you want.
20response = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=False)
21
22print(response)
23
24messages = [
25 {"role": "user", "content": "How to split the property if I divorced with my handsband?"}
26]
27
28input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
29outputs = model.generate(input_ids.to('cuda'),max_new_tokens=200)//you can adjust the max_new_tokens as you want.
30response = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=False)
31
32print(response)