Updated input prompt.
Browse files- src/streamlit_app.py +3 -18
src/streamlit_app.py
CHANGED
|
@@ -33,17 +33,13 @@ st.title("Math Bot")
|
|
| 33 |
|
| 34 |
# ── Get answers via HuggingFace LLM ───────────────────────────────────────
|
| 35 |
def get_llm_response(user_prompt):
|
| 36 |
-
"""Use HF Inference API to
|
| 37 |
client = InferenceClient(
|
| 38 |
# model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 39 |
# model="mistralai/Mistral-7B-Instruct-v0.2",
|
| 40 |
# model="nvidia/Gemma-4-26B-A4B-NVFP4",
|
| 41 |
# model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
| 42 |
model="meta-llama/Llama-3.3-70B-Instruct",
|
| 43 |
-
# token=st.secrets.get("HF_TOKEN", None),
|
| 44 |
-
# token=st.secrets.get("rainytrek010526001read", None),
|
| 45 |
-
# token=st.secrets.get("API_KEY", None),
|
| 46 |
-
# token=os.getenv("API_KEY"),
|
| 47 |
token=os.getenv("mathbot110526read"),
|
| 48 |
provider="fireworks-ai"
|
| 49 |
)
|
|
@@ -56,16 +52,12 @@ def get_llm_response(user_prompt):
|
|
| 56 |
|
| 57 |
messages = [
|
| 58 |
{"role": "system", "content": system_prompt},
|
| 59 |
-
{"role": "user", "content": f"
|
| 60 |
]
|
| 61 |
|
| 62 |
response = client.chat_completion(messages=messages, max_tokens=256, temperature=0.1)
|
| 63 |
result = response.choices[0].message.content.strip()
|
| 64 |
|
| 65 |
-
## raw = [c.strip() for c in response["choices"][0]["message"]["content"].split("\"") if len(c.strip()) > 1]
|
| 66 |
-
## cities = json.loads(raw)
|
| 67 |
-
# return [c.strip() for c in cities if isinstance(c, str) and c.strip()]
|
| 68 |
-
|
| 69 |
return result
|
| 70 |
|
| 71 |
# ── Show response ────────────────────────────────────────────────
|
|
@@ -97,16 +89,9 @@ if run and user_input.strip():
|
|
| 97 |
with st.spinner("Asking the LLM to help with math…"):
|
| 98 |
try:
|
| 99 |
### get and handle response here
|
| 100 |
-
# reponse = get_llm_response(user_prompt=question_text)
|
| 101 |
response = get_llm_response(user_prompt=user_input)
|
| 102 |
-
|
| 103 |
-
# show_response(question_text, response_text)
|
| 104 |
show_response(user_input, response)
|
| 105 |
|
| 106 |
-
# cities = extract_cities_with_llm(user_input)
|
| 107 |
-
### forecast = fetch_forecast(loc["lat"], loc["lon"], loc["timezone"])
|
| 108 |
-
### render_city_card(loc, forecast)
|
| 109 |
-
|
| 110 |
except Exception as e:
|
| 111 |
st.markdown(f'<div class="error-box">⚠️ LLM error: {e}</div>', unsafe_allow_html=True)
|
| 112 |
|
|
@@ -116,7 +101,7 @@ elif run:
|
|
| 116 |
st.markdown("---")
|
| 117 |
st.markdown(
|
| 118 |
'<div style="font-family: Space Mono, monospace; font-size: 0.65rem; color: #37474f; text-align:center;">'
|
| 119 |
-
'
|
| 120 |
'</div>',
|
| 121 |
unsafe_allow_html=True,
|
| 122 |
)
|
|
|
|
| 33 |
|
| 34 |
# ── Get answers via HuggingFace LLM ───────────────────────────────────────
|
| 35 |
def get_llm_response(user_prompt):
|
| 36 |
+
"""Use HF Inference API to get help with highschool math from a natural-language prompt."""
|
| 37 |
client = InferenceClient(
|
| 38 |
# model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 39 |
# model="mistralai/Mistral-7B-Instruct-v0.2",
|
| 40 |
# model="nvidia/Gemma-4-26B-A4B-NVFP4",
|
| 41 |
# model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
| 42 |
model="meta-llama/Llama-3.3-70B-Instruct",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
token=os.getenv("mathbot110526read"),
|
| 44 |
provider="fireworks-ai"
|
| 45 |
)
|
|
|
|
| 52 |
|
| 53 |
messages = [
|
| 54 |
{"role": "system", "content": system_prompt},
|
| 55 |
+
{"role": "user", "content": f"Provide help with this question:\n\n{user_prompt}, give step-by-step diretives, if possible."},
|
| 56 |
]
|
| 57 |
|
| 58 |
response = client.chat_completion(messages=messages, max_tokens=256, temperature=0.1)
|
| 59 |
result = response.choices[0].message.content.strip()
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return result
|
| 62 |
|
| 63 |
# ── Show response ────────────────────────────────────────────────
|
|
|
|
| 89 |
with st.spinner("Asking the LLM to help with math…"):
|
| 90 |
try:
|
| 91 |
### get and handle response here
|
|
|
|
| 92 |
response = get_llm_response(user_prompt=user_input)
|
|
|
|
|
|
|
| 93 |
show_response(user_input, response)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
except Exception as e:
|
| 96 |
st.markdown(f'<div class="error-box">⚠️ LLM error: {e}</div>', unsafe_allow_html=True)
|
| 97 |
|
|
|
|
| 101 |
st.markdown("---")
|
| 102 |
st.markdown(
|
| 103 |
'<div style="font-family: Space Mono, monospace; font-size: 0.65rem; color: #37474f; text-align:center;">'
|
| 104 |
+
'LLM: Llama-3.3-70B-Instruct via Hugging Face Inference API'
|
| 105 |
'</div>',
|
| 106 |
unsafe_allow_html=True,
|
| 107 |
)
|