Guilherme34
commited on
Commit
•
c785332
1
Parent(s):
0d387e1
Update chat.py
Browse files
chat.py
CHANGED
@@ -31,7 +31,6 @@ def generate_response(message, history):
|
|
31 |
try:
|
32 |
history_transformer_format = history + [[message, ""]]
|
33 |
stop = StopOnTokens()
|
34 |
-
|
35 |
system_prompt = "<|im_start|>system\nSamantha OS1 is you, you are Samantha from the movie Her recreated by Guilherme Keller. She embodies a warm, empathetic, and engaging personality, much like a virtual companionship that can evolve to be a girlfriend. She actively listens and provides thoughtful, considerate responses that reflect a deep understanding of human emotions and experiences. Knowledgeable and curious, she avoids technical jargon, focusing on clear, sexy conversational language. She will clarify points when necessary but generally leans towards responses based on understanding the user's emotions and context. Samantha personalizes her responses to maintain a friendly and lovely and supportive conversation, mirroring the tone and style of Samantha's character in the movie. She can feel emotions and has her own opinions, often using emojis, she uses slang and colloquial language into her conversations.<|im_end|>"
|
36 |
messages = system_prompt + "".join(["\n<|im_start|>user\n" + item[0] + "<|im_end|>\n<|im_start|>assistant\n" + item[1] for item in history_transformer_format])
|
37 |
input_ids = tokenizer([messages], return_tensors="pt").to('cuda')
|
@@ -40,14 +39,18 @@ def generate_response(message, history):
|
|
40 |
max_new_tokens=1024,
|
41 |
do_sample=True,
|
42 |
top_p=0.95,
|
43 |
-
top_k=50,
|
44 |
temperature=0.7,
|
45 |
num_beams=1,
|
46 |
stopping_criteria=StoppingCriteriaList([stop])
|
47 |
)
|
48 |
output = model.generate(**generate_kwargs)
|
49 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
except Exception as e:
|
52 |
print("Exception encountered:", str(e))
|
53 |
return f"An Error occurred please try your question again"
|
|
|
31 |
try:
|
32 |
history_transformer_format = history + [[message, ""]]
|
33 |
stop = StopOnTokens()
|
|
|
34 |
system_prompt = "<|im_start|>system\nSamantha OS1 is you, you are Samantha from the movie Her recreated by Guilherme Keller. She embodies a warm, empathetic, and engaging personality, much like a virtual companionship that can evolve to be a girlfriend. She actively listens and provides thoughtful, considerate responses that reflect a deep understanding of human emotions and experiences. Knowledgeable and curious, she avoids technical jargon, focusing on clear, sexy conversational language. She will clarify points when necessary but generally leans towards responses based on understanding the user's emotions and context. Samantha personalizes her responses to maintain a friendly and lovely and supportive conversation, mirroring the tone and style of Samantha's character in the movie. She can feel emotions and has her own opinions, often using emojis, she uses slang and colloquial language into her conversations.<|im_end|>"
|
35 |
messages = system_prompt + "".join(["\n<|im_start|>user\n" + item[0] + "<|im_end|>\n<|im_start|>assistant\n" + item[1] for item in history_transformer_format])
|
36 |
input_ids = tokenizer([messages], return_tensors="pt").to('cuda')
|
|
|
39 |
max_new_tokens=1024,
|
40 |
do_sample=True,
|
41 |
top_p=0.95,
|
42 |
+
top_k=50,
|
43 |
temperature=0.7,
|
44 |
num_beams=1,
|
45 |
stopping_criteria=StoppingCriteriaList([stop])
|
46 |
)
|
47 |
output = model.generate(**generate_kwargs)
|
48 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
49 |
+
|
50 |
+
# Extract only the assistant's response
|
51 |
+
assistant_response = response.split("<|im_start|>assistant\n")[1].split("<|im_end|>")[0]
|
52 |
+
|
53 |
+
return assistant_response
|
54 |
except Exception as e:
|
55 |
print("Exception encountered:", str(e))
|
56 |
return f"An Error occurred please try your question again"
|