Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravelle committed Aug 26, 2024
2 parents 171c6b0 + b7c014d commit b44d7c3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions groq_provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
groq_provider.py

import os
import json
from typing import Dict, Any, List, Union, AsyncIterator
import asyncio
from groq import Groq, AsyncGroq

try:
from groq import Groq, AsyncGroq
except ImportError:
print("Warning: Unable to import Groq and AsyncGroq from groq package. Make sure you have the correct version installed.")
Groq = None
AsyncGroq = None

from .exceptions import GroqAPIKeyMissingError, GroqAPIError
from .config import get_api_key

Expand All @@ -11,6 +20,8 @@ def __init__(self, api_key: str = None):
self.api_key = api_key or get_api_key()
if not self.api_key:
raise GroqAPIKeyMissingError("Groq API key is not provided")
if Groq is None or AsyncGroq is None:
raise ImportError("Groq and AsyncGroq classes could not be imported. Please check your groq package installation.")
self.client = Groq(api_key=self.api_key)
self.async_client = AsyncGroq(api_key=self.api_key)
self.tool_use_models = [
Expand Down Expand Up @@ -152,4 +163,4 @@ def process_response(self, response: Any) -> Dict[str, Any]:
return response

def send_request(self, data: Dict[str, Any]) -> Any:
return self._create_completion(data["messages"], **data)
return self._create_completion(data["messages"], **data)

0 comments on commit b44d7c3

Please sign in to comment.