Data Visualization
An llm does not have the innate capability to make dynamic visualizations like charts and KPI cards.
Therefore, I manually make an agent to make appropriate visualization from the final response.
def visualization(llm, answer):
template = """
You are given a statement which may contain one or multiple quantities. You must return 'compare', 'time-series' or 'kpi' depending on whether the statement contains data comparing similar quantities of multiple items, or a time series of data, or a single quantity, as well as the corresponding data and
categories if any, and type of quantity like quantity delivered or inventory.
---
<Instructions>
---
---
<Examples>
---
---
Statement: {answer}
Response:
---
"""
prompt_template = PromptTemplate(input_variables=["answer"], template=template)
return llm.invoke(prompt_template.format(answer=answer)).content
The output contains information of what visualization to use and data to be visualized, so it is passed directly to the frontend where an appropriate component is rendered conditionally.