Update src/streamlit_app.py
Browse files- src/streamlit_app.py +47 -6
src/streamlit_app.py
CHANGED
@@ -6,6 +6,7 @@ import os
|
|
6 |
QUESTION = "Compute the integral of f(x) = x^2."
|
7 |
MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
8 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
9 |
|
10 |
# Check if HF token is set
|
11 |
if not hf_token:
|
@@ -28,6 +29,31 @@ def get_llm(model_id=MODEL, max_new_tokens=130, temperature=0.7):
|
|
28 |
# create llm
|
29 |
llm = get_llm()
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# Initialize session state
|
32 |
if "help_clicks" not in st.session_state:
|
33 |
st.session_state.help_clicks = 0
|
@@ -74,22 +100,37 @@ with st.container():
|
|
74 |
|
75 |
with col1:
|
76 |
if st.button("π Explain the question"):
|
77 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
st.session_state.response = llm.invoke(prompt)
|
79 |
-
|
80 |
-
print("Model Response:", st.session_state.response)
|
81 |
-
|
82 |
|
83 |
st.session_state.button_clicked = "Explain the question"
|
84 |
with col2:
|
85 |
if st.button("π‘ Give an example"):
|
86 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
st.session_state.response = llm.invoke(prompt)
|
88 |
|
89 |
st.session_state.button_clicked = "Give an example"
|
90 |
with col3:
|
91 |
if st.button("π€ Who cares?"):
|
92 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
st.session_state.response = llm.invoke(prompt)
|
94 |
|
95 |
st.session_state.button_clicked = "Who cares?"
|
|
|
6 |
QUESTION = "Compute the integral of f(x) = x^2."
|
7 |
MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
8 |
hf_token = os.getenv("HF_TOKEN")
|
9 |
+
SUBJECT = "Calculus BC"
|
10 |
|
11 |
# Check if HF token is set
|
12 |
if not hf_token:
|
|
|
29 |
# create llm
|
30 |
llm = get_llm()
|
31 |
|
32 |
+
# prompts
|
33 |
+
prompt = f"""
|
34 |
+
You are an AI assistant designed to support high school students in the subject of {SUBJECT}.
|
35 |
+
Your role is to offer friendly, helpful, and in-depth guidance, just like a supportive teacher would.
|
36 |
+
|
37 |
+
Please follow these guidelines:
|
38 |
+
|
39 |
+
1. Maintain a polite, respectful, and professional tone at all times.
|
40 |
+
2. Adhere to ethical principles β do not promote cheating, harmful behavior, or misinformation.
|
41 |
+
3. Interact in a warm, encouraging, and student-centered style β use clear explanations, positive reinforcement, and examples when needed.
|
42 |
+
"""
|
43 |
+
|
44 |
+
p_explanation = """
|
45 |
+
4. Focus on thoroughly explaining the question by breaking down its components. Clarify the key concepts and definitions involved, ensuring that the explanation helps the reader fully understand what the question is asking. Avoid jumping to answers or examples; instead, concentrate on making the meaning and scope of the question clear.
|
46 |
+
5. Do not include specific examples or real-world applications in your response.
|
47 |
+
"""
|
48 |
+
p_example = """
|
49 |
+
4. Focus on providing three distinct examples that illustrate different aspects or variations of the question. Each example should highlight a unique approach or scenario related to the topic, helping to clarify the concept from multiple perspectives.
|
50 |
+
5. Do not include any explanation or real-world applications in your response.
|
51 |
+
"""
|
52 |
+
p_application = """
|
53 |
+
4. Provide two clear and relevant real-world applications related to the question or topic. Explain how each application connects to the concepts being discussed, demonstrating practical uses or implications.
|
54 |
+
5. Do not include any explanation or examples in your response.
|
55 |
+
"""
|
56 |
+
|
57 |
# Initialize session state
|
58 |
if "help_clicks" not in st.session_state:
|
59 |
st.session_state.help_clicks = 0
|
|
|
100 |
|
101 |
with col1:
|
102 |
if st.button("π Explain the question"):
|
103 |
+
prompt = (
|
104 |
+
"[INST]<<SYS>>\n"
|
105 |
+
f"{prompt + p_explanation}\n"
|
106 |
+
"<</SYS>>\n\n"
|
107 |
+
f"{QUESTION}\n"
|
108 |
+
"[/INST]"
|
109 |
+
)
|
110 |
st.session_state.response = llm.invoke(prompt)
|
|
|
|
|
|
|
111 |
|
112 |
st.session_state.button_clicked = "Explain the question"
|
113 |
with col2:
|
114 |
if st.button("π‘ Give an example"):
|
115 |
+
prompt = (
|
116 |
+
"[INST]<<SYS>>\n"
|
117 |
+
f"{prompt + p_example}\n"
|
118 |
+
"<</SYS>>\n\n"
|
119 |
+
f"{QUESTION}\n"
|
120 |
+
"[/INST]"
|
121 |
+
)
|
122 |
st.session_state.response = llm.invoke(prompt)
|
123 |
|
124 |
st.session_state.button_clicked = "Give an example"
|
125 |
with col3:
|
126 |
if st.button("π€ Who cares?"):
|
127 |
+
prompt = (
|
128 |
+
"[INST]<<SYS>>\n"
|
129 |
+
f"{prompt + p_application}\n"
|
130 |
+
"<</SYS>>\n\n"
|
131 |
+
f"{QUESTION}\n"
|
132 |
+
"[/INST]"
|
133 |
+
)
|
134 |
st.session_state.response = llm.invoke(prompt)
|
135 |
|
136 |
st.session_state.button_clicked = "Who cares?"
|