Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,9 @@ from chromadb.utils import embedding_functions
|
|
| 21 |
import shutil
|
| 22 |
import os
|
| 23 |
from io import StringIO
|
|
|
|
|
|
|
|
|
|
| 24 |
#
|
| 25 |
|
| 26 |
last = 0
|
|
@@ -46,6 +49,7 @@ frequency_penalty=0.0
|
|
| 46 |
repetition_penalty=1.12
|
| 47 |
presence_penalty=0.15
|
| 48 |
cs = "s0"
|
|
|
|
| 49 |
|
| 50 |
system_sr = "Zoveš se U-Chat AI asistent i pomažeš odgovorima korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem na koji očekuje rešenje. "
|
| 51 |
# " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
|
|
@@ -97,7 +101,8 @@ Settings.embed_model = HuggingFaceEmbedding(model_name=EMBED_MODEL)
|
|
| 97 |
#)
|
| 98 |
vector_store = ChromaVectorStore(chroma_collection=collection)
|
| 99 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
| 100 |
-
chat_engine = index.as_chat_engine(chat_mode="
|
|
|
|
| 101 |
#query_engine = index.as_query_engine(verbose=True)
|
| 102 |
|
| 103 |
def upload_file(filepath):
|
|
@@ -114,6 +119,7 @@ def resetChat():
|
|
| 114 |
return True
|
| 115 |
|
| 116 |
def rag(input_text, history, jezik): # , file):
|
|
|
|
| 117 |
# if (btn):
|
| 118 |
# resetChat()
|
| 119 |
# print(history, input_text)
|
|
@@ -179,9 +185,14 @@ def rag(input_text, history, jezik): # , file):
|
|
| 179 |
system_prompt = system_sr + "Call centar telefon je 12755 za Crnu Goru, 0800 31111 za BIH, 070 700 700 u Sloveniji, 19900 u Srbiji, 095 1000 444 za hrvatske korisnike. Odgovori na jeziku istom kao i u postavljenom pitanju ili problemu korisnika."
|
| 180 |
print("jezik: "+o_jezik)
|
| 181 |
system_prompt = system_prompt + " Sledi pitanje ili problem korisnika, sa kojim dalje komuniciraš: "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# if (o_jezik!='N/A'):
|
| 183 |
# input_text += " - odgovori " + o_jezik + "."
|
| 184 |
# Settings.llm.system_prompt = system_prompt
|
|
|
|
| 185 |
response = chat_engine.chat(str({"role": "user", "content": system_prompt + input_text})).response
|
| 186 |
# response = query_engine.query(input_text)
|
| 187 |
return response
|
|
|
|
| 21 |
import shutil
|
| 22 |
import os
|
| 23 |
from io import StringIO
|
| 24 |
+
from llama_index.core.memory import ChatMemoryBuffer
|
| 25 |
+
|
| 26 |
+
memory = ChatMemoryBuffer.from_defaults(token_limit=1500)
|
| 27 |
#
|
| 28 |
|
| 29 |
last = 0
|
|
|
|
| 49 |
repetition_penalty=1.12
|
| 50 |
presence_penalty=0.15
|
| 51 |
cs = "s0"
|
| 52 |
+
sp_flag = True
|
| 53 |
|
| 54 |
system_sr = "Zoveš se U-Chat AI asistent i pomažeš odgovorima korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem na koji očekuje rešenje. "
|
| 55 |
# " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
|
|
|
|
| 101 |
#)
|
| 102 |
vector_store = ChromaVectorStore(chroma_collection=collection)
|
| 103 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
| 104 |
+
chat_engine = index.as_chat_engine(chat_mode="condense_plus_context", memory=memory, verbose=True)
|
| 105 |
+
# best condense_question context condense_plus_context
|
| 106 |
#query_engine = index.as_query_engine(verbose=True)
|
| 107 |
|
| 108 |
def upload_file(filepath):
|
|
|
|
| 119 |
return True
|
| 120 |
|
| 121 |
def rag(input_text, history, jezik): # , file):
|
| 122 |
+
global sp_flag
|
| 123 |
# if (btn):
|
| 124 |
# resetChat()
|
| 125 |
# print(history, input_text)
|
|
|
|
| 185 |
system_prompt = system_sr + "Call centar telefon je 12755 za Crnu Goru, 0800 31111 za BIH, 070 700 700 u Sloveniji, 19900 u Srbiji, 095 1000 444 za hrvatske korisnike. Odgovori na jeziku istom kao i u postavljenom pitanju ili problemu korisnika."
|
| 186 |
print("jezik: "+o_jezik)
|
| 187 |
system_prompt = system_prompt + " Sledi pitanje ili problem korisnika, sa kojim dalje komuniciraš: "
|
| 188 |
+
if sp_flag:
|
| 189 |
+
sp_flag = False
|
| 190 |
+
else:
|
| 191 |
+
system_prompt = ""
|
| 192 |
# if (o_jezik!='N/A'):
|
| 193 |
# input_text += " - odgovori " + o_jezik + "."
|
| 194 |
# Settings.llm.system_prompt = system_prompt
|
| 195 |
+
|
| 196 |
response = chat_engine.chat(str({"role": "user", "content": system_prompt + input_text})).response
|
| 197 |
# response = query_engine.query(input_text)
|
| 198 |
return response
|