added user name to model
This commit is contained in:
17
chat_qwen.py
17
chat_qwen.py
@@ -1,8 +1,6 @@
|
||||
import torch
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
|
||||
from utils.conversation import save_conversation_json
|
||||
from utils.prompt import prompt
|
||||
|
||||
|
||||
class ChatQwen:
|
||||
@@ -11,7 +9,9 @@ class ChatQwen:
|
||||
default_model_id = 'Qwen/Qwen1.5-1.8B-Chat'
|
||||
# default_model_id = 'Qwen/Qwen1.5-4B-Chat'
|
||||
|
||||
default_instruction = {'role': 'system', 'content': 'Your name is "Laura". You are an AI created by Alice.'}
|
||||
default_instruction = {'role': 'system',
|
||||
'name': 'system',
|
||||
'content': 'Your name is "Laura". You are an AI created by Alice.'}
|
||||
|
||||
def __init__(self, model_id_or_path=default_model_id):
|
||||
# model_id = model_id_or_path if not load_from_disk else os.path.abspath(sys.argv[1])
|
||||
@@ -20,9 +20,9 @@ class ChatQwen:
|
||||
self.model_id_or_path = model_id_or_path
|
||||
self.model = AutoModelForCausalLM.from_pretrained(model_id_or_path, torch_dtype='auto', device_map='auto')
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(model_id_or_path)
|
||||
# print(tokenizer.default_chat_template)
|
||||
# print(type(model))
|
||||
# print(type(tokenizer))
|
||||
# print(self.tokenizer.default_chat_template)
|
||||
# print(type(self.model))
|
||||
# print(type(self.tokenizer))
|
||||
print('Loaded')
|
||||
|
||||
def generate(self, messages):
|
||||
@@ -41,8 +41,9 @@ class ChatQwen:
|
||||
response = self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
||||
|
||||
# add response and save conversation
|
||||
messages.append({'role': 'assistant', 'content': response})
|
||||
self.record_conversation(input_messages, {'role': 'assistant', 'content': response})
|
||||
response_entry = {'role': 'assistant', 'name': 'assistant', 'content': response}
|
||||
messages.append(response_entry)
|
||||
self.record_conversation(input_messages, response_entry)
|
||||
|
||||
return messages
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user