Skip to content

[BUG] generate_twitter_agent_graph does not work with JSON user data #164

@judgeNotFound

Description

@judgeNotFound

Required prerequisites

What version of camel-oasis are you using?

0.2.3

System information

3.10.16 (main, Dec 3 2024, 17:27:57) [Clang 19.1.7 ] darwin
0.2.3

Problem description

Running the code in Twitter Simulation Example leads to the following error:

pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2

Possible Solution

In oasis/social_agent/agents_generator.py (Function generate_twitter_agent_graph), the following is the first line:

agent_info = pd.read_csv(profile_path)

This means it tries to read from a CSV. However, the example is provided in JSON format, which is incompatible. Therefore, this line should be changed to the line from the similar function generate_reddit_agent_graph, which is:

agent_graph = AgentGraph()
with open(profile_path, "r") as file:
    agent_info = json.load(file)

Reproducible example code

See guide from Twitter Simulation Documentation.

Traceback

Traceback (most recent call last):
  File "/Users/someone/Git/oasis/backend/simulation.py", line 94, in <module>
    asyncio.run(main())
  File "/nix/store/1zajgd4p9dxxkkprrk7djzkfd2dlcx1i-python3-3.10.16/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/nix/store/1zajgd4p9dxxkkprrk7djzkfd2dlcx1i-python3-3.10.16/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/someone/Git/oasis/backend/simulation.py", line 36, in main
    agent_graph = await generate_twitter_agent_graph(
  File "/Users/someone/Library/Caches/pypoetry/virtualenvs/oasis-Mv7OdWUu-py3.10/lib/python3.10/site-packages/oasis/social_agent/agents_generator.py", line 620, in generate_twitter_agent_graph
    agent_info = pd.read_csv(profile_path)
  File "/Users/someone/Library/Caches/pypoetry/virtualenvs/oasis-Mv7OdWUu-py3.10/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1026, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/Users/someone/Library/Caches/pypoetry/virtualenvs/oasis-Mv7OdWUu-py3.10/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 626, in _read
    return parser.read(nrows)
  File "/Users/someone/Library/Caches/pypoetry/virtualenvs/oasis-Mv7OdWUu-py3.10/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1923, in read
    ) = self._engine.read(  # type: ignore[attr-defined]
  File "/Users/someone/Library/Caches/pypoetry/virtualenvs/oasis-Mv7OdWUu-py3.10/lib/python3.10/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 234, in read
    chunks = self._reader.read_low_memory(nrows)
  File "parsers.pyx", line 838, in pandas._libs.parsers.TextReader.read_low_memory
  File "parsers.pyx", line 905, in pandas._libs.parsers.TextReader._read_rows
  File "parsers.pyx", line 874, in pandas._libs.parsers.TextReader._tokenize_rows
  File "parsers.pyx", line 891, in pandas._libs.parsers.TextReader._check_tokenize_status
  File "parsers.pyx", line 2061, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2

Expected behavior

A working code.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions