Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

fix(cohere): Catch attribute error

Isaac Miller64209c128729
diff --git a/dsp/modules/cohere.py b/dsp/modules/cohere.py
index b24390e55..728172dcc 100644
--- a/dsp/modules/cohere.py
+++ b/dsp/modules/cohere.py
@@ -6,10 +6,14 @@ from dsp.modules.lm import LM
try:
import cohere
+
cohere_api_error = cohere.errors.UnauthorizedError
except ImportError:
cohere_api_error = Exception
# print("Not loading Cohere because it is not installed.")
+except AttributeError:
+ cohere_api_error = Exception
+
def backoff_hdlr(details):
"""Handler from https://pypi.org/project/backoff/"""
@@ -84,13 +88,14 @@ class Cohere(LM):
kwargs.pop("n")
response = self.co.chat(**kwargs)
-
- self.history.append({
- "prompt": prompt,
- "response": response,
- "kwargs": kwargs,
- "raw_kwargs": raw_kwargs,
- })
+ self.history.append(
+ {
+ "prompt": prompt,
+ "response": response,
+ "kwargs": kwargs,
+ "raw_kwargs": raw_kwargs,
+ }
+ )
return response