diff --git a/package/gentrace/providers/getters.py b/package/gentrace/providers/getters.py index 781ff98..098f728 100644 --- a/package/gentrace/providers/getters.py +++ b/package/gentrace/providers/getters.py @@ -1,6 +1,5 @@ import os import re -from urllib.parse import urlparse import openai @@ -12,13 +11,22 @@ VALID_GENTRACE_HOST = r"^https?://[\w.-]+:\d{1,5}/api/v1/?$" +def test_validity(): + from gentrace import api_key, host + + if not api_key: + raise ValueError("Gentrace API key not set") + + if host and not re.match(VALID_GENTRACE_HOST, host): + raise ValueError("Gentrace host is invalid") + + def configure_openai(): from gentrace import api_key, host from .llms.openai import annotate_openai_module - if not api_key: - raise ValueError("Gentrace API key not set") + test_validity() if host and not re.match(VALID_GENTRACE_HOST, host): raise ValueError("Gentrace host is invalid") @@ -30,12 +38,9 @@ def configure_openai(): def configure_pinecone(): - from gentrace import api_key, host - from .vectorstores.pinecone import annotate_pinecone_module - if not api_key: - raise ValueError("Gentrace API key not set") + test_validity() annotate_pinecone_module()