Fix AWS Bedrock invocation; create output folder in cli.py if it doesn't exist #1014
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Without this change AWS Bedrock fails with the following error:
Error in reading JSON, attempting to repair JSON
Error using json_repair: the JSON object must be str, bytes or bytearray, not NoneType
Traceback (most recent call last):
File "/Users/xo/gpt-researcher/gpt_researcher/actions/agent_creator.py", line 27, in choose_agent
response = await create_chat_completion(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/utils/llm.py", line 54, in create_chat_completion
provider = get_llm(llm_provider, model=model, temperature=temperature,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/utils/llm.py", line 19, in get_llm
return GenericLLMProvider.from_provider(llm_provider, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/llm_provider/generic/base.py", line 104, in from_provider
llm = ChatBedrock(**kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/langchain_core/load/serializable.py", line 113, in init
super().init(*args, **kwargs)
File "/opt/homebrew/lib/python3.12/site-packages/pydantic/v1/main.py", line 341, in init
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 2 validation errors for ChatBedrock
max_tokens
extra fields not permitted (type=value_error.extra)
temperature
extra fields not permitted (type=value_error.extra)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xo/gpt-researcher/cli.py", line 103, in
asyncio.run(main(args))
File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/cli.py", line 89, in main
await researcher.conduct_research()
File "/Users/xo/gpt-researcher/gpt_researcher/agent.py", line 92, in conduct_research
self.agent, self.role = await choose_agent(
^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/actions/agent_creator.py", line 44, in choose_agent
return await handle_json_error(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/actions/agent_creator.py", line 55, in handle_json_error
json_string = extract_json_with_regex(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xo/gpt-researcher/gpt_researcher/actions/agent_creator.py", line 71, in extract_json_with_regex
json_match = re.search(r"{.*?}", response, re.DOTALL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/init.py", line 177, in search
return _compile(pattern, flags).search(string)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'