Views
No views yet

1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from transformers.generation.utils import GenerationConfig
4tokenizer = AutoTokenizer.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ", use_fast=False, trust_remote_code=True)
5model = AutoModelForCausalLM.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ", device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
6model.generation_config = GenerationConfig.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ")
7messages = []
8messages.append({"role": "user", "content": "你的MBTI人格是什么"})
9response = model.chat(tokenizer, messages)
10print(response)
11messages.append({'role': 'assistant', 'content': response})
12messages.append({"role": "user", "content": "和一群人聚会一天回到家,你会是什么感受"})
13response = model.chat(tokenizer, messages)
14print(response)1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from transformers.generation.utils import GenerationConfig
4tokenizer = AutoTokenizer.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ", use_fast=False, trust_remote_code=True)
5model = AutoModelForCausalLM.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ", device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
6model.generation_config = GenerationConfig.from_pretrained("FarReelAILab/Machine_Mindset_zh_ISTJ")
7messages = []
8print("####Enter 'exit' to exit.")
9print("####Enter 'clear' to clear the chat history.")
10while True:
11 user=str(input("User:"))
12 if user.strip()=="exit":
13 break
14 elif user.strip()=="clear":
15 messages=[]
16 continue
17 messages.append({"role": "user", "content": user})
18 response = model.chat(tokenizer, messages)
19 print("Assistant:", response)
20 messages.append({"role": "assistant", "content": str(response)})1git clone https://github.com/hiyouga/LLaMA-Factory.git
2cd LLaMA-Factory
3python ./src/cli_demo.py \
4 --model_name_or_path /path_to_your_local_model \
5 --template baichuan2 #如果您使用的是中文模型,template须指定为baichuan2;如果您使用的是英文模型,template须指定为llama2@article{cui2023machine,
title={Machine Mindset: An MBTI Exploration of Large Language Models},
author={Cui, Jiaxi and Lv, Liuzhenghao and Wen, Jing and Tang, Jing and Tian, YongHong and Yuan, Li},
journal={arXiv preprint arXiv:2312.12999},
year={2023}
}