Advice | Program - Code-A2Z/jarvis GitHub Wiki

πŸ—£ Advice - Program

The Advice Program in Jarvis fetches and displays random motivational or humorous advice using a public API. It’s a fun and thoughtful feature that adds personality to the AI assistant.

API Overview

We're using the free Advice Slip JSON API β€” a lightweight service that delivers quick, random advice in JSON format.

⚑ Fast & simple: Perfect for interactive interfaces like Streamlit.

image

Endpoint Used

This api consists of different end-points with explanations. You can explore it here.

Endpoint Response Preview Description
/advice { "slip": { "id": 17, "advice": "Sometimes it's best to ignore other people's advice." }} Returns a random advice slip as a slip object.

A new random advice is returned on every request β€” perfect for dynamic experiences like Jarvis.


Quick Test in Python

You can quickly fetch an advice using this minimal code

import requests

res = requests.get("https://api.adviceslip.com/advice").json()
advice_text = res['slip']['advice']
print(advice_text)

Jarvis Integration: Streamlit App

The following code shows how the Advice Program is implemented in Jarvis using Streamlit

import streamlit as st
import requests

def advice():
  res = requests.get("https://api.adviceslip.com/advice").json()
  advice_text = res['slip']['advice']
  st.markdown(f"#### πŸ’‘ **{advice_text}**")

  if st.button("πŸ”„ Reload Advice"):
    st.session_state['reload_advice'] = not st.session_state.get('reload_advice', False)

image

What’s Happening?

  • st.markdown(...): Displays the advice text with an emoji and markdown styling.
  • st.button(...): Adds a "Reload Advice" button to refresh the quote.
  • st.session_state: A lightweight trick to force Streamlit to re-run the function and pull a new quote without refreshing the entire app.