Update chatbot.py
Browse files- chatbot.py +11 -1
chatbot.py
CHANGED
@@ -1,9 +1,14 @@
|
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
from typing import List, Dict
|
3 |
from config import HF_TOKEN, MODEL_NAME, SYSTEM_PROMPT
|
4 |
|
|
|
|
|
|
|
5 |
class Chatbot:
|
6 |
def __init__(self):
|
|
|
7 |
self.client = InferenceClient(api_key=HF_TOKEN)
|
8 |
self.conversation_history = [
|
9 |
{"role": "system", "content": SYSTEM_PROMPT}
|
@@ -13,6 +18,7 @@ class Chatbot:
|
|
13 |
context = "Kontekst z przepisów prawnych:\n\n"
|
14 |
for chunk in relevant_chunks:
|
15 |
context += f"{chunk['text']}\n\n"
|
|
|
16 |
return context
|
17 |
|
18 |
def get_response(self, user_input: str, context: str) -> str:
|
@@ -21,6 +27,7 @@ class Chatbot:
|
|
21 |
]
|
22 |
|
23 |
response = ""
|
|
|
24 |
stream = self.client.chat.completions.create(
|
25 |
model=MODEL_NAME,
|
26 |
messages=messages,
|
@@ -34,12 +41,15 @@ class Chatbot:
|
|
34 |
content = chunk.choices[0].delta.content
|
35 |
if content:
|
36 |
response += content
|
37 |
-
|
38 |
|
39 |
self.conversation_history.append({"role": "user", "content": user_input})
|
40 |
self.conversation_history.append({"role": "assistant", "content": response})
|
|
|
|
|
41 |
|
42 |
def clear_history(self):
|
|
|
43 |
self.conversation_history = [
|
44 |
{"role": "system", "content": SYSTEM_PROMPT}
|
45 |
]
|
|
|
1 |
+
import logging
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from typing import List, Dict
|
4 |
from config import HF_TOKEN, MODEL_NAME, SYSTEM_PROMPT
|
5 |
|
6 |
+
# Konfiguracja logowania
|
7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
8 |
+
|
9 |
class Chatbot:
|
10 |
def __init__(self):
|
11 |
+
logging.info("Inicjalizacja chatbota...")
|
12 |
self.client = InferenceClient(api_key=HF_TOKEN)
|
13 |
self.conversation_history = [
|
14 |
{"role": "system", "content": SYSTEM_PROMPT}
|
|
|
18 |
context = "Kontekst z przepisów prawnych:\n\n"
|
19 |
for chunk in relevant_chunks:
|
20 |
context += f"{chunk['text']}\n\n"
|
21 |
+
logging.info("Wygenerowano kontekst dla chatbota.")
|
22 |
return context
|
23 |
|
24 |
def get_response(self, user_input: str, context: str) -> str:
|
|
|
27 |
]
|
28 |
|
29 |
response = ""
|
30 |
+
logging.info("Generowanie odpowiedzi dla użytkownika: %s", user_input)
|
31 |
stream = self.client.chat.completions.create(
|
32 |
model=MODEL_NAME,
|
33 |
messages=messages,
|
|
|
41 |
content = chunk.choices[0].delta.content
|
42 |
if content:
|
43 |
response += content
|
44 |
+
logging.debug("Otrzymano fragment odpowiedzi: %s", content)
|
45 |
|
46 |
self.conversation_history.append({"role": "user", "content": user_input})
|
47 |
self.conversation_history.append({"role": "assistant", "content": response})
|
48 |
+
logging.info("Zwrócono odpowiedź: %s", response)
|
49 |
+
return response
|
50 |
|
51 |
def clear_history(self):
|
52 |
+
logging.info("Czyszczenie historii konwersacji.")
|
53 |
self.conversation_history = [
|
54 |
{"role": "system", "content": SYSTEM_PROMPT}
|
55 |
]
|