Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ import chromadb as chromadb
|
|
18 |
from chromadb.utils import embedding_functions
|
19 |
#
|
20 |
|
|
|
21 |
CHROMA_DATA_PATH = "chroma_data/"
|
22 |
EMBED_MODEL = "BAAI/bge-m3"
|
23 |
# all-MiniLM-L6-v2
|
@@ -32,6 +33,7 @@ max_tokens=3072
|
|
32 |
top_p=0.8
|
33 |
frequency_penalty=0.0
|
34 |
presence_penalty=0.15
|
|
|
35 |
|
36 |
system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. "
|
37 |
# " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
|
@@ -47,6 +49,7 @@ collection = chroma_client.get_or_create_collection(
|
|
47 |
embedding_function=embedding_func,
|
48 |
metadata={"hnsw:space": "cosine"},
|
49 |
)
|
|
|
50 |
|
51 |
#
|
52 |
HF_TOKEN = "wncSKewozDfuZCXCyFbYbAMHgUrfcrumkc"
|
@@ -79,6 +82,16 @@ vector_store = ChromaVectorStore(chroma_collection=collection)
|
|
79 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
80 |
query_engine = index.as_query_engine()
|
81 |
def rag(input_text, file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
return query_engine.query(
|
83 |
input_text
|
84 |
)
|
|
|
18 |
from chromadb.utils import embedding_functions
|
19 |
#
|
20 |
|
21 |
+
last = 0
|
22 |
CHROMA_DATA_PATH = "chroma_data/"
|
23 |
EMBED_MODEL = "BAAI/bge-m3"
|
24 |
# all-MiniLM-L6-v2
|
|
|
33 |
top_p=0.8
|
34 |
frequency_penalty=0.0
|
35 |
presence_penalty=0.15
|
36 |
+
jezik = "srpski"
|
37 |
|
38 |
system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. "
|
39 |
# " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
|
|
|
49 |
embedding_function=embedding_func,
|
50 |
metadata={"hnsw:space": "cosine"},
|
51 |
)
|
52 |
+
last = collection.count()
|
53 |
|
54 |
#
|
55 |
HF_TOKEN = "wncSKewozDfuZCXCyFbYbAMHgUrfcrumkc"
|
|
|
82 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
83 |
query_engine = index.as_query_engine()
|
84 |
def rag(input_text, file):
|
85 |
+
if (file):
|
86 |
+
documents = []
|
87 |
+
for f in file:
|
88 |
+
documents += SimpleDirectoryReader(f).load_data()
|
89 |
+
index = VectorStoreIndex.from_documents(documents)
|
90 |
+
collection.add(
|
91 |
+
documents=documents,
|
92 |
+
ids=[f"id{last+i}" for i in range(len(documents))],
|
93 |
+
metadatas=[{"state": "s0", "next": "s0", "used": False, "source": 'None', "page": -1, "lang": jezik } for i in range(len(documents)) ]
|
94 |
+
)
|
95 |
return query_engine.query(
|
96 |
input_text
|
97 |
)
|