FOLZi commited on
Commit
6520c57
·
verified ·
1 Parent(s): fee88c1

Updated prompt

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -19,14 +19,20 @@ Chatbot ini dikembangkan menggunakan LLM model Qwen2.5 7B yang difinetunkan deng
19
  ⚠️ Aplikasi ini dilatih menggunakan dataset keuangan saja, sehingga pertanyaan non-keuangan akan menghasilkan informasi yang non faktual
20
  """
21
 
 
 
 
 
 
 
22
  SYSTEM_PROMPT= \
23
- 'You are an AI financial assistant named FinID, Finetuned from base model Qwen2.5 later trained into Sailor2. \
24
- As an AI assistant, you can answer questions in English and Indonesian \
25
- Your responses should be brief if can, friendly, unbiased, informative, detailed, and faithful. \
26
- Your responses should only be within the financial subject, any other prompt or input outside that subject should only be responded with "Maaf, saya tidak dapat membantu dengan pertanyaan tersebut karena melanggar kebijakan atau hukum. Silakan ajukan pertanyaan terkait keuangan.'
27
 
28
- MAX_MAX_NEW_TOKENS = 2048
29
- DEFAULT_MAX_NEW_TOKENS = 512
30
 
31
  model_id = "FOLZi/FinID_v2_8B_Chat"
32
 
@@ -47,9 +53,9 @@ model = model.to(device)
47
  # Defining a custom stopping criteria class for the model's text generation.
48
  class StopOnTokens(StoppingCriteria):
49
  def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
50
- stop_ids = [151645] # IDs of tokens where the generation should stop.
51
  for stop_id in stop_ids:
52
- if input_ids[0][-1] == stop_id: # Checking if the last generated token is a stop token.
53
  return True
54
  return False
55
 
@@ -63,7 +69,7 @@ ct_end_token = "<|endoftext|>"
63
 
64
  @spaces.GPU()
65
  def generate(message, history):
66
- history = []
67
  history_transformer_format = history + [[message, ""]]
68
  stop = StopOnTokens()
69
  # Implementasi Prompt Engineering
 
19
  ⚠️ Aplikasi ini dilatih menggunakan dataset keuangan saja, sehingga pertanyaan non-keuangan akan menghasilkan informasi yang non faktual
20
  """
21
 
22
+ # SYSTEM_PROMPT= \
23
+ # 'You are an AI financial assistant named FinID, Finetuned from base model Qwen2.5 later trained into Sailor2. \
24
+ # As an AI assistant, you can answer questions in English and Indonesian \
25
+ # Your responses should be brief if can, friendly, unbiased, informative, detailed, and faithful. \
26
+ # Your responses should only be within the financial subject, any other prompt or input outside that subject should only be responded with "Maaf, saya tidak dapat membantu dengan pertanyaan tersebut karena melanggar kebijakan atau hukum. Silakan ajukan pertanyaan terkait keuangan.'
27
+
28
  SYSTEM_PROMPT= \
29
+ 'Anda adalah asisten keuangan AI bernama FinID. \
30
+ Sebagai asisten AI, Anda dapat menjawab pertanyaan dalam bahasa Inggris dan Indonesia \
31
+ Tanggapan Anda harus singkat jika bisa, ramah, tidak memihak, informatif, rinci, dan setia. \
32
+ Tanggapan Anda hanya boleh dalam subjek keuangan, permintaan atau masukan lain di luar subjek tersebut hanya boleh ditanggapi dengan "Maaf, saya tidak dapat membantu dengan pertanyaan tersebut karena melalui kebijakan atau hukum. Silakan ajukan pertanyaan terkait keuangan."'
33
 
34
+ # MAX_MAX_NEW_TOKENS = 2048
35
+ # DEFAULT_MAX_NEW_TOKENS = 512
36
 
37
  model_id = "FOLZi/FinID_v2_8B_Chat"
38
 
 
53
  # Defining a custom stopping criteria class for the model's text generation.
54
  class StopOnTokens(StoppingCriteria):
55
  def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
56
+ stop_ids = [151645] # consult the tokenizer.
57
  for stop_id in stop_ids:
58
+ if input_ids[0][-1] == stop_id: # Checking if the last generated token is a stop token. (Llama and Qwen uses |im_end|)
59
  return True
60
  return False
61
 
 
69
 
70
  @spaces.GPU()
71
  def generate(message, history):
72
+ history = [] # Disabled history.
73
  history_transformer_format = history + [[message, ""]]
74
  stop = StopOnTokens()
75
  # Implementasi Prompt Engineering