Spaces:
Sleeping
Sleeping
def chat(self, user_message, chat_history, socratic_mode=False, service_type='openai'):
Browse files- chatbot.py +11 -9
chatbot.py
CHANGED
@@ -10,7 +10,7 @@ class Chatbot:
|
|
10 |
self.jutor_chat_key = config.get('jutor_chat_key')
|
11 |
self.transcript_text = self.get_transcript_text(config.get('transcript'))
|
12 |
self.key_moments_text = self.get_key_moments_text(config.get('key_moments'))
|
13 |
-
self.
|
14 |
self.ai_client = config.get('ai_client')
|
15 |
self.instructions = config.get('instructions')
|
16 |
|
@@ -39,15 +39,17 @@ class Chatbot:
|
|
39 |
return key_moments_text
|
40 |
|
41 |
|
42 |
-
def chat(self, user_message, chat_history
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
response_text = self.chat_with_service(service_type, system_prompt, messages)
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
|
52 |
def prepare_messages(self, chat_history, user_message):
|
53 |
messages = []
|
|
|
10 |
self.jutor_chat_key = config.get('jutor_chat_key')
|
11 |
self.transcript_text = self.get_transcript_text(config.get('transcript'))
|
12 |
self.key_moments_text = self.get_key_moments_text(config.get('key_moments'))
|
13 |
+
self.ai_model_name = config.get('ai_model_name')
|
14 |
self.ai_client = config.get('ai_client')
|
15 |
self.instructions = config.get('instructions')
|
16 |
|
|
|
39 |
return key_moments_text
|
40 |
|
41 |
|
42 |
+
def chat(self, user_message, chat_history):
|
43 |
+
try:
|
44 |
+
messages = self.prepare_messages(chat_history, user_message)
|
45 |
+
system_prompt = self.instructions
|
46 |
+
service_type = self.ai_model_name
|
47 |
response_text = self.chat_with_service(service_type, system_prompt, messages)
|
48 |
+
except Exception as e:
|
49 |
+
print(f"Error: {e}")
|
50 |
+
response_text = "學習精靈有點累,請稍後再試!"
|
51 |
+
|
52 |
+
return response_text
|
53 |
|
54 |
def prepare_messages(self, chat_history, user_message):
|
55 |
messages = []
|