Update app.py
Browse files
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}\
|
17 |
return formatted_history
|
18 |
|
19 |
def chat(message, history):
|
20 |
-
system_prompt = """Ti si YugoGPT,
|
21 |
|
22 |
-
|
23 |
-
-
|
24 |
-
-
|
25 |
-
-
|
26 |
-
-
|
27 |
-
-
|
28 |
-
-
|
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
|
38 |
{chat_history}
|
39 |
|
40 |
USER: {message}
|
41 |
-
|
42 |
|
43 |
response = llm(
|
44 |
full_prompt,
|
45 |
max_tokens=2048,
|
46 |
-
temperature=0.
|
47 |
-
top_p=0.
|
48 |
repeat_penalty=1.2,
|
49 |
-
top_k=
|
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 |
-
|
|
|
|
|
|
|
58 |
yield partial_message
|
59 |
|
60 |
demo = gr.ChatInterface(
|
61 |
fn=chat,
|
62 |
-
title="YugoGPT
|
63 |
-
description="
|
64 |
examples=[
|
65 |
-
"
|
66 |
-
"
|
67 |
-
"
|
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 |
)
|
|