Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -17,14 +17,16 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
17 |
|
18 |
@spaces.GPU
|
19 |
def generate(message: str, chat_history: list[tuple[str, str]], temperature=0.7, top_p=0.9, top_k=50, max_new_tokens=512, repetition_penalty=1.1) -> Iterator[str]:
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
conversation = []
|
23 |
for user, assistant in chat_history:
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
input_ids = tokenizer.apply_chat_template(
|
28 |
|
29 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
30 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
|
|
17 |
|
18 |
@spaces.GPU
|
19 |
def generate(message: str, chat_history: list[tuple[str, str]], temperature=0.7, top_p=0.9, top_k=50, max_new_tokens=512, repetition_penalty=1.1) -> Iterator[str]:
|
20 |
+
messages = [
|
21 |
+
{"role": "system", "content": "You are a helpful assistant named Zurich, a 7 billion parameter Large Language Model, fine-tuned and trained by Ruben Roy. You have been trained with the GammaCorpus v2 dataset, a structured and filtered multi-turn conversation dataset created by Ruben Roy."}
|
22 |
+
]
|
23 |
|
|
|
24 |
for user, assistant in chat_history:
|
25 |
+
messages.append({"role": "user", "content": user})
|
26 |
+
messages.append({"role": "assistant", "content": assistant})
|
27 |
+
messages.append({"role": "user", "content": message})
|
28 |
|
29 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
30 |
|
31 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
32 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|