Skip to content

Comments

Modify FuncchainSettings.llm to str type#33

Open
danielpodrazka wants to merge 1 commit intoshroominic:mainfrom
danielpodrazka:fix_settings
Open

Modify FuncchainSettings.llm to str type#33
danielpodrazka wants to merge 1 commit intoshroominic:mainfrom
danielpodrazka:fix_settings

Conversation

@danielpodrazka
Copy link

The current union of BaseChatModel | str in FuncchainSettings is causing a failure when we try to set LLM in .env because it tries to call a BaseChatModel function on validation, which doesn't exist if the passed value is of str type. Changing it to str fixes the issue although I've noticed that llm is assigned BaseChatModel in some places so changing it to str doesn't fully describe what the variable can be. However, for the sake of the fix and for a working .env reading, I think it's a good trade-off.

The error that this change is fixing:

Traceback (most recent call last):
  File "/home/daniel/pp/venvs/funcchain/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-5eb8bcd049fd>", line 1, in <module>
    from funcchain import settings
  File "/home/daniel/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/pp/funcchain/src/funcchain/__init__.py", line 3, in <module>
    from .backend.settings import settings
  File "/home/daniel/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/pp/funcchain/src/funcchain/backend/settings.py", line 100, in <module>
    settings = FuncchainSettings()
               ^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/pp/venvs/funcchain/lib/python3.11/site-packages/pydantic_settings/main.py", line 167, in __init__
    super().__init__(
  File "/home/daniel/pp/venvs/funcchain/lib/python3.11/site-packages/pydantic/main.py", line 212, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/pp/venvs/funcchain/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 236, in raise_deprecation
    if values.get("callback_manager") is not None:
       ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

To replicate the error:

  1. Add .env file with content: LLM=something
  2. Call from funcchain import settings

The current union of `BaseChatModel | str` is causing a failure when we try to set LLM in `.env` because it tries to call a `BaseChatModel` function on validation, which doesn't exist if the passed value is of `str` type
@danielpodrazka danielpodrazka changed the title Modify FuncchainSettings.llm to str type. Modify FuncchainSettings.llm to str type Jan 29, 2025
@danielpodrazka
Copy link
Author

@shroominic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant