Skip to content

OPENAI_API_KEY missing error when running the End-to-end example from Azure OpenAI docs  #629

@yashworlikar

Description

@yashworlikar

I encountered an error while running the End-to-end example from the Azure OpenAI documentation. The error indicates that the OPENAI_API_KEY is not set .

Error Message:


Traceback (most recent call last):
  File "C:\Applications\Application\autoLLM\demo.py", line 21, in <module>
    world_model = WorldModel()
                  ^^^^^^^^^^^^
  File "C:\Applications\Application\autoLLM\venv\Lib\site-packages\lavague\core\world_model.py", line 377, in __init__
    mm_llm = get_default_context().mm_llm
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Applications\Application\autoLLM\venv\Lib\site-packages\lavague\core\context.py", line 35, in get_default_context
    return OpenaiContext()
           ^^^^^^^^^^^^^^^
  File "C:\Applications\Application\autoLLM\venv\Lib\site-packages\lavague\contexts\openai\base.py", line 23, in __init__
    raise ValueError("OPENAI_API_KEY is not set")
ValueError: OPENAI_API_KEY is not set

Steps to Reproduce:

  1. Follow the End-to-end example from the Azure OpenAI documentation.
  2. Fill in the required Azure configs
  3. Run the provided code snippet.

Code Snippet:

from lavague.core import WorldModel, ActionEngine
from lavague.core.agents import WebAgent
from lavague.drivers.selenium import SeleniumDriver
from lavague.contexts.openai import AzureOpenaiContext

# Initialize context with our custom elements
context = AzureOpenaiContext(
    api_key="your_api_key",
    deployment="deployment_name",
    llm="<model_name>",
    mm_llm="<model_name>",
    endpoint="<your_endpoint>",
    embedding="embedding_model_name",
    embedding_deployment="embedding_deployment_name"
)

selenium_driver = SeleniumDriver()

# Build Action Engine and World Model from Context
action_engine = ActionEngine.from_context(context=context, driver=selenium_driver)
world_model = WorldModel()

# Build agent & run query
agent = WebAgent(world_model, action_engine)
agent.get("https://huggingface.co/")
agent.run("What is this week's top Space of the week?")

Expected Behavior: The code should run without errors and perform the intended actions.

Actual Behavior: The code raises a ValueError indicating that the OPENAI_API_KEY is not set.

Passing the mm_llm from the context to the WorldModel when creating an instance of it fixes it.

world_model = WorldModel(mm_llm=context.mm_llm) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions