cigol123 commited on
Commit
602b78e
·
verified ·
1 Parent(s): 02622b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -25
app.py CHANGED
@@ -13,20 +13,34 @@ llm = Llama(
13
  def format_chat_history(history):
14
  formatted_history = ""
15
  for user_msg, assistant_msg in history:
16
- formatted_history += f"USER: {user_msg}\n{assistant_msg}\n"
17
  return formatted_history
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def chat(message, history):
20
- system_prompt = """Ti si YugoGPT, pouzdan i precizan AI asistent koji daje jasne i korisne informacije.
21
 
22
- PRAVILA RADA:
23
- - Dajem precizne i korisne informacije
24
- - Odgovaram sa sigurnošću o temama koje poznajem
25
- - Koristim jasan i precizan jezik
26
- - Primarno komuniciram na srpskom jeziku
27
  - Odgovaram direktno i pozitivno
28
- - Fokusiram se na rešenja i mogućnosti
29
- - Uvek koristim pravilnu interpunkciju i razmake između reči"""
30
 
31
  chat_history = format_chat_history(history)
32
 
@@ -35,8 +49,8 @@ PRAVILA RADA:
35
  KONTEKST:
36
  {chat_history}
37
 
38
- USER: {message}
39
- """
40
 
41
  response = llm(
42
  full_prompt,
@@ -45,31 +59,25 @@ USER: {message}
45
  top_p=0.1,
46
  repeat_penalty=1.2,
47
  top_k=20,
48
- stop=["USER:", "\n\n"],
49
  stream=True
50
  )
51
 
52
  partial_message = ""
53
  for chunk in response:
54
  if chunk and chunk['choices'][0]['text']:
55
- text = chunk['choices'][0]['text']
56
- # Clean up the text
57
- text = text.replace("ASSISTANT:", "").strip()
58
- # Ensure proper spacing after punctuation
59
- text = text.replace(".", ". ").replace(",", ", ").replace("!", "! ").replace("?", "? ")
60
- # Remove double spaces
61
- text = " ".join(text.split())
62
- partial_message += text
63
- yield partial_message.strip()
64
 
65
  demo = gr.ChatInterface(
66
  fn=chat,
67
  title="YugoGPT Stručni Asistent",
68
- description="Precizan izvor informacija i stručne pomoći, PAŽNJA!!! ZNA DA HALUCINIRA I ZATO PONEKAD LAŽE!!!",
69
  examples=[
70
- "Koji su osnovni principi relacionih baza podataka?",
71
- "Objasnite kako funkcioniše HTTP protokol",
72
- "Koje su glavne komponente računara i njihove funkcije?"
73
  ]
74
  )
75
 
@@ -79,3 +87,4 @@ if __name__ == "__main__":
79
  server_port=7860,
80
  share=False
81
  )
 
 
13
  def format_chat_history(history):
14
  formatted_history = ""
15
  for user_msg, assistant_msg in history:
16
+ formatted_history += f"Pitanje: {user_msg}\nOdgovor: {assistant_msg}\n"
17
  return formatted_history
18
 
19
+ def clean_text(text):
20
+ # Basic cleaning
21
+ text = text.replace("ASSISTANT:", "").strip()
22
+
23
+ # Handle spaces after punctuation
24
+ punctuation_marks = ['.', ',', '!', '?', ':', ';']
25
+ for mark in punctuation_marks:
26
+ text = text.replace(mark, mark + ' ')
27
+
28
+ # Normalize spaces
29
+ words = text.split()
30
+ text = ' '.join(words)
31
+
32
+ return text
33
+
34
  def chat(message, history):
35
+ system_prompt = """Ti si YugoGPT, visoko precizan AI asistent.
36
 
37
+ OSNOVNI PRINCIPI:
38
+ - Dajem konkretne i tačne informacije
39
+ - Odgovaram samo o temama koje dobro poznajem
40
+ - Koristim jasan i precizan srpski jezik
41
+ - Fokusiram se na činjenice
42
  - Odgovaram direktno i pozitivno
43
+ - Izbegavam nagađanja"""
 
44
 
45
  chat_history = format_chat_history(history)
46
 
 
49
  KONTEKST:
50
  {chat_history}
51
 
52
+ Pitanje: {message}
53
+ Odgovor:"""
54
 
55
  response = llm(
56
  full_prompt,
 
59
  top_p=0.1,
60
  repeat_penalty=1.2,
61
  top_k=20,
62
+ stop=["Pitanje:", "\n\n"],
63
  stream=True
64
  )
65
 
66
  partial_message = ""
67
  for chunk in response:
68
  if chunk and chunk['choices'][0]['text']:
69
+ text = clean_text(chunk['choices'][0]['text'])
70
+ partial_message = clean_text(partial_message + text)
71
+ yield partial_message
 
 
 
 
 
 
72
 
73
  demo = gr.ChatInterface(
74
  fn=chat,
75
  title="YugoGPT Stručni Asistent",
76
+ description="Precizan izvor informacija. PAŽNJA!!! ZNA DA LAŽE!!!",
77
  examples=[
78
+ "Objasnite princip rada relacione baze podataka",
79
+ "Kako funkcioniše HTTP protokol?",
80
+ "Opišite osnovne komponente računara"
81
  ]
82
  )
83
 
 
87
  server_port=7860,
88
  share=False
89
  )
90
+