From f1a737f76e21185aac20e3a8acc54a4b684ba2ec Mon Sep 17 00:00:00 2001 From: Nathan Nowack Date: Mon, 5 Feb 2024 21:39:19 -0600 Subject: [PATCH 1/2] dont require api key if not openai base url --- src/marvin/utilities/openai.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/marvin/utilities/openai.py b/src/marvin/utilities/openai.py index 667865b55..0b2844067 100644 --- a/src/marvin/utilities/openai.py +++ b/src/marvin/utilities/openai.py @@ -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, From 4881eed6c13eafc115e33ad819b04f8dcd7d26c4 Mon Sep 17 00:00:00 2001 From: Nathan Nowack Date: Mon, 5 Feb 2024 22:19:57 -0600 Subject: [PATCH 2/2] flake --- tests/ai/beta/vision/test_cast.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ai/beta/vision/test_cast.py b/tests/ai/beta/vision/test_cast.py index 755b3da9a..1089993b9 100644 --- a/tests/ai/beta/vision/test_cast.py +++ b/tests/ai/beta/vision/test_cast.py @@ -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): @@ -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): @@ -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): @@ -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):