Skip to content

Commit

Permalink
Showing 62 changed files with 410 additions and 896 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
5 changes: 1 addition & 4 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
@@ -6,10 +6,7 @@

from vizro_ai.chains import ModelConstructor
from vizro_ai.chains._llm_models import LLM_MODELS
from vizro_ai.components import (
GetCodeExplanation,
GetDebugger,
)
from vizro_ai.components import GetCodeExplanation, GetDebugger
from vizro_ai.task_pipeline._pipeline_manager import PipelineManager
from vizro_ai.utils import _safeguard_check

6 changes: 1 addition & 5 deletions vizro-ai/src/vizro_ai/chains/_llm_chain.py
Original file line number Diff line number Diff line change
@@ -53,11 +53,7 @@ def __init__(

def _construct_prompt(self, raw_prompt, partial_vars_map) -> str:
"""Construct the prompt from partial variables input."""
prompt = PromptTemplate(
input_variables=["input"],
template=raw_prompt,
partial_variables=partial_vars_map,
)
prompt = PromptTemplate(input_variables=["input"], template=raw_prompt, partial_variables=partial_vars_map)

vars_set = set(re.findall(r"\{([^}]*)\}", raw_prompt))
vars_set -= {"input"}
5 changes: 1 addition & 4 deletions vizro-ai/src/vizro_ai/components/_base.py
Original file line number Diff line number Diff line change
@@ -57,10 +57,7 @@ def run(self, chain_input: str, *args, **kwargs) -> str:
llm_kwargs_to_use, partial_vars = self._pre_process(*args, **kwargs)

function_call_chain = FunctionCallChain(
llm=self.llm,
raw_prompt=self.prompt,
partial_vars_map=partial_vars,
llm_kwargs=llm_kwargs_to_use,
llm=self.llm, raw_prompt=self.prompt, partial_vars_map=partial_vars, llm_kwargs=llm_kwargs_to_use
)

response = function_call_chain.execute_chain(input_str=chain_input)
5 changes: 1 addition & 4 deletions vizro-ai/src/vizro_ai/components/code_validation.py
Original file line number Diff line number Diff line change
@@ -101,8 +101,5 @@ def run(self, code_snippet: str, chain_input: str = "") -> str:

test = GetDebugger(llm=llm_to_use)

res = test.run(
chain_input=error_msg,
code_snippet=test_code_snippet,
)
res = test.run(chain_input=error_msg, code_snippet=test_code_snippet)
print(res) # noqa: T201
4 changes: 1 addition & 3 deletions vizro-ai/src/vizro_ai/components/custom_chart_wrap.py
Original file line number Diff line number Diff line change
@@ -121,7 +121,5 @@ def _add_capture_code(code_string: str) -> str:

test_custom_chart = GetCustomChart(llm=llm_to_use)

res = test_custom_chart.run(
chain_input=outcome_visual_tool,
)
res = test_custom_chart.run(chain_input=outcome_visual_tool)
print(res) # noqa: T201
7 changes: 1 addition & 6 deletions vizro-ai/src/vizro_ai/task_pipeline/_pipeline_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""Pipeline Manager."""
from vizro_ai.chains._llm_models import LLM_MODELS
from vizro_ai.components import (
GetChartSelection,
GetCustomChart,
GetDataFrameCraft,
GetVisualCode,
)
from vizro_ai.components import GetChartSelection, GetCustomChart, GetDataFrameCraft, GetVisualCode
from vizro_ai.task_pipeline._pipeline import Pipeline


12 changes: 1 addition & 11 deletions vizro-ai/src/vizro_ai/utils/_constants.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
"""File to store all constants."""
WHITELISTED_PACKAGES = [
"pandas",
"numpy",
"vizro",
"plotly",
"datetime",
"matplotlib",
"dash",
"scipy",
"sklearn",
]
WHITELISTED_PACKAGES = ["pandas", "numpy", "vizro", "plotly", "datetime", "matplotlib", "dash", "scipy", "sklearn"]

WHITELISTED_BUILTINS = [
# '__name__',
7 changes: 1 addition & 6 deletions vizro-ai/src/vizro_ai/utils/safeguard.py
Original file line number Diff line number Diff line change
@@ -4,12 +4,7 @@
import re
from typing import Union

from ._constants import (
REDLISTED_CLASS_METHODS,
REDLISTED_DATA_HANDLING,
WHITELISTED_BUILTINS,
WHITELISTED_PACKAGES,
)
from ._constants import REDLISTED_CLASS_METHODS, REDLISTED_DATA_HANDLING, WHITELISTED_BUILTINS, WHITELISTED_PACKAGES


def _check_imports(node: Union[ast.Import, ast.ImportFrom]):
28 changes: 5 additions & 23 deletions vizro-ai/tests/integration/test_example.py
Original file line number Diff line number Diff line change
@@ -11,41 +11,23 @@ def test_chart():
resp = vizro_ai.plot(df, "describe the composition of scatter chart with gdp in continent")
assert_that(
resp["code_string"],
all_of(
contains_string("px.scatter"),
contains_string("x='continent'"),
contains_string("y='gdpPercap'"),
),
all_of(contains_string("px.scatter"), contains_string("x='continent'"), contains_string("y='gdpPercap'")),
)
assert_that(resp["business_insights"], equal_to(None))
assert_that(resp["code_explanation"], equal_to(None))


def test_chart_with_explanation():
vizro_ai._return_all_text = True
resp = vizro_ai.plot(
df,
"describe the composition of gdp in US",
explain=True,
)
resp = vizro_ai.plot(df, "describe the composition of gdp in US", explain=True)
assert_that(
resp["code_string"],
all_of(
contains_string("px.bar"),
contains_string("x='year'"),
contains_string("y='gdpPercap'"),
),
all_of(contains_string("px.bar"), contains_string("x='year'"), contains_string("y='gdpPercap'")),
)
assert_that(
resp["business_insights"],
any_of(
contains_string("GDP in the United States"),
contains_string("GDP in the US"),
),
resp["business_insights"], any_of(contains_string("GDP in the United States"), contains_string("GDP in the US"))
)
assert_that(
resp["code_explanation"],
all_of(
contains_string("https://vizro.readthedocs.io/en/stable/pages/user_guides/custom_charts/"),
),
all_of(contains_string("https://vizro.readthedocs.io/en/stable/pages/user_guides/custom_charts/")),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
11 changes: 3 additions & 8 deletions vizro-core/examples/_dev/app.py
Original file line number Diff line number Diff line change
@@ -34,21 +34,16 @@
y="lifeExp",
size="pop",
color="continent",
),
),
)
)
],
),
],
controls=[vm.Filter(column="continent")],
)


dashboard = vm.Dashboard(
title="Dashboard Title",
pages=[
table_and_container,
],
)
dashboard = vm.Dashboard(title="Dashboard Title", pages=[table_and_container])

if __name__ == "__main__":
Vizro().build(dashboard).run()
23 changes: 7 additions & 16 deletions vizro-core/examples/demo/app.py
Original file line number Diff line number Diff line change
@@ -344,7 +344,7 @@ def create_continent_summary():
However, Africa has shown notable improvements in life expectancy over time, reaching 55 years in
2007. Despite these economic disparities, Africa's population has been steadily increasing,
reflecting its significant potential for development.
""",
"""
),
vm.Card(
text="""
@@ -359,7 +359,7 @@ def create_continent_summary():
maintained similar levels to Asia, reflecting its economic significance. With North America
generally reporting higher life expectancy compared to South America, America remains a region of
opportunities and challenges.
""",
"""
),
vm.Card(
text="""
@@ -373,7 +373,7 @@ def create_continent_summary():
Despite facing various socio-economic challenges, Asia's increasing life expectancy from 46 years
to 70 over the years reflects advancements in healthcare and overall well-being, making it a vital
region driving global progress and development.
""",
"""
),
vm.Card(
text="""
@@ -388,7 +388,7 @@ def create_continent_summary():
quality of life, Europe continues to be a leading force in the global economy. Between 1952 and
2007, Europe's population experienced moderate growth, with a factor of approximately 1.5,
notably lower compared to other continents like Asia and America.
""",
"""
),
vm.Card(
text="""
@@ -401,7 +401,7 @@ def create_continent_summary():
Despite a relatively smaller population size, Oceania's strong economic growth has contributed
to improved living standards and overall well-being of its population.
""",
"""
),
],
)
@@ -475,16 +475,7 @@ def create_benchmark_analysis():
hover_name="country",
),
),
vm.Button(
text="Export data",
actions=[
vm.Action(
function=export_data(
targets=["line_country"],
)
),
],
),
vm.Button(text="Export data", actions=[vm.Action(function=export_data(targets=["line_country"]))]),
],
controls=[
vm.Filter(column="continent", selector=vm.Dropdown(value="Europe", multi=False, title="Select continent")),
@@ -573,7 +564,7 @@ def create_home_page():
),
vm.NavLink(label="Summary", pages=["Continent Summary"], icon="Globe"),
]
),
)
),
)

Loading

0 comments on commit 9bbc6b3

Please sign in to comment.