added expection for missing key

This commit is contained in:
Siddhesh Agarwal
2024-10-29 09:28:30 +05:30
parent 584ca9a197
commit ca086bb574
4 changed files with 11 additions and 4 deletions
+2
View File
@@ -21,6 +21,8 @@ class Anthropic(BaseProvider):
@property
def client(self):
"""The raw Anthropic client."""
if not self.api_key:
raise ValueError("Anthropic API key is required")
return anthropic.Anthropic(api_key=self.api_key)
@property
+3 -1
View File
@@ -20,6 +20,8 @@ class Groq(BaseProvider):
@property
def client(self):
"""The raw Groq client."""
if not self.api_key:
raise ValueError("Groq API key is required")
return groq.Groq(api_key=self.api_key)
@property
@@ -43,7 +45,7 @@ class Groq(BaseProvider):
# Create and return a properly formatted Message instance
return Message(
role="assistant",
text=assistant_message.content,
text=assistant_message.content or "",
raw=response,
llm_model=conversation.llm_model or DEFAULT_MODEL,
llm_provider=PROVIDER_NAME,
+2
View File
@@ -20,6 +20,8 @@ class OpenAI(BaseProvider):
@property
def client(self):
"""The raw OpenAI client."""
if not self.api_key:
raise ValueError("OpenAI API key is required")
return oa.OpenAI(api_key=self.api_key)
@property
+4 -3
View File
@@ -22,10 +22,11 @@ class XAI(BaseProvider):
@property
def client(self):
"""The raw OpenAI client."""
if not self.api_key:
raise ValueError("XAI API key is required")
return oa.OpenAI(
api_key=settings.XAI_API_KEY,
base_url="https://api.x.ai/v1",
api_key=self.api_key,
base_url=BASE_URL,
)
@property