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

dont require api key if not openai base url #830

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/marvin/utilities/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ def get_openai_client(
)

if not api_key:
raise ValueError(
inspect.cleandoc(
"""
OpenAI API key not found! Marvin will not work properly without it.

You can either:
1. Set the `MARVIN_OPENAI_API_KEY` or `OPENAI_API_KEY` environment variables
2. Set `marvin.settings.openai.api_key` in your code (not recommended for production)
if (
api_url := marvin.settings.openai.base_url
) is None or api_url.startswith("https://api.openai.com"):
raise ValueError(
inspect.cleandoc(
"""
OpenAI API key not found! Marvin will not work properly without it.

If you do not have an OpenAI API key, you can create one at https://platform.openai.com/api-keys.
"""
You can either:
1. Set the `MARVIN_OPENAI_API_KEY` or `OPENAI_API_KEY` environment variables
2. Set `marvin.settings.openai.api_key` in your code (not recommended for production)

If you do not have an OpenAI API key, you can create one at https://platform.openai.com/api-keys.
"""
)
)
)
else:
api_key = "does-not-matter-for-self-hosted"

kwargs.update(
api_key=api_key,
Expand Down
4 changes: 4 additions & 0 deletions tests/ai/beta/vision/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_cast_ny(self):
assert result in (
Location(city="New York", state="NY"),
Location(city="New York City", state="NY"),
Location(city="Manhattan", state="NY"),
)

def test_cast_ny_images_input(self):
Expand All @@ -28,6 +29,7 @@ def test_cast_ny_images_input(self):
assert result in (
Location(city="New York", state="NY"),
Location(city="New York City", state="NY"),
Location(city="Manhattan", state="NY"),
)

def test_cast_ny_image_input(self):
Expand All @@ -38,6 +40,7 @@ def test_cast_ny_image_input(self):
assert result in (
Location(city="New York", state="NY"),
Location(city="New York City", state="NY"),
Location(city="Manhattan", state="NY"),
)

def test_cast_ny_image_and_text(self):
Expand All @@ -52,6 +55,7 @@ def test_cast_ny_image_and_text(self):
assert result in (
Location(city="New York", state="NY"),
Location(city="New York City", state="NY"),
Location(city="Manhattan", state="NY"),
)

def test_cast_dog(self):
Expand Down
Loading