Skip to content

Commit

Permalink
Merge branch 'main' into docs/add-vizroai-tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
stichbury authored Jan 16, 2025
2 parents 54934ee + b9c7fa3 commit 4acd120
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
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

- Fixed the "Model name could not be retrieved" error when using with AWS Bedrock. ([#953](https://github.com/mckinsey/vizro/pull/953))

<!--
### 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))
-->
2 changes: 1 addition & 1 deletion vizro-ai/docs/pages/user-guides/customize-vizro-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ Consider upgrading to, in the case of OpenAI the `gpt-4o` and `gpt-4` model seri

### Dashboard generation

At the time of writing we find that cheaper models only work for basic dashboards. For a reasonably complex dashboard we recommend the flagship models of the leading vendors, for example `gpt-4o` or `claude-3-5-sonnet-latest`.
At the time of writing we find that cheaper models only work for basic dashboards. For a reasonably complex dashboard we recommend the flagship models of the leading vendors, for example `gpt-4o`.
2 changes: 2 additions & 0 deletions vizro-ai/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"langchain-community",
"langchain_mistralai",
"langchain-anthropic",
"langchain-aws",
"pre-commit"
]
installer = "uv"
Expand All @@ -39,6 +40,7 @@ example = "cd examples; python example.py"
example-create-dashboard = "cd examples; python example_dashboard.py"
example-ui = "cd examples/dashboard_ui; python app.py"
lint = "pre-commit run {args} --all-files"
notebook = "cd examples; jupyter notebook"
pip = '"{env:HATCH_UV}" pip {args}'
prep-release = [
"hatch version release",
Expand Down
14 changes: 0 additions & 14 deletions vizro-ai/src/vizro_ai/_llm_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import suppress
from typing import Optional, Union

from langchain_core.language_models.chat_models import BaseChatModel
Expand Down Expand Up @@ -74,19 +73,6 @@ def _get_llm_model(model: Optional[Union[BaseChatModel, str]] = None) -> BaseCha
)


def _get_model_name(model: BaseChatModel) -> str:
methods = [
lambda: model.model_name, # OpenAI models
lambda: model.model, # Anthropic models
]

for method in methods:
with suppress(AttributeError):
return method()

raise ValueError("Model name could not be retrieved")


if __name__ == "__main__":
llm_chat_openai = _get_llm_model(model="gpt-4o-mini")
print(repr(llm_chat_openai)) # noqa: T201
Expand Down
10 changes: 4 additions & 6 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import HumanMessage

from vizro_ai._llm_models import _get_llm_model, _get_model_name
from vizro_ai._llm_models import _get_llm_model
from vizro_ai.dashboard._graph.dashboard_creation import _create_and_compile_graph
from vizro_ai.dashboard._pydantic_output import _get_pydantic_model # TODO: make general, ie remove from dashboard
from vizro_ai.dashboard.utils import DashboardOutputs, _extract_overall_imports_and_code, _register_data
Expand Down Expand Up @@ -50,12 +50,10 @@ def __init__(self, model: Optional[Union[BaseChatModel, str]] = None):
self.components_instances = {}

# TODO add pending URL link to docs
model_name = _get_model_name(self.model)
logger.info(
f"You have selected {model_name},"
f"Engaging with LLMs (Large Language Models) carries certain risks. "
f"Users are advised to become familiar with these risks to make informed decisions, "
f"and visit this page for detailed information: "
"Engaging with LLMs (Large Language Models) carries certain risks. "
"Users are advised to become familiar with these risks to make informed decisions, "
"and visit this page for detailed information: "
"https://vizro-ai.readthedocs.io/en/latest/pages/explanation/disclaimer/"
)

Expand Down

0 comments on commit 4acd120

Please sign in to comment.