not-lain commited on
Commit
ec493d8
β€’
1 Parent(s): fdd8ddb

🌘wπŸŒ–

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -22,6 +22,7 @@ device = torch.device("cuda")
22
  model = model.to(device)
23
  RAG = SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1")
24
  TOP_K = 3
 
25
  # prepare data
26
  # since data is too big we will only select the first 3K lines
27
 
@@ -57,15 +58,14 @@ def prepare_prompt(query, retrieved_examples):
57
  def talk(message, history):
58
  retrieved_examples = search(message)
59
  message, metadata = prepare_prompt(message, retrieved_examples)
60
- resources = "\nRESOURCES:\n"
61
  for title, url in metadata:
62
  resources += f"[{title}]({url}), "
63
  chat = []
64
  for item in history:
65
  chat.append({"role": "user", "content": item[0]})
66
- if item[1] is not None:
67
- cleaned_past = item[1].split("\nRESOURCES:\n")[0]
68
- chat.append({"role": "assistant", "content": cleaned_past})
69
  chat.append({"role": "user", "content": message})
70
  messages = tokenizer.apply_chat_template(
71
  chat, tokenize=False, add_generation_prompt=True
 
22
  model = model.to(device)
23
  RAG = SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1")
24
  TOP_K = 3
25
+ HEADER = "\n# RESOURCES:\n"
26
  # prepare data
27
  # since data is too big we will only select the first 3K lines
28
 
 
58
  def talk(message, history):
59
  retrieved_examples = search(message)
60
  message, metadata = prepare_prompt(message, retrieved_examples)
61
+ resources = HEADER
62
  for title, url in metadata:
63
  resources += f"[{title}]({url}), "
64
  chat = []
65
  for item in history:
66
  chat.append({"role": "user", "content": item[0]})
67
+ cleaned_past = item[1].split(HEADER)[0]
68
+ chat.append({"role": "assistant", "content": cleaned_past})
 
69
  chat.append({"role": "user", "content": message})
70
  messages = tokenizer.apply_chat_template(
71
  chat, tokenize=False, add_generation_prompt=True