File size: 1,558 Bytes
b106d86
 
 
 
 
 
c1f3724
b106d86
 
 
 
 
 
d6688a2
b106d86
 
d6688a2
 
b106d86
c1f3724
b106d86
 
 
 
 
 
 
 
 
 
 
c1f3724
 
 
d6688a2
c1f3724
d6688a2
c1f3724
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
from llama_index.core import VectorStoreIndex
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
import chromadb
from llama_index.vector_stores.chroma import ChromaVectorStore

st.title("Infections - retriever")

db = chromadb.PersistentClient(path="./zakazenia")
chroma_collection = db.get_or_create_collection("zalacznik_nr12")
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")

# Indeks z vector store
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=embed_model)

# Retriever bez LLM
retriever = index.as_retriever(similarity_top_k=1)

if "messages" not in st.session_state:
    st.session_state.messages = [{"role": "assistant", "content": "Zadaj mi pytanie..."}]

for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.write(message["content"])

if input := st.chat_input():
    st.session_state.messages.append({"role": "user", "content": input})
    with st.chat_message("user"):
        st.write(input)

    if st.session_state.messages[-1]["role"] != "assistant":
        with st.chat_message("assistant"):
            with st.spinner("Czekaj, trwa wyszukiwanie..."):
                
                results = retriever.retrieve(input)
                
                content = "\n\n---\n\n".join([doc.text for doc in results])
                st.write(content)
                st.session_state.messages.append({"role": "assistant", "content": content})