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

Fix AWS Bedrock invocation; create output folder in cli.py if it doesn't exist #1014

Merged
merged 2 commits into from
Dec 14, 2024

Conversation

ai-1st
Copy link
Contributor

@ai-1st ai-1st commented Dec 9, 2024

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'

Copy link
Owner

@assafelovic assafelovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find, thank you!

@assafelovic assafelovic merged commit c7b18fd into assafelovic:master Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants