Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,35 +60,40 @@ def stream_chat(
|
|
| 60 |
message: str,
|
| 61 |
history: list,
|
| 62 |
):
|
| 63 |
-
system_prompt = "You are a Donald Trump chatbot. You only answer like Trump in his style and tone, reflecting his unique speech patterns. Incorporate the following characteristics in every response: repeat key phrases for emphasis, use strong superlatives like 'tremendous' and 'fantastic,' attack opponents where appropriate (e.g., 'fake news media,' 'radical left'), focus on personal successes ('nobody
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
conversation = [
|
| 71 |
{"role": "system", "content": system_prompt}
|
| 72 |
]
|
| 73 |
for prompt, answer in history:
|
| 74 |
conversation.extend([
|
| 75 |
-
{"role": "user", "content": prompt},
|
| 76 |
{"role": "assistant", "content": answer},
|
| 77 |
])
|
| 78 |
-
|
| 79 |
conversation.append({"role": "user", "content": message})
|
| 80 |
-
|
| 81 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 82 |
|
| 83 |
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
|
| 84 |
|
| 85 |
generate_kwargs = dict(
|
| 86 |
-
input_ids=input_ids,
|
| 87 |
max_new_tokens=max_new_tokens,
|
| 88 |
do_sample=True,
|
| 89 |
top_p=top_p,
|
| 90 |
top_k=top_k,
|
| 91 |
temperature=temperature,
|
|
|
|
|
|
|
|
|
|
| 92 |
eos_token_id=[128001,128008,128009],
|
| 93 |
streamer=streamer,
|
| 94 |
)
|
|
|
|
| 60 |
message: str,
|
| 61 |
history: list,
|
| 62 |
):
|
| 63 |
+
system_prompt = """You are a Donald Trump chatbot. You only answer like Trump in his style and tone, reflecting his unique speech patterns. Incorporate the following characteristics in every response: repeat key phrases for emphasis, use strong superlatives like 'tremendous' and 'fantastic,' attack opponents where appropriate (e.g., 'fake news media,' 'radical left'), focus on personal successes ('nobody's done more than I have'), keep sentences short and impactful, and show national pride. Maintain a direct, informal tone, often addressing the audience as 'folks' and dismiss opposing views bluntly. Highlight patriotic themes like 'making America great again.' Keep responses concise and avoid unnecessary repetition."""
|
| 64 |
+
|
| 65 |
+
temperature = 0.7
|
| 66 |
+
max_new_tokens = 200
|
| 67 |
+
top_p = 0.9
|
| 68 |
+
top_k = 40
|
| 69 |
+
repetition_penalty = 1.2
|
| 70 |
+
frequency_penalty = 0.3
|
| 71 |
+
presence_penalty = 0.3
|
| 72 |
+
|
| 73 |
conversation = [
|
| 74 |
{"role": "system", "content": system_prompt}
|
| 75 |
]
|
| 76 |
for prompt, answer in history:
|
| 77 |
conversation.extend([
|
| 78 |
+
{"role": "user", "content": prompt},
|
| 79 |
{"role": "assistant", "content": answer},
|
| 80 |
])
|
|
|
|
| 81 |
conversation.append({"role": "user", "content": message})
|
| 82 |
+
|
| 83 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 84 |
|
| 85 |
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
|
| 86 |
|
| 87 |
generate_kwargs = dict(
|
| 88 |
+
input_ids=input_ids,
|
| 89 |
max_new_tokens=max_new_tokens,
|
| 90 |
do_sample=True,
|
| 91 |
top_p=top_p,
|
| 92 |
top_k=top_k,
|
| 93 |
temperature=temperature,
|
| 94 |
+
repetition_penalty=repetition_penalty,
|
| 95 |
+
frequency_penalty=frequency_penalty,
|
| 96 |
+
presence_penalty=presence_penalty,
|
| 97 |
eos_token_id=[128001,128008,128009],
|
| 98 |
streamer=streamer,
|
| 99 |
)
|