MetaGPT icon indicating copy to clipboard operation
MetaGPT copied to clipboard

data analysis fails to work with gemini pro due to temperature parameter

Open iitrsamrat opened this issue 3 months ago • 7 comments

Bug description data analysis example fail to work with gemini pro. as of now only web search researcher role working with gemini pro

Bug solved method python3 data_analysis.py

Environment information

  • LLM type and model name: Gemini pro
  • System version:
  • Python version: 3.9

Screenshots or logs python3 data_analysis.py
2024-03-25 18:02:03.871 | INFO | metagpt.const:get_metagpt_package_root:29 - Package root set to /Users/samsaha2

[
  {
    "task_id": "1",
    "dependent_task_ids": [],
    "instruction": "Download the TruthfulQA dataset from GitHub."
  },
  {
    "task_id": "2",
    "dependent_task_ids": [
      "1"
    ],
    "instruction": "Load the dataset into a data analysis tool."
  },
  {
    "task_id": "3",
    "dependent_task_ids": [
      "2"
    ],
    "instruction": "Perform data analysis on the dataset."
  },
  {
    "task_id": "4",
    "dependent_task_ids": [
      "3"
    ],
    "instruction": "Create plots to visualize the results of the data analysis."
  },
  {
    "task_id": "5",
    "dependent_task_ids": [
      "4"
    ],
    "instruction": "Share the analysis and plots with others."
  }
]

2024-03-25 18:02:15.630 | INFO | metagpt.utils.cost_manager:update_cost:52 - Total running cost: $0.000 | Max budget: $10.000 | Current cost: $0.000, prompt_tokens: 255, completion_tokens: 245 2024-03-25 18:02:15.632 | INFO | metagpt.roles.role:_plan_and_act:494 - ready to take on task task_id='1' dependent_task_ids=[] instruction='Download the TruthfulQA dataset from GitHub.' task_type='' code='' result='' is_success=False is_finished=False 2024-03-25 18:02:15.632 | INFO | metagpt.roles.di.data_interpreter:_write_code:79 - ready to WriteCodeWithoutTools 2024-03-25 18:02:15.640 | WARNING | metagpt.utils.common:wrapper:572 - There is a exception in role's execution, in order to resume, we delete the newest role communication message in the role's memory. Traceback (most recent call last): File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/utils/common.py", line 563, in wrapper return await func(self, *args, **kwargs) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 558, in run rsp = await self.react() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 529, in react rsp = await self._plan_and_act() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 497, in _plan_and_act task_result = await self._act_on_task(task) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 46, in _act_on_task code, result, is_success = await self._write_and_exec_code() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 56, in _write_and_exec_code code, cause_by = await self._write_code() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 83, in _write_code code = await todo.run(context=context, plan=self.planner.plan, temperature=0.0) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/actions/di/write_analysis_code.py", line 52, in run rsp = await self.llm.aask_code(messages, **kwargs) TypeError: aask_code() got an unexpected keyword argument 'temperature'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/samsaha2/data_analysis.py", line 17, in asyncio.run(main(requirement)) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/Users/samsaha2/data_analysis.py", line 9, in main rsp = await di.run(requirement) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/utils/common.py", line 585, in wrapper raise Exception(format_trackback_info(limit=None)) Exception: Traceback (most recent call last): File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/utils/common.py", line 563, in wrapper return await func(self, *args, **kwargs) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 558, in run rsp = await self.react() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 529, in react rsp = await self._plan_and_act() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/role.py", line 497, in _plan_and_act task_result = await self._act_on_task(task) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 46, in _act_on_task code, result, is_success = await self._write_and_exec_code() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 56, in _write_and_exec_code code, cause_by = await self._write_code() File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/roles/di/data_interpreter.py", line 83, in _write_code code = await todo.run(context=context, plan=self.planner.plan, temperature=0.0) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/site-packages/metagpt/actions/di/write_analysis_code.py", line 52, in run rsp = await self.llm.aask_code(messages, **kwargs) TypeError: aask_code() got an unexpected keyword argument 'temperature'

iitrsamrat avatar Mar 25 '24 12:03 iitrsamrat

What is the command you used to install metagpt?

geekan avatar Mar 25 '24 13:03 geekan

Hello @geekan , I have used "pip install --upgrade metagpt" to install for google search etc I had to install other bunch of packages. I downloaded the data_analysis.py from GitHub and running as below.

python3 data_analysis.py

My requirement is little different as below. " requirement = "Run data analysis on https://github.com/sylinrl/TruthfulQA dataset, share your analysis and include plots" "

iitrsamrat avatar Mar 25 '24 13:03 iitrsamrat

This issue has been fixed in main branch.

iorisa avatar Mar 25 '24 15:03 iorisa

I did a git pull following is my version. 5e789715..02e0eb0a code_interpreter -> origin/code_interpreter

data analysis still does not run. here is the error.

`[ { "task_id": "1", "dependent_task_ids": [], "instruction": "Load the TruthfulQA dataset and examine the data", "task_type": "eda" }, { "task_id": "2", "dependent_task_ids": ["1"], "instruction": "Analyze the data to identify trends and patterns", "task_type": "eda" }, { "task_id": "3", "dependent_task_ids": ["2"], "instruction": "Create visualizations and plots to highlight key insights", "task_type": "other"
} ] 2024-03-27 11:32:18.321 | WARNING | metagpt.utils.common:wrapper:649 - There is a exception in role's execution, in order to resume, we delete the newest role communication message in the role's memory. Traceback (most recent call last): File "/Users/samsaha2/MetaGPT/metagpt/utils/common.py", line 640, in wrapper return await func(self, *args, **kwargs) File "/Users/samsaha2/MetaGPT/metagpt/roles/role.py", line 550, in run rsp = await self.react() File "/Users/samsaha2/MetaGPT/metagpt/roles/role.py", line 521, in react rsp = await self._plan_and_act() File "/Users/samsaha2/MetaGPT/metagpt/roles/di/data_interpreter.py", line 89, in _plan_and_act rsp = await super()._plan_and_act() File "/Users/samsaha2/MetaGPT/metagpt/roles/role.py", line 481, in _plan_and_act await self.planner.update_plan(goal=goal) File "/Users/samsaha2/MetaGPT/metagpt/strategy/planner.py", line 89, in update_plan update_plan_from_rsp(rsp=rsp, current_plan=self.plan) File "/Users/samsaha2/MetaGPT/metagpt/actions/di/write_plan.py", line 55, in update_plan_from_rsp rsp = json.loads(rsp) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/samsaha2/miniconda3/envs/metagpt/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:`

iitrsamrat avatar Mar 27 '24 06:03 iitrsamrat

how about try to use main branch?

geekan avatar Mar 27 '24 07:03 geekan

I recommend using main, too. From your log, the original temperature issue is fixed, which is good. The problem is Gemini did not follow the instruction to generate response in a valid json-format string. Maybe close this issue and raise a different issue asking for auto repairing Gemini response if Gemini fails to adhere to instruction?

garylin2099 avatar Mar 27 '24 08:03 garylin2099

I ran data analysis with claude and the above error occurred.

Here is the branch details.

git branch

  • main

MetaGPT % git status On branch main Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

` #llm: #api_type: "gemini" #api_key: "" #model: "gemini-pro" #base_url: "https://generativelanguage.googleapis.com/v1beta/models/"

llm: api_type: "anthropic" api_key: "" model: "claude-3-opus-20240229" base_url: "https://api.anthropic.com" `

iitrsamrat avatar Mar 27 '24 08:03 iitrsamrat