diff --git a/README.md b/README.md index f64fb8eebb6273081bbcbd61d096742a8ca5c181..03480b8dfb67d82ba5bf21fe475c68640cf77a56 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ politics = Route( utterances=[ "isn't politics the best thing ever", "why don't you tell me about your political opinions", - "don't you just love the president" "don't you just hate the president", + "don't you just love the president", "they're going to destroy this country!", "they will save the country!", ], @@ -147,4 +147,4 @@ Daniel Avila, [Semantic Router: Enhancing Control in LLM Conversations](https:// Yogendra Sisodia, [Stop Chat-GPT From Going Rogue In Production With Semantic Router](https://medium.com/@scholarly360/stop-chat-gpt-from-going-rogue-in-production-with-semantic-router-937a4768ae19), Medium -Aniket Hingane, [LLM Apps: Why you Must Know Semantic Router in 2024: Part 1](https://medium.com/@learn-simplified/llm-apps-why-you-must-know-semantic-router-in-2024-part-1-bfbda81374c5), Medium \ No newline at end of file +Aniket Hingane, [LLM Apps: Why you Must Know Semantic Router in 2024: Part 1](https://medium.com/@learn-simplified/llm-apps-why-you-must-know-semantic-router-in-2024-part-1-bfbda81374c5), Medium diff --git a/semantic_router/encoders/openai.py b/semantic_router/encoders/openai.py index 7699c3c1558cde828055d28b1c313424d3253a54..de6c0599710b59a14124ae269eee3b047eb33063 100644 --- a/semantic_router/encoders/openai.py +++ b/semantic_router/encoders/openai.py @@ -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, @@ -29,11 +30,14 @@ class OpenAIEncoder(BaseEncoder): 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}"