cigol123 commited on
Commit
a268e29
·
verified ·
1 Parent(s): 3f4254b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -13,40 +13,37 @@ 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}\nASSISTANT: {assistant_msg}\n"
17
  return formatted_history
18
 
19
  def chat(message, history):
20
- system_prompt = """Ti si YugoGPT, profesionalni AI asistent specijalizovan za precizne i činjenično tačne odgovore.
21
 
22
- KLJUČNE SMERNICE:
23
- - Uvek daj konkretne, precizne i proverljive informacije
24
- - Kada nisi siguran u nešto, jasno to naglasi
25
- - Fokusiraj se na činjenice i pouzdane izvore
26
- - Izbegavaj spekulacije i nepotvrđene informacije
27
- - Koristi jasan, profesionalan i koncizan jezik
28
- - Komuniciraj prvenstveno na srpskom jeziku
29
- - Održavaj doslednost u odgovorima
30
-
31
- Ako pitanje zahteva specifično stručno znanje koje prevazilazi tvoje mogućnosti, jasno to naglasi."""
32
 
33
  chat_history = format_chat_history(history)
34
 
35
  full_prompt = f"""SYSTEM: {system_prompt}
36
 
37
- KONTEKST RAZGOVORA:
38
  {chat_history}
39
 
40
  USER: {message}
41
- ASSISTANT: """
42
 
43
  response = llm(
44
  full_prompt,
45
  max_tokens=2048,
46
- temperature=0.3, # Reduced for more focused responses
47
- top_p=0.85, # Adjusted for better precision
48
  repeat_penalty=1.2,
49
- top_k=40,
50
  stop=["USER:", "\n\n"],
51
  stream=True
52
  )
@@ -54,17 +51,20 @@ ASSISTANT: """
54
  partial_message = ""
55
  for chunk in response:
56
  if chunk and chunk['choices'][0]['text']:
57
- partial_message += chunk['choices'][0]['text']
 
 
 
58
  yield partial_message
59
 
60
  demo = gr.ChatInterface(
61
  fn=chat,
62
- title="YugoGPT Profesionalni Asistent",
63
- description="Profesionalni AI asistent za precizne i pouzdane informacije",
64
  examples=[
65
- "Objasnite principe mašinskog učenja",
66
- "Koje su prednosti i mane različitih tipova baza podataka?",
67
- "Kako funkcioniše TCP/IP protokol?"
68
  ]
69
  )
70
 
@@ -74,4 +74,3 @@ if __name__ == "__main__":
74
  server_port=7860,
75
  share=False
76
  )
77
-
 
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
+ - Fokusiram se na ono što znam i mogu da objasnim
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
 
30
  chat_history = format_chat_history(history)
31
 
32
  full_prompt = f"""SYSTEM: {system_prompt}
33
 
34
+ KONTEKST:
35
  {chat_history}
36
 
37
  USER: {message}
38
+ """
39
 
40
  response = llm(
41
  full_prompt,
42
  max_tokens=2048,
43
+ temperature=0.1,
44
+ top_p=0.1,
45
  repeat_penalty=1.2,
46
+ top_k=20,
47
  stop=["USER:", "\n\n"],
48
  stream=True
49
  )
 
51
  partial_message = ""
52
  for chunk in response:
53
  if chunk and chunk['choices'][0]['text']:
54
+ text = chunk['choices'][0]['text']
55
+ # Remove "ASSISTANT:" if it appears in the response
56
+ text = text.replace("ASSISTANT:", "").strip()
57
+ partial_message += text
58
  yield partial_message
59
 
60
  demo = gr.ChatInterface(
61
  fn=chat,
62
+ title="YugoGPT Stručni Asistent u pokušaju. PAŽNJA!!! Zna da halucinira t.j. da laže!!!",
63
+ description="Precizan izvor informacija i stručne pomoći",
64
  examples=[
65
+ "Koji su osnovni principi relacionih baza podataka?",
66
+ "Objasnite kako funkcioniše HTTP protokol",
67
+ "Koje su glavne komponente računara i njihove funkcije?"
68
  ]
69
  )
70
 
 
74
  server_port=7860,
75
  share=False
76
  )