Ctaake commited on
Commit
4b94eca
1 Parent(s): 8ca6a28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -1,25 +1,23 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import random
 
4
  from mySystemPrompt import SYSTEM_PROMPT
5
 
6
  # Model which is used
7
  checkpoint = "mistralai/Mistral-7B-Instruct-v0.2"
8
  # Inference client with the model (And HF-token if needed)
9
  client = InferenceClient(checkpoint)
10
-
11
-
12
 
13
  def format_prompt(message,chatbot,system_prompt):
14
- if system_prompt != "":
15
- input_prompt = f"<s>[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n\n "
16
- else:
17
- input_prompt = f"<s>[INST] "
18
- for interaction in chatbot:
19
- input_prompt = input_prompt + str(interaction[0]) + " [/INST] " + str(interaction[1]) + " </s><s>[INST] "
20
- input_prompt = input_prompt + str(message) + " [/INST] "
21
- return input_prompt
22
-
23
 
24
  def inference(message, history, systemPrompt=SYSTEM_PROMPT, temperature=0.9, maxTokens=512, topP=0.9, repPenalty=1.1):
25
  # Updating the settings for the generation
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import random
4
+ from transformers import AutoTokenizer
5
  from mySystemPrompt import SYSTEM_PROMPT
6
 
7
  # Model which is used
8
  checkpoint = "mistralai/Mistral-7B-Instruct-v0.2"
9
  # Inference client with the model (And HF-token if needed)
10
  client = InferenceClient(checkpoint)
11
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
 
12
 
13
  def format_prompt(message,chatbot,system_prompt):
14
+ messages = [{"role": "system","content": system_prompt}]
15
+ for user_message,bot_message in chatbot:
16
+ messages.append({"role": "user", "content":user_message})
17
+ messages.append({"role": "assistant", "content":bot_message})
18
+ messages.append({"role": "user", "content":message})
19
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
20
+ return tokenized_chat
 
 
21
 
22
  def inference(message, history, systemPrompt=SYSTEM_PROMPT, temperature=0.9, maxTokens=512, topP=0.9, repPenalty=1.1):
23
  # Updating the settings for the generation