Skip to content

Commit 64209c1

Browse files
committed
fix(cohere): Catch attribute error
1 parent 303c669 commit 64209c1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

dsp/modules/cohere.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
try:
88
import cohere
9+
910
cohere_api_error = cohere.errors.UnauthorizedError
1011
except ImportError:
1112
cohere_api_error = Exception
1213
# print("Not loading Cohere because it is not installed.")
14+
except AttributeError:
15+
cohere_api_error = Exception
16+
1317

1418
def backoff_hdlr(details):
1519
"""Handler from https://pypi.org/project/backoff/"""
@@ -84,13 +88,14 @@ def basic_request(self, prompt: str, **kwargs):
8488
kwargs.pop("n")
8589
response = self.co.chat(**kwargs)
8690

87-
88-
self.history.append({
89-
"prompt": prompt,
90-
"response": response,
91-
"kwargs": kwargs,
92-
"raw_kwargs": raw_kwargs,
93-
})
91+
self.history.append(
92+
{
93+
"prompt": prompt,
94+
"response": response,
95+
"kwargs": kwargs,
96+
"raw_kwargs": raw_kwargs,
97+
}
98+
)
9499

95100
return response
96101

0 commit comments

Comments
 (0)