rubenroy commited on
Commit
c72c1c2
Β·
verified Β·
1 Parent(s): f196196

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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
- """Generates text responses using Zurich model with streaming."""
 
 
21
 
22
- conversation = []
23
  for user, assistant in chat_history:
24
- conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
25
- conversation.append({"role": "user", "content": message})
 
26
 
27
- input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
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:]