clui commited on
Commit
d1fcdad
·
verified ·
1 Parent(s): 7ef7fc8

Add generation time

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -10,8 +10,7 @@ from llama_index.llms.ollama import Ollama
10
  from llama_index.llms.huggingface import HuggingFaceLLM
11
 
12
  from llama_index.core import Settings
13
- from transformers import BitsAndBytesConfig
14
-
15
 
16
  # Ustawienia strony
17
  st.title("Aplikacja z LlamaIndex")
@@ -29,11 +28,6 @@ index = VectorStoreIndex.from_vector_store(vector_store, embed_model=embed_model
29
  # Load the correct tokenizer and LLM
30
  from transformers import AutoTokenizer
31
 
32
- # quantization_config = BitsAndBytesConfig(
33
- # load_in_4bit=True,
34
- # bnb_4bit_compute_dtype="float16"
35
- # )
36
-
37
  llm = HuggingFaceLLM(
38
  model_name="eryk-mazus/polka-1.1b", # Mały model 1.3B
39
  tokenizer=AutoTokenizer.from_pretrained("eryk-mazus/polka-1.1b"),
@@ -71,14 +65,20 @@ if input := st.chat_input():
71
  if st.session_state.messages[-1]["role"] != "assistant":
72
  with st.chat_message("assistant"):
73
  with st.spinner("Czekaj, odpowiedź jest generowana.."):
 
74
  response = query_engine.query(input)
75
-
 
 
76
  # Zbuduj treść wiadomości z odpowiedzią i score
77
  content = str(response.response) # Upewnij się, że response jest stringiem
78
  if hasattr(response, 'source_nodes') and response.source_nodes: # Sprawdź, czy source_nodes istnieje
79
  # Dodaj score pierwszego węzła (jeśli istnieje)
80
  content += f"\nScore: {response.source_nodes[0].score:.4f}" # Dodaj score
81
 
 
 
 
82
  st.write(content) # Wyświetl całą treść w Streamlit
83
 
84
  message = {"role": "assistant", "content": content} # Zapisz całą treść w wiadomości
 
10
  from llama_index.llms.huggingface import HuggingFaceLLM
11
 
12
  from llama_index.core import Settings
13
+ import time
 
14
 
15
  # Ustawienia strony
16
  st.title("Aplikacja z LlamaIndex")
 
28
  # Load the correct tokenizer and LLM
29
  from transformers import AutoTokenizer
30
 
 
 
 
 
 
31
  llm = HuggingFaceLLM(
32
  model_name="eryk-mazus/polka-1.1b", # Mały model 1.3B
33
  tokenizer=AutoTokenizer.from_pretrained("eryk-mazus/polka-1.1b"),
 
65
  if st.session_state.messages[-1]["role"] != "assistant":
66
  with st.chat_message("assistant"):
67
  with st.spinner("Czekaj, odpowiedź jest generowana.."):
68
+ start_time = time.time() # Start timing
69
  response = query_engine.query(input)
70
+ end_time = time.time() # End timing
71
+ generation_time = end_time - start_time
72
+
73
  # Zbuduj treść wiadomości z odpowiedzią i score
74
  content = str(response.response) # Upewnij się, że response jest stringiem
75
  if hasattr(response, 'source_nodes') and response.source_nodes: # Sprawdź, czy source_nodes istnieje
76
  # Dodaj score pierwszego węzła (jeśli istnieje)
77
  content += f"\nScore: {response.source_nodes[0].score:.4f}" # Dodaj score
78
 
79
+ # Add generation time
80
+ content += f"\nCzas generowania: {generation_time:.2f} sekund"
81
+
82
  st.write(content) # Wyświetl całą treść w Streamlit
83
 
84
  message = {"role": "assistant", "content": content} # Zapisz całą treść w wiadomości