Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
artemus717 opened this issue May 5, 2024 · 1 comment
Open

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

artemus717 opened this issue May 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@artemus717
Copy link

artemus717 commented May 5, 2024

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

Langflow Version
0.6.17

Browser and Version

  • Browser Edge
  • Version 124.0.2478.80 (Official build) (x86_64)

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>
-> <function _run_code at
0x7fe1e95288b0>
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...
-> <code object 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()
-> <function main at
0x7fe1bcba1240>
File
"/usr/local/lib/python3.10/site-package
s/langflow/main.py", line 377, in
main
app()
-> <typer.main.Typer object at
0x7fe1bcc60430>
File
"/usr/local/lib/python3.10/site-package
s/typer/main.py", line 311, in call
return get_command(self)(*args,
**kwargs)
| | |
-> {}
| | -> ()
| ->
<typer.main.Typer object at
0x7fe1bcc60430>
-> <function get_command at
0x7fe1b90d6b00>
File
"/usr/local/lib/python3.10/site-package
s/click/core.py", line 1157, in
call
return self.main(*args, **kwargs)
| | | -> {}
| | -> ()
| -> <function
TyperGroup.main at 0x7fe1b90d6680>
->
File
"/usr/local/lib/python3.10/site-package
s/typer/core.py", line 783, in main
return _main(
-> <function _main at
0x7fe1b90d5900>
File
"/usr/local/lib/python3.10/site-package
s/typer/core.py", line 225, in _main
rv = self.invoke(ctx)
| | ->
<click.core.Context object at
0x7fe1bcc8b7f0>
| -> <function
MultiCommand.invoke at 0x7fe1b91e5120>
->
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))
| | |
| -> <click.core.Context object at
0x7fe1bcb777f0>
| | |
-> <function Command.invoke at
0x7fe1b91e4c10>
| | ->

| ->
<click.core.Context object at
0x7fe1bcb777f0>
-> <function
MultiCommand.invoke.._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-...
| | | |
-> <click.core.Context object at
0x7fe1bcb777f0>
| | | -> <function
run at 0x7fe1bcba3400>
| | ->
| -> <function
Context.invoke at 0x7fe1b91cf910>
-> <click.core.Context
object at 0x7fe1bcb777f0>
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-...
-> <function run at
0x7fe1bcba0e50>
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)
| | | |
| ->
<fastapi.applications.FastAPI object at
0x7fe1a932ca90>
| | | |
-> {'bind': '0.0.0.0:7860', 'workers':
1, 'timeout': 300, 'worker_class':
'uvicorn.workers.UvicornWorker'}
| | | ->
'debug'
| | -> 7860
| -> '0.0.0.0'
-> <function run_on_mac_or_linux at
0x7fe1bcba0d30>
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)
| | | |
| ->
<fastapi.applications.FastAPI object at
0x7fe1a932ca90>
| | | |
-> {'bind': '0.0.0.0:7860', 'workers':
1, 'timeout': 300, 'worker_class':
'uvicorn.workers.UvicornWorker'}
| | | -> 'debug'
| | -> 7860
| -> '0.0.0.0'
-> <function run_langflow at
0x7fe1bcba11b0>
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'}
| ->
<fastapi.applications.FastAPI object at
0x7fe1a932ca90>
-> <class
'langflow.server.LangflowApplication'>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/app/base.py", line 72, in
run
Arbiter(self).run()
| ->
<langflow.server.LangflowApplication
object at 0x7fe1a8a9ebf0>
-> <class
'gunicorn.arbiter.Arbiter'>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/arbiter.py", line 202, in
run
self.manage_workers()
| -> <function
Arbiter.manage_workers at
0x7fe1a8ac6e60>
-> <gunicorn.arbiter.Arbiter object
at 0x7fe1a89e3fd0>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/arbiter.py", line 571, in
manage_workers
self.spawn_workers()
| -> <function
Arbiter.spawn_workers at
0x7fe1a8ac6f80>
-> <gunicorn.arbiter.Arbiter object
at 0x7fe1a89e3fd0>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/arbiter.py", line 642, in
spawn_workers
self.spawn_worker()
| -> <function
Arbiter.spawn_worker at 0x7fe1a8ac6ef0>
-> <gunicorn.arbiter.Arbiter object
at 0x7fe1a89e3fd0>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/arbiter.py", line 609, in
spawn_worker
worker.init_process()
| -> <function
UvicornWorker.init_process at
0x7fe1a8829a20>
-> <uvicorn.workers.UvicornWorker
object at 0x7fe1bcb46890>
File
"/usr/local/lib/python3.10/site-package
s/uvicorn/workers.py", line 66, in
init_process
super(UvicornWorker,
self).init_process()
| ->
<uvicorn.workers.UvicornWorker object
at 0x7fe1bcb46890>
-> <class
'uvicorn.workers.UvicornWorker'>
File
"/usr/local/lib/python3.10/site-package
s/gunicorn/workers/base.py", line 142,
in init_process
self.run()
| -> <function UvicornWorker.run
at 0x7fe1a8829c60>
-> <uvicorn.workers.UvicornWorker
object at 0x7fe1bcb46890>
File
"/usr/local/lib/python3.10/site-package
s/uvicorn/workers.py", line 98, in run
return asyncio.run(self._serve())
| | | ->
<function UvicornWorker._serve at
0x7fe1a8829bd0>
| | ->
<uvicorn.workers.UvicornWorker object
at 0x7fe1bcb46890>
| -> <function run at
0x7fe1e8d6e4d0>
-> <module 'asyncio' from
'/usr/local/lib/python3.10/asyncio/in
it
.py'>
File
"/usr/local/lib/python3.10/asyncio/runn
ers.py", line 44, in run
return
loop.run_until_complete(main)
| | ->
<coroutine object UvicornWorker._serve
at 0x7fe1a8835540>
| -> <method
'run_until_complete' of
'uvloop.loop.Loop' objects>
-> <uvloop.Loop running=True
closed=False debug=False>
File
"/usr/local/lib/python3.10/site-package
s/starlette/responses.py", line 260, in
wrap
await func()
-> functools.partial(<bound
method
StreamingResponse.stream_response of
<starlette.responses.StreamingResponse
object at 0x7fe1c...
File
"/usr/local/lib/python3.10/site-package
s/starlette/responses.py", line 249, in
stream_response
async for chunk in
self.body_iterator:
| ->
<async_generator object
stream_build..event_stream at
0x7fe1ce9a1040>
->
<starlette.responses.StreamingResponse
object at 0x7fe1ce87a0b0>
> 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...
| ->
<classmethod(<function
Graph.from_payload at 0x7fe1b9358c10>)>
-> <class
'langflow.graph.graph.base.Graph'>
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...
-> <class
'langflow.graph.graph.base.Graph'>
File
"/usr/local/lib/python3.10/site-package
s/langflow/graph/graph/base.py", line
35, in init
self._build_graph()
| -> <function
Graph._build_graph at 0x7fe1b9358d30>
-> 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()
| -> <function
Graph._build_vertex_params at
0x7fe1b9358dc0>
-> 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()
| -> <function
Vertex._build_params at 0x7fe1b967d510>
-> 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()}
| | |
-> <method 'get' of 'dict' objects>
| | ->
{'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 dosubot bot added the bug Something isn't working label May 5, 2024
Copy link

dosubot bot commented May 5, 2024

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


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant