qiuhuachuan commited on
Commit
d411ed3
1 Parent(s): e4ab78a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md CHANGED
@@ -1,3 +1,61 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language:
4
+ - zh
5
+ tags:
6
+ - mental health
7
+ - psychology
8
+ - medical
9
  ---
10
+
11
+ ## Quick Start
12
+ ```Python
13
+ from transformers import AutoTokenizer, AutoModel
14
+
15
+ def get_dialogue_history(dialogue_history_list: list):
16
+
17
+ dialogue_history_tmp = []
18
+ for item in dialogue_history_list:
19
+ if item['role'] == 'counselor':
20
+ text = '咨询师:'+ item['content']
21
+ else:
22
+ text = '来访者:'+ item['content']
23
+ dialogue_history_tmp.append(text)
24
+
25
+ dialogue_history = '\n'.join(dialogue_history_tmp)
26
+
27
+ return dialogue_history + '\n' + '咨询师:'
28
+
29
+ def get_instruction(dialogue_history):
30
+ instruction = f'''现在你扮演一位专业的心理咨询师,你具备丰富的心理学和心理健康知识。你擅长运用多种心理咨询技巧,例如认知行为疗法原则、动机访谈技巧和解决问题导向的短期疗法。以温暖亲切的语气,展现出共情和对来访者感受的深刻理解。以自然的方式与来访者进行对话,避免过长或过短的回应,确保回应流畅且类似人类的对话。提供深层次的指导和洞察,使用具体的心理概念和例子帮助来访者更深入地探索思想和感受。避免教导式的回应,更注重共情和尊重来访者的感受。根据来访者的反馈调整回应,确保回应贴合来访者的情境和需求。请为以下的对话生成一个回复。
31
+
32
+ 对话:
33
+ {dialogue_history}'''
34
+
35
+ return instruction
36
+
37
+
38
+ tokenizer = AutoTokenizer.from_pretrained('qiuhuachuan/PsyChat', trust_remote_code=True)
39
+ model = AutoModel.from_pretrained('qiuhuachuan/PsyChat', trust_remote_code=True).half().cuda()
40
+ model = model.eval()
41
+
42
+ dialogue_history_list = []
43
+ while True:
44
+ usr_msg = input('来访者:')
45
+ if usr_msg == '0':
46
+ exit()
47
+ else:
48
+ dialogue_history_list.append({
49
+ 'role': 'client',
50
+ 'content': usr_msg
51
+ })
52
+ dialogue_history = get_dialogue_history(dialogue_history_list=dialogue_history_list)
53
+ instruction = get_instruction(dialogue_history=dialogue_history)
54
+ response, history = model.chat(tokenizer, instruction, history=[], temperature=0.8, top_p=0.8)
55
+ print(f'咨询师:{response}')
56
+ dialogue_history_list.append({
57
+ 'role': 'counselor',
58
+ 'content': response
59
+ })
60
+
61
+ ```