PrefectHQ / marvin

✨ Build AI interfaces that spark joy
https://askmarvin.ai
Apache License 2.0
5.15k stars 326 forks source link

AttributeError: module 'marvin.openai' has no attribute 'api_key' #703

Closed dzaffren closed 7 months ago

dzaffren commented 8 months ago

First check

Bug summary

I am having trouble to import marvin and use AzureOpenAI with it. I have seen some other people who have raised quite a similar issue but the trouble with mine is that it doesn't even allow me to import marvin! Could it be that it's taking OpenAI by default (similar to the others who raised this issue)?

Reproduction

import marvin
from marvin import ai_model

from llama_index.bridge.pydantic import BaseModel, Field

marvin.settings.azure_openai = os.environ["OPENAI_API_KEY"]

@ai_model
class SportsSupplement(BaseModel):
    name: str = Field(..., description="The name of the sports supplement")
    description: str = Field(
        ..., description="A description of the sports supplement"
    )
    pros_cons: str = Field(
        ..., description="The pros and cons of the sports supplement"
    )

Error

AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 import marvin
      2 from marvin import ai_model
      4 from llama_index.bridge.pydantic import BaseModel, Field

File ~/Documents/bnm_chatgpt/.gpt_venv/lib/python3.9/site-packages/marvin/__init__.py:3
      1 from .settings import settings
----> 3 from .components import (
      4     ai_classifier,
      5     ai_fn,
      6     ai_model,
      7     AIApplication,
      8     AIFunction,
      9     AIModel,
     10     AIModelFactory,
     11 )
     13 try:
     14     from ._version import version as __version__

File ~/Documents/bnm_chatgpt/.gpt_venv/lib/python3.9/site-packages/marvin/components/__init__.py:7
      5 from .ai_model_factory import AIModelFactory
      6 from .ai_model import AIModel
----> 7 from .ai_classifier import ai_classifier
...
---> 60 if marvin_openai.api_key:
     61     response["api_key"] = marvin_openai.api_key
     62 response["temperature"] = settings.llm_temperature

AttributeError: module 'marvin.openai' has no attribute 'api_key'

Versions

Name: marvin
Version: 1.5.0

Additional context

No response

zzstoatzz commented 7 months ago

hi @dzaffren - we've updated the way to configure azure settings in marvin 2. You can find the docs here

let us know if you have any trouble!