langflow-ai / langflow

⛓️ Langflow is a dynamic graph where each node is an executable unit. Its modular and interactive design fosters rapid experimentation and prototyping, pushing hard on the limits of creativity.
http://www.langflow.org
MIT License
17.87k stars 2.68k forks source link

AttributeError: 'str' object has no attribute 'items' #1837

Open artemus717 opened 1 week ago

artemus717 commented 1 week ago

Describe the bug AttributeError: 'str' object has no attribute 'items'

Langflow Version 0.6.17

Browser and Version

Additional context [05/05/24 02:04:32] ERROR 2024-05-05 02:04:32 - ERROR - chat - chat.py:217 'str' object has no attribute 'items' Traceback (most recent call last): File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, | | -> {'name': 'main', 'doc': None, 'package': 'langflow', 'loader': <_frozen_importlib_external.SourceFileL oad... | -> <code object

at 0x7fe1b935f940, file "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 1> -> File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) | -> {'__name__': '__main__', '__doc__': None, '__package__': 'langflow', '__loader__': <_frozen_importlib_external.SourceFileL oad... -> at 0x7fe1b935f940, file "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 1> File "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 381, in main() -> File "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 377, in main app() -> File "/usr/local/lib/python3.10/site-package s/typer/main.py", line 311, in __call__ return get_command(self)(*args, **kwargs) | | | -> {} | | -> () | -> -> File "/usr/local/lib/python3.10/site-package s/click/core.py", line 1157, in __call__ return self.main(*args, **kwargs) | | | -> {} | | -> () | -> -> File "/usr/local/lib/python3.10/site-package s/typer/core.py", line 783, in main return _main( -> File "/usr/local/lib/python3.10/site-package s/typer/core.py", line 225, in _main rv = self.invoke(ctx) | | -> | -> -> File "/usr/local/lib/python3.10/site-package s/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke( sub_ctx)) | | | | -> | | | -> | | -> | -> -> ._process_r esult at 0x7fe1bcba36d0> File "/usr/local/lib/python3.10/site-package s/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) | | | | | -> {'host': '0.0.0.0', 'port': 7860, 'workers': 1, 'timeout': 300, 'components_path': PosixPath('/usr/local/lib/python3.10/si te-... | | | | -> | | | -> | | -> | -> -> File "/usr/local/lib/python3.10/site-package s/click/core.py", line 783, in invoke return __callback(*args, **kwargs) | -> {'host': '0.0.0.0', 'port': 7860, 'workers': 1, 'timeout': 300, 'components_path': PosixPath('/usr/local/lib/python3.10/si te-... -> () File "/usr/local/lib/python3.10/site-package s/typer/main.py", line 683, in wrapper return callback(**use_params) # type: ignore | -> {'host': '0.0.0.0', 'workers': 1, 'timeout': 300, 'port': 7860, 'components_path': PosixPath('/usr/local/lib/python3.10/si te-... -> File "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 216, in run run_on_mac_or_linux(host, port, log_level, options, app) | | | | | -> | | | | -> {'bind': '0.0.0.0:7860', 'workers': 1, 'timeout': 300, 'worker_class': 'uvicorn.workers.UvicornWorker'} | | | -> 'debug' | | -> 7860 | -> '0.0.0.0' -> File "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 221, in run_on_mac_or_linux run_langflow(host, port, log_level, options, app) | | | | | -> | | | | -> {'bind': '0.0.0.0:7860', 'workers': 1, 'timeout': 300, 'worker_class': 'uvicorn.workers.UvicornWorker'} | | | -> 'debug' | | -> 7860 | -> '0.0.0.0' -> File "/usr/local/lib/python3.10/site-package s/langflow/__main__.py", line 312, in run_langflow LangflowApplication(app, options).run() | | -> {'bind': '0.0.0.0:7860', 'workers': 1, 'timeout': 300, 'worker_class': 'uvicorn.workers.UvicornWorker'} | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/app/base.py", line 72, in run Arbiter(self).run() | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/arbiter.py", line 202, in run self.manage_workers() | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/arbiter.py", line 571, in manage_workers self.spawn_workers() | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/arbiter.py", line 642, in spawn_workers self.spawn_worker() | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/arbiter.py", line 609, in spawn_worker worker.init_process() | -> -> File "/usr/local/lib/python3.10/site-package s/uvicorn/workers.py", line 66, in init_process super(UvicornWorker, self).init_process() | -> -> File "/usr/local/lib/python3.10/site-package s/gunicorn/workers/base.py", line 142, in init_process self.run() | -> -> File "/usr/local/lib/python3.10/site-package s/uvicorn/workers.py", line 98, in run return asyncio.run(self._serve()) | | | -> | | -> | -> -> File "/usr/local/lib/python3.10/asyncio/runn ers.py", line 44, in run return loop.run_until_complete(main) | | -> | -> -> File "/usr/local/lib/python3.10/site-package s/starlette/responses.py", line 260, in wrap await func() -> functools.partial( .event_stream at 0x7fe1ce9a1040> -> > File "/usr/local/lib/python3.10/site-package s/langflow/api/v1/chat.py", line 150, in event_stream graph = Graph.from_payload(graph_data) | | -> {'name': 'lill25 test ollama', 'description': 'Unfolding Linguistic Possibilities.', 'data': {'nodes': [{'id': 'BaseLLM-Ns3Qh... | -> )> -> File "/usr/local/lib/python3.10/site-package s/langflow/graph/graph/base.py", line 59, in from_payload return cls(vertices, edges) | | -> [{'source': 'ConversationBufferMemory-16N2x', 'sourceHandle': '{œbaseClassesœ:[œConversationBufferMem oryœ,œBaseMemoryœ,œBaseC... | -> [{'id': 'BaseLLM-Ns3Qh', 'type': 'genericNode', 'position': {'x': -395.7470792565887, 'y': 1170.4865220713727}, 'data': {'typ... -> File "/usr/local/lib/python3.10/site-package s/langflow/graph/graph/base.py", line 35, in __init__ self._build_graph() | -> -> Graph: Nodes: ['BaseLLM-Ns3Qh', 'ConversationalRetrievalChain-kImXj', 'ConversationBufferMemory-16N2x', 'PostgresChatMessageH... File "/usr/local/lib/python3.10/site-package s/langflow/graph/graph/base.py", line 79, in _build_graph self._build_vertex_params() | -> -> Graph: Nodes: ['BaseLLM-Ns3Qh', 'ConversationalRetrievalChain-kImXj', 'ConversationBufferMemory-16N2x', 'PostgresChatMessageH... File "/usr/local/lib/python3.10/site-package s/langflow/graph/graph/base.py", line 87, in _build_vertex_params vertex._build_params() | -> -> Vertex(id=Qdrant-ibD3d, data={'type': 'Qdrant', 'node': {'template': {'documents': {'type': 'Document', 'required': False, 'p... File "/usr/local/lib/python3.10/site-package s/langflow/graph/vertex/base.py", line 184, in _build_params params = {k: v for item in value.get("value", []) for k, v in item.items()} | | | -> | | -> {'type': 'NestedDict', 'required': False, 'placeholder': '', 'list': False, 'show': True, 'multiline': False, 'fileTypes': []... | -> 'search_kwargs' -> {'documents': Vertex(id=CharacterTextSplitter-BFWW2, data={'type': 'CharacterTextSplitter', 'node': {'template': {'documents'... File "/usr/local/lib/python3.10/site-package s/langflow/graph/vertex/base.py", line 184, in params = {k: v for item in value.get("value", []) for k, v in item.items()} | -> 'value' -> 'value' AttributeError: 'str' object has no attribute 'items' ╭─ Traceback (most recent call last) ─╮ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/api/v1/chat.py:150 in │ │ event_stream │ │ │ │ 147 │ │ │ logger.debug("Bui │ │ 148 │ │ │ │ │ 149 │ │ │ # Some error coul │ │ ❱ 150 │ │ │ graph = Graph.fro │ │ 151 │ │ │ │ │ 152 │ │ │ number_of_nodes = │ │ 153 │ │ │ update_build_stat │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/graph/base.py:5 │ │ 9 in from_payload │ │ │ │ 56 │ │ try: │ │ 57 │ │ │ vertices = payloa │ │ 58 │ │ │ edges = payload[" │ │ ❱ 59 │ │ │ return cls(vertic │ │ 60 │ │ except KeyError as ex │ │ 61 │ │ │ logger.exception( │ │ 62 │ │ │ raise ValueError( │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/graph/base.py:3 │ │ 5 in __init__ │ │ │ │ 32 │ │ │ │ 33 │ │ self._vertices = self │ │ 34 │ │ self._edges = self._g │ │ ❱ 35 │ │ self._build_graph() │ │ 36 │ │ │ 37 │ def __getstate__(self): │ │ 38 │ │ return self.raw_graph │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/graph/base.py:7 │ │ 9 in _build_graph │ │ │ │ 76 │ │ │ │ 77 │ │ # This is a hack to m │ │ 78 │ │ # the toolkit vertex │ │ ❱ 79 │ │ self._build_vertex_pa │ │ 80 │ │ # remove invalid vert │ │ 81 │ │ self._validate_vertic │ │ 82 │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/graph/base.py:8 │ │ 7 in _build_vertex_params │ │ │ │ 84 │ │ """Identifies and han │ │ 85 │ │ llm_vertex = None │ │ 86 │ │ for vertex in self.ve │ │ ❱ 87 │ │ │ vertex._build_par │ │ 88 │ │ │ if isinstance(ver │ │ 89 │ │ │ │ llm_vertex = │ │ 90 │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/vertex/base.py: │ │ 184 in _build_params │ │ │ │ 181 │ │ │ │ │ # list of │ │ 182 │ │ │ │ │ # before │ │ 183 │ │ │ │ │ if isinst │ │ ❱ 184 │ │ │ │ │ │ param │ │ in item.items()} │ │ 185 │ │ │ │ │ elif isin │ │ 186 │ │ │ │ │ │ param │ │ 187 │ │ │ │ elif value.ge │ │ │ │ /usr/local/lib/python3.10/site-pack │ │ ages/langflow/graph/vertex/base.py: │ │ 184 in │ │ │ │ 181 │ │ │ │ │ # list of │ │ 182 │ │ │ │ │ # before │ │ 183 │ │ │ │ │ if isinst │ │ ❱ 184 │ │ │ │ │ │ param │ │ in item.items()} │ │ 185 │ │ │ │ │ elif isin │ │ 186 │ │ │ │ │ │ param │ │ 187 │ │ │ │ elif value.ge │ ╰─────────────────────────────────────╯ AttributeError: 'str' object has no attribute 'items' ERROR 2024-05-05 02:04:32 - ERROR - chat - chat.py:218 Error while building the flow: %s
dosubot[bot] commented 1 week ago

The error you're encountering, 'str' object has no attribute 'items', is due to a string being passed to a method or operation that expects a dictionary. This typically happens in the _build_params method within the langflow/graph/vertex/base.py file, where the code attempts to iterate over a dictionary using .items(). If a string is passed instead of a dictionary, Python raises this error because strings do not have an items method.

To resolve this issue, ensure that all data passed into _build_params and similar functions are correctly typed as dictionaries where dictionaries are expected. This may involve validating or converting input data types before they are used in dictionary-specific operations.

This problem is indicative of a type mismatch in the data handling logic of the application. It's crucial to review the data flow and ensure that data structures are correctly managed and transformed. Specifically, look into how data is parsed, loaded, and manipulated across the application to prevent strings from being treated as dictionaries.

In version 0.6.17 of Langflow, there's a known issue that could lead to this problem, particularly in how parameters are handled or converted. Upgrading to a newer version, if available, or reviewing recent changes in the handling of these data structures in the context of your application might provide a direct fix or further insights into resolving the error.

For a more immediate solution, review the logic that leads to the _build_params call and ensure that the data being passed is indeed a dictionary. This might involve debugging the data flow or adding type checks and conversions at critical points in your application.

#### Details **Sources** - [src/backend/base/langflow/graph/vertex/base.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/base/langflow/graph/vertex/base.py) - [src/backend/langflow/graph/vertex/base.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/langflow/graph/vertex/base.py) - [src/frontend/src/components/codeTabsComponent/index.tsx](https://github.com/logspace-ai/langflow/blob/dev/src/frontend/src/components/codeTabsComponent/index.tsx) - [src/backend/langflow/interface/initialize/loading.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/langflow/interface/initialize/loading.py) - [src/backend/base/langflow/schema/schema.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/base/langflow/schema/schema.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.