Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2024
1 parent 8c9128c commit f3e4cab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
13 changes: 6 additions & 7 deletions vizro-ai/docs/pages/user-guides/add-generated-chart-usecase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ This guide explains the different ways in which you can add a chart generated by

!!! example "Vizro-AI chart"
=== "Code for the cell"

```python
import vizro_ai
from vizro_ai import VizroAI
import vizro.plotly.express as px
from dotenv import load_dotenv

load_dotenv()

df = px.data.gapminder()
vizro_ai = VizroAI(model="gpt-4o")

result = vizro_ai.plot(
df,
"""Plot a bubble chart to show the changes in life expectancy
Expand All @@ -30,8 +29,8 @@ This guide explains the different ways in which you can add a chart generated by
Add animation on yearly basis, and do not use facets.
Put the legend on top""",
return_elements=True,
)
)

print(f"Insight:\n{result.chart_insights}\n")
print(f"Code explanation:\n{result.code_explanation}\n\nCode:\n{result.code_vizro}\n")
result.get_fig_object(df).show()
Expand All @@ -40,7 +39,7 @@ This guide explains the different ways in which you can add a chart generated by
=== "Result"
[![VizroAIChart]][vizroaichart]

2. Insert the resulting chart into a dashboard.
1. Insert the resulting chart into a dashboard.

Once you are satisfied with the chart, you can add it to a [Vizro](https://github.com/mckinsey/vizro/tree/main/vizro-core) dashboard.

Expand Down
1 change: 0 additions & 1 deletion vizro-ai/docs/pages/user-guides/customize-vizro-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ vizro_ai = VizroAI(model="<chosen model>")
For the string settings to work, you must supply your API key via environment variables. The relevant variable names to be set are noted in each vendor tab.

=== "OpenAI"

| Environment variable | Name(s) |
| -------------------- | ----------------- |
| API key | `OPENAI_API_KEY` |
Expand Down
18 changes: 8 additions & 10 deletions vizro-ai/docs/pages/user-guides/vizro-ai-langchain-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ chain = llm_with_tools | inject_df | tool_router.map()

Now you can use the chain to generate charts or dashboards based on natural language queries. The chain will generate code that you can use to create visualizations.


!!! example "Generate chart code"

=== "Code"
```python
# Load sample data
Expand All @@ -126,17 +124,17 @@ Now you can use the chain to generate charts or dashboards based on natural lang
plot_response = chain.invoke("Plot GDP per capita for each continent")
print(plot_response[0].content)
```

=== "Vizro-AI Generated Code"
```python
import plotly.graph_objects as go
from vizro.models.types import capture


@capture("graph")
def custom_chart(data_frame):
continent_gdp = data_frame.groupby("continent")["gdpPercap"].mean().reset_index()
fig = go.Figure(
data=[go.Bar(x=continent_gdp["continent"], y=continent_gdp["gdpPercap"])]
)
fig = go.Figure(data=[go.Bar(x=continent_gdp["continent"], y=continent_gdp["gdpPercap"])])
fig.update_layout(
title="GDP per Capita by Continent",
xaxis_title="Continent",
Expand All @@ -146,14 +144,16 @@ Now you can use the chain to generate charts or dashboards based on natural lang
```

!!! example "Generate dashboard code"

=== "Code"
```python
dfs = [px.data.gapminder()]

dashboard_response = chain.invoke("Create a dashboard. This dashboard has a chart showing the correlation between gdpPercap and lifeExp.")
dashboard_response = chain.invoke(
"Create a dashboard. This dashboard has a chart showing the correlation between gdpPercap and lifeExp."
)
print(dashboard_response[0].content)
```

=== "Vizro-AI Generated Code"
```python
############ Imports ##############
Expand All @@ -166,9 +166,7 @@ Now you can use the chain to generate charts or dashboards based on natural lang
@capture("graph")
def gdp_life_exp_graph(data_frame):
fig = go.Figure()
fig.add_trace(
go.Scatter(x=data_frame["gdpPercap"], y=data_frame["lifeExp"], mode="markers")
)
fig.add_trace(go.Scatter(x=data_frame["gdpPercap"], y=data_frame["lifeExp"], mode="markers"))
fig.update_layout(
title="GDP per Capita vs Life Expectancy",
xaxis_title="GDP per Capita",
Expand Down

0 comments on commit f3e4cab

Please sign in to comment.