Skip to content

Commit

Permalink
Merge pull request #35 from stanford-oval/auto-sync-2024-04-25-23-24-14
Browse files Browse the repository at this point in the history
auto-sync-2024-04-25-23-24-14
  • Loading branch information
Yucheng-Jiang authored Apr 26, 2024
2 parents 5206981 + 4b71364 commit 6c89da1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,4 @@ Please cite our paper if you use this code or part of it in your work:
}
```


16 changes: 4 additions & 12 deletions src/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
from dsp.modules.hf_client import send_hfvllm_request_v00, send_hftgi_request_v01_wrapped
from transformers import AutoTokenizer

try:
import anthropic
except ImportError:
pass


class OpenAIModel(dspy.OpenAI):
"""A wrapper class for dspy.OpenAI."""
Expand Down Expand Up @@ -120,7 +115,7 @@ def __init__(
):
super().__init__(model)
try:
from anthropic import Anthropic
from anthropic import Anthropic, RateLimitError
except ImportError as err:
raise ImportError("Claude requires `pip install anthropic`.") from err

Expand Down Expand Up @@ -193,7 +188,7 @@ def basic_request(self, prompt: str, **kwargs):

@backoff.on_exception(
backoff.expo,
(anthropic.RateLimitError,),
(RateLimitError,),
max_time=1000,
max_tries=8,
on_backoff=backoff_hdlr,
Expand Down Expand Up @@ -224,11 +219,8 @@ def __call__(self, prompt, only_completed=True, return_sorted=False, **kwargs):
for _ in range(n):
response = self.request(prompt, **kwargs)
self.log_usage(response)
# This is the original behavior in dspy/dsp/modules/anthropic.py.
# Comment it out because it can cause "IndexError: list index out of range" silently
# which is not transparent to developers.
# if only_completed and response.stop_reason == "max_tokens":
# continue
if only_completed and response.stop_reason == "max_tokens":
continue
completions = [c.text for c in response.content]
return completions

Expand Down

0 comments on commit 6c89da1

Please sign in to comment.