Skip to content

Commit

Permalink
Merge branch 'main' into readme-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescalam authored Mar 15, 2024
2 parents 0e995c9 + d063a20 commit fc8f9a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion semantic_router/encoders/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class OpenAIEncoder(BaseEncoder):
def __init__(
self,
name: Optional[str] = None,
openai_base_url: Optional[str] = None,
openai_api_key: Optional[str] = None,
openai_org_id: Optional[str] = None,
score_threshold: float = 0.82,
Expand All @@ -29,11 +30,14 @@ def __init__(
name = EncoderDefault.OPENAI.value["embedding_model"]
super().__init__(name=name, score_threshold=score_threshold)
api_key = openai_api_key or os.getenv("OPENAI_API_KEY")
base_url = openai_base_url or os.getenv("OPENAI_BASE_URL")
openai_org_id = openai_org_id or os.getenv("OPENAI_ORG_ID")
if api_key is None:
raise ValueError("OpenAI API key cannot be 'None'.")
try:
self.client = openai.Client(api_key=api_key, organization=openai_org_id)
self.client = openai.Client(
base_url=base_url, api_key=api_key, organization=openai_org_id
)
except Exception as e:
raise ValueError(
f"OpenAI API client failed to initialize. Error: {e}"
Expand Down

0 comments on commit fc8f9a4

Please sign in to comment.