Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

fix: remove logging.basicConfig from groq_client

KCaverly5f3ab1014b71
diff --git a/dsp/modules/groq_client.py b/dsp/modules/groq_client.py
index 0f1d2ffe4..2632d13b9 100644
--- a/dsp/modules/groq_client.py
+++ b/dsp/modules/groq_client.py
@@ -6,22 +6,15 @@ import backoff
try:
import groq
from groq import Groq
+
groq_api_error = (groq.APIError, groq.RateLimitError)
except ImportError:
- groq_api_error = (Exception)
+ groq_api_error = Exception
import dsp
from dsp.modules.lm import LM
-# Configure logging
-logging.basicConfig(
- level=logging.INFO,
- format="%(message)s",
- handlers=[logging.FileHandler("groq_usage.log")],
-)
-
-
def backoff_hdlr(details):
"""Handler from https://pypi.org/project/backoff/"""
@@ -51,10 +44,9 @@ class GroqLM(LM):
self.provider = "groq"
if api_key:
self.api_key = api_key
- self.client = Groq(api_key = api_key)
+ self.client = Groq(api_key=api_key)
else:
raise ValueError("api_key is required for groq")
-
self.kwargs = {
"temperature": 0.0,
@@ -64,14 +56,13 @@ class GroqLM(LM):
"presence_penalty": 0,
"n": 1,
**kwargs,
- }
+ }
models = self.client.models.list().data
if models is not None:
- if model in [m.id for m in models]:
+ if model in [m.id for m in models]:
self.kwargs["model"] = model
self.history: list[dict[str, Any]] = []
-
def log_usage(self, response):
"""Log the total tokens from the Groq API response."""
usage_data = response.get("usage")
@@ -118,7 +109,7 @@ class GroqLM(LM):
"""Handles retreival of model completions whilst handling rate limiting and caching."""
response = self.client.chat.completions.create(**kwargs)
return response
-
+
def __call__(
self,
prompt: str,
@@ -166,4 +157,4 @@ class GroqLM(LM):
scored_completions = sorted(scored_completions, reverse=True)
completions = [c for _, c in scored_completions]
- return completions
\ No newline at end of file
+ return completions