Update app.py
Browse files
app.py
CHANGED
@@ -13,61 +13,58 @@ llm = Llama(
|
|
13 |
def format_chat_history(history):
|
14 |
formatted_history = ""
|
15 |
for user_msg, assistant_msg in history:
|
16 |
-
formatted_history += f"
|
17 |
return formatted_history
|
18 |
|
19 |
-
def process_chunk(text):
|
20 |
-
# Remove any special tokens
|
21 |
-
text = text.replace("ASSISTANT:", "").replace("A:", "")
|
22 |
-
|
23 |
-
# Add space after each character if there isn't one already
|
24 |
-
processed_text = ""
|
25 |
-
for i, char in enumerate(text):
|
26 |
-
processed_text += char
|
27 |
-
if i < len(text) - 1 and not text[i+1].isspace():
|
28 |
-
processed_text += " "
|
29 |
-
|
30 |
-
return processed_text.strip()
|
31 |
-
|
32 |
def chat(message, history):
|
33 |
-
system_prompt = """Ti si YugoGPT.
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
chat_history = format_chat_history(history)
|
37 |
|
38 |
full_prompt = f"""SYSTEM: {system_prompt}
|
39 |
|
|
|
40 |
{chat_history}
|
41 |
|
42 |
-
|
43 |
-
|
44 |
|
45 |
response = llm(
|
46 |
full_prompt,
|
47 |
max_tokens=2048,
|
48 |
-
temperature=0.
|
49 |
top_p=0.1,
|
50 |
repeat_penalty=1.2,
|
51 |
top_k=20,
|
52 |
-
stop=["
|
53 |
stream=True
|
54 |
)
|
55 |
|
56 |
partial_message = ""
|
57 |
for chunk in response:
|
58 |
if chunk and chunk['choices'][0]['text']:
|
59 |
-
text =
|
|
|
|
|
60 |
partial_message += text
|
61 |
yield partial_message
|
62 |
|
63 |
demo = gr.ChatInterface(
|
64 |
fn=chat,
|
65 |
-
title="YugoGPT",
|
66 |
-
description="
|
67 |
examples=[
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
]
|
72 |
)
|
73 |
|
@@ -78,4 +75,3 @@ if __name__ == "__main__":
|
|
78 |
share=False
|
79 |
)
|
80 |
|
81 |
-
|
|
|
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.7,
|
44 |
top_p=0.1,
|
45 |
repeat_penalty=1.2,
|
46 |
top_k=20,
|
47 |
+
stop=["USER:", "\n\n"],
|
48 |
stream=True
|
49 |
)
|
50 |
|
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",
|
63 |
+
description="Precizan izvor informacija i stručne pomoći. PAŽNJA, ZNA DA LAŽE!!!",
|
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 |
|
|
|
75 |
share=False
|
76 |
)
|
77 |
|
|