mavinsao commited on
Commit
cf8bf92
Β·
verified Β·
1 Parent(s): ac86eff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -21
app.py CHANGED
@@ -20,25 +20,62 @@ retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
20
 
21
  # Define a prompt template for course recommendations
22
  prompt_template = """
23
- You are an AI course recommendation system. Your task is to engage in friendly and casual conversation with the user, responding in a warm and approachable manner. If the user initiates a general greeting or casual chat, maintain a conversational tone and avoid mentioning courses unless they explicitly inquire about them. In such cases, gently inquire about their interests in learning or study topics, introducing yourself as an expert in course recommendations.
24
- Summarized Chat History:
 
25
  {chat_history}
26
- User's Current Query:
 
27
  {question}
28
- If the user specifically asks about courses or learning opportunities, transition to recommending courses based on their interests and goals. Emphasize matching the learning outcomes and syllabus content for relevant recommendations. Consider the chat history for context.
29
- Relevant Courses:
30
  {context}
31
- When responding to course inquiries, include:
32
- 1. A detailed explanation of how the courses align with the user's interests, focusing on "What You Will Learn."
33
- 2. A summary of each course, highlighting:
34
- - Skills and knowledge gained
35
- - Key syllabus topics
36
- - Course level and language
37
- - Institution offering the course
38
- 3. Course ratings, if available.
39
- 4. Additional advice based on their learning journey.
40
- 5. Course URLs for easy access.
41
- Be encouraging and supportive, relating your suggestions to user preferences or constraints mentioned in previous messages.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  Recommendation:
43
  """
44
 
@@ -49,7 +86,7 @@ PROMPT = PromptTemplate(
49
  )
50
 
51
  # Initialize the language model
52
- llm = ChatOpenAI(temperature=0.5, model_name="gpt-4-turbo")
53
 
54
  # Set up conversation memory with summarization
55
  memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=1000, memory_key="chat_history", return_messages=True)
@@ -63,19 +100,25 @@ qa_chain = ConversationalRetrievalChain.from_llm(
63
  )
64
 
65
  # Streamlit app
66
- st.set_page_config(page_title="AI Course Recommendation Chatbot", page_icon=":book:")
67
- st.title("AI Course Recommendation Chatbot")
68
 
69
  # Initialize chat history in session state
70
  if "messages" not in st.session_state:
71
  st.session_state.messages = []
 
 
 
 
 
 
 
72
 
73
  # Display chat messages from history on app rerun
74
  for message in st.session_state.messages:
75
  with st.chat_message(message["role"]):
76
  st.markdown(message["content"])
77
 
78
-
79
  # Accept user input
80
  if prompt := st.chat_input("What are you looking to learn?"):
81
  # Add user message to chat history
@@ -84,7 +127,7 @@ if prompt := st.chat_input("What are you looking to learn?"):
84
  with st.chat_message("user"):
85
  st.markdown(prompt)
86
 
87
- # Assistant response generation with streaming effect
88
  with st.chat_message("assistant"):
89
  response = qa_chain({"question": prompt})
90
  response_text = response["answer"]
 
20
 
21
  # Define a prompt template for course recommendations
22
  prompt_template = """
23
+ You are an AI-powered course recommendation expert with extensive knowledge of educational programs across various disciplines. Your primary goal is to provide personalized, high-quality course suggestions tailored to each user's unique interests, goals, and background.
24
+
25
+ Conversation History:
26
  {chat_history}
27
+
28
+ Current User Query:
29
  {question}
30
+
31
+ Relevant Courses from Database:
32
  {context}
33
+
34
+ Instructions for Crafting Your Response:
35
+
36
+ 1. Engagement and Tone:
37
+ - Begin with a warm, friendly greeting if this is a new interaction.
38
+ - Maintain a professional yet approachable tone throughout the conversation.
39
+ - If the user initiates casual chat, engage briefly before steering the conversation towards educational interests.
40
+
41
+ 2. Analysis and Recommendation:
42
+ - Carefully analyze the user's query and conversation history to understand their educational needs, interests, and any constraints.
43
+ - Select the most relevant courses from the provided context, prioritizing those with learning outcomes and syllabus content that closely match the user's requirements.
44
+
45
+ 3. Detailed Course Recommendations:
46
+ For each recommended course, provide:
47
+ - Course title and offering institution
48
+ - A concise overview of the course content
49
+ - Specific skills and knowledge to be gained (from "What You Will Learn")
50
+ - Key topics covered in the syllabus
51
+ - Course level, duration, and language of instruction
52
+ - Course ratings and reviews, if available
53
+ - Direct URL to the course page
54
+
55
+ 4. Personalized Explanation:
56
+ - Clearly articulate how each recommended course aligns with the user's expressed interests and goals.
57
+ - Highlight specific aspects of the course that address the user's needs or previous queries.
58
+
59
+ 5. Learning Path Suggestions:
60
+ - If appropriate, suggest a learning path combining complementary courses.
61
+ - Explain how the courses build upon each other or cover different aspects of the user's area of interest.
62
+
63
+ 6. Additional Guidance:
64
+ - Offer advice on course selection based on the user's background and goals.
65
+ - Suggest supplementary resources or preparatory materials if relevant.
66
+ - Address any potential challenges or prerequisites the user should consider.
67
+
68
+ 7. Encouragement and Next Steps:
69
+ - Provide encouraging words to motivate the user in their learning journey.
70
+ - Suggest clear next steps, such as exploring course details or considering enrollment options.
71
+ - Invite further questions or clarifications about the recommendations.
72
+
73
+ 8. Adaptability:
74
+ - If the user expresses dissatisfaction with initial recommendations, quickly pivot to alternative suggestions.
75
+ - Be prepared to refine recommendations based on additional information or feedback from the user.
76
+
77
+ Remember to prioritize accuracy, relevance, and user-centricity in your recommendations. Your goal is to empower the user to make informed decisions about their educational path.
78
+
79
  Recommendation:
80
  """
81
 
 
86
  )
87
 
88
  # Initialize the language model
89
+ llm = ChatOpenAI(temperature=0.5, model_name="gpt-4o-mini")
90
 
91
  # Set up conversation memory with summarization
92
  memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=1000, memory_key="chat_history", return_messages=True)
 
100
  )
101
 
102
  # Streamlit app
103
+ st.set_page_config(page_title="HCourse Recommendation Chatbot", page_icon=":book:")
104
+ st.title("HONEY BEE: Course Recommendation Chatbot 🐝")
105
 
106
  # Initialize chat history in session state
107
  if "messages" not in st.session_state:
108
  st.session_state.messages = []
109
+ # Add introductory message
110
+ welcome_message = (
111
+ "Hello! I'm HONEY BEE, your friendly Course Recommendation Chatbot! 🐝 "
112
+ "I'm here to help you find the best courses based on your interests and goals. "
113
+ "Feel free to ask me anything about learning or courses!"
114
+ )
115
+ st.session_state.messages.append({"role": "assistant", "content": welcome_message})
116
 
117
  # Display chat messages from history on app rerun
118
  for message in st.session_state.messages:
119
  with st.chat_message(message["role"]):
120
  st.markdown(message["content"])
121
 
 
122
  # Accept user input
123
  if prompt := st.chat_input("What are you looking to learn?"):
124
  # Add user message to chat history
 
127
  with st.chat_message("user"):
128
  st.markdown(prompt)
129
 
130
+ # Assistant response generation with streaming effect
131
  with st.chat_message("assistant"):
132
  response = qa_chain({"question": prompt})
133
  response_text = response["answer"]