When I had installed nemoguardrails 0.11.0 and added azure open ai as main model in config.yml, it had worked.
But when I installed the latest nemoguardrails 0.14.0 with the same model configuration, its throwing the below error
.venv\Lib\site-packages\nemoguardrails\llm\models\langchain_initializer.py", line 193, in init_langchain_model
raise ModelInitializationError(base) from last_exception
nemoguardrails.llm.models.langchain_initializer.ModelInitializationError: Failed to initialize model ‘gpt-4o-mini’ with provider ‘azure’ in ‘chat’ mode: ValueError encountered in initializer _init_text_completion_model(modes=[‘text’, ‘chat’]) for model: gpt-4o-mini and provider: azure: 1 validation error for OpenAIChat
Value error, Did not find openai_api_key, please add an environment variable OPENAI_API_KEY which contains it, or pass openai_api_key as a named parameter. [type=value_error, input_value={‘api_key’: ‘9DUJj5JczBLw…allowed_special’: ‘all’}, input_type=dict]
Hi @kavanakitty8,
Can you set the OPENAI_API_KEY Environment Variable with your key and try again?
export OPENAI_API_KEY=<your_openai_api_key>
If you do not have an OpenAI API key, you could try setting this to a placeholder value - this seems to have worked for others on this thread Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error) · Issue #7189 · langchain-ai/langchain · GitHub.
Let us know how you get on.
Best,
Sophie
The error I’ve mentioned is when I run the examples in nemoguardrails repository. When I integrate it with langchain in my own project by configuring same Azure open ai llm, I get an LLM Call Exception: ‘NoneType’ object has no attribute ‘create’
I’ve tried adding openai_api_key as both environment variable and as a parameter in model configuration in the yml, but still the same error exists with nemoguardrails 0.14.0 version.
Thanks for the extra info, I’ll reach out to the Guardrails team for assistance here!
Thanks, that helps!
I would be waiting for the team’s response.
Best,
Kavana
An update here:
In the nemoguardrails 0.14.0 release repository, the error I have already mentioned occurred. Post that, I added my azure open ai api key as the value in the environment variable OPENAI_API_KEY, then it asked me to install openai. Post installation of openai, I see the below error which also occurs in my project where I have installed nemoguardrails 0.14.0 and integrated with langchain and using azure open ai:
Traceback (most recent call last):
File “”, line 198, in _run_module_as_main
File “”, line 88, in run_code
File ".venv\Scripts\nemoguardrails.exe_main.py", line 7, in
sys.exit(app())
~~~^^
File “.venv\Lib\site-packages\typer\main.py”, line 341, in call
raise e
File “.venv\Lib\site-packages\typer\main.py”, line 324, in call
return get_command(self)(*args, **kwargs)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File “.venv\Lib\site-packages\click\core.py”, line 1442, in call
return self.main(*args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^
File “.venv\Lib\site-packages\typer\core.py”, line 757, in main
return _main(
self,
…<6 lines>…
**extra,
)
File “.venv\Lib\site-packages\typer\core.py”, line 195, in _main
rv = self.invoke(ctx)
File “.venv\Lib\site-packages\click\core.py”, line 1830, in invoke
return process_result(sub_ctx.command.invoke(sub_ctx))
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File “.venv\Lib\site-packages\click\core.py”, line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “.venv\Lib\site-packages\click\core.py”, line 794, in invoke
return callback(*args, **kwargs)
File “.venv\Lib\site-packages\typer\main.py”, line 699, in wrapper
return callback(**use_params)
File "nemoguardrails\cli_init.py", line 101, in chat
run_chat(
~~~~~~~~^
config_path=config[0],
^^^^^^^^^^^^^^^^^^^^^^
…<4 lines>…
config_id=config_id,
^^^^^^^^^^^^^^^^^^^^
)
^
File “nemoguardrails\cli\chat.py”, line 667, in run_chat
asyncio.run(
~~~~~~~~~~~^
_run_chat_v1_0(
^^^^^^^^^^^^^^^
…<5 lines>…
)
^
)
^
File “Python313\Lib\asyncio\runners.py”, line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File “Python313\Lib\asyncio\runners.py”, line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File “Python313\Lib\asyncio\base_events.py”, line
725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File “nemoguardrails\cli\chat.py”, line 104, in _run_chat_v1_0
bot_message = await rails_app.generate_async(messages=history)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “nemoguardrails\rails\llm\llmrails.py”, line 706, in generate_async
new_events = await self.runtime.generate_events(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
state_events + events, processing_log=processing_log
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “nemoguardrails\colang\v1_0\runtime\runtime.py”, line 167, in generate_events
next_events = await self._process_start_action(events)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “nemoguardrails\colang\v1_0\runtime\runtime.py”, line 363, in _process_start_action
result, status = await self.action_dispatcher.execute_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
action_name, kwargs
^^^^^^^^^^^^^^^^^^^
)
^
File “nemoguardrails\actions\action_dispatcher.py”, line 253, in execute_action
raise e
File “nemoguardrails\actions\action_dispatcher.py”, line 214, in execute_action
result = await result
^^^^^^^^^^^^
File “nemoguardrails\library\self_check\input_check\actions.py”, line 72, in self_check_input
response = await llm_call(llm, prompt, stop=stop)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “nemoguardrails\actions\llm\utils.py”, line 96, in llm_call
raise LLMCallException(e)
nemoguardrails.actions.llm.utils.LLMCallException: LLM Call Exception: ‘NoneType’ object has no attribute ‘create’
The issue was with the configuration of LLM engine. I was using “azure” but its no longer supported, it should be “azure_openai” instead.