Skip to content

Commit 064f6d2

Browse files
authored
Remove retry_strategy in LM and handle no-docstring functions in ReAct (#1725)
* Remove retry_strategy in LM and handle no-docstring functions in ReAct * exponential_backoff_retry tests
1 parent 94f1fd7 commit 064f6d2

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

dspy/clients/lm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(
3939
cache: bool = True,
4040
launch_kwargs: Optional[Dict[str, Any]] = None,
4141
callbacks: Optional[List[BaseCallback]] = None,
42-
num_retries: int = 8,
42+
num_retries: int = 3,
4343
**kwargs,
4444
):
4545
"""
@@ -186,7 +186,6 @@ def litellm_completion(request, num_retries: int, cache={"no-cache": True, "no-s
186186
kwargs = ujson.loads(request)
187187
return litellm.completion(
188188
num_retries=num_retries,
189-
retry_strategy="exponential_backoff_retry",
190189
cache=cache,
191190
**kwargs,
192191
)
@@ -223,7 +222,6 @@ def litellm_text_completion(request, num_retries: int, cache={"no-cache": True,
223222
api_base=api_base,
224223
prompt=prompt,
225224
num_retries=num_retries,
226-
retry_strategy="exponential_backoff_retry",
227225
**kwargs,
228226
)
229227

dspy/predict/react.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, func: Callable, name: str = None, desc: str = None, args: dic
1212
annotations_func = func if inspect.isfunction(func) else func.__call__
1313
self.func = func
1414
self.name = name or getattr(func, '__name__', type(func).__name__)
15-
self.desc = desc or getattr(func, '__doc__', None) or getattr(annotations_func, '__doc__', "No description")
15+
self.desc = desc or getattr(func, '__doc__', None) or getattr(annotations_func, '__doc__', "")
1616
self.args = {
1717
k: v.schema() if isinstance((origin := get_origin(v) or v), type) and issubclass(origin, BaseModel)
1818
else get_annotation_name(v)
@@ -50,10 +50,10 @@ def __init__(self, signature, tools: list[Callable], max_iters=5):
5050
tools["finish"] = Tool(func=lambda **kwargs: "Completed.", name="finish", desc=finish_desc, args=finish_args)
5151

5252
for idx, tool in enumerate(tools.values()):
53-
desc = tool.desc.replace("\n", " ")
5453
args = tool.args if hasattr(tool, 'args') else str({tool.input_variable: str})
55-
desc = f"whose description is <desc>{desc}</desc>. It takes arguments {args} in JSON format."
56-
instr.append(f"({idx+1}) {tool.name}, {desc}")
54+
desc = (f", whose description is <desc>{tool.desc}</desc>." if tool.desc else ".").replace('\n', " ")
55+
desc += f" It takes arguments {args} in JSON format."
56+
instr.append(f"({idx+1}) {tool.name}{desc}")
5757

5858
signature_ = (
5959
dspy.Signature({**signature.input_fields}, "\n".join(instr))

tests/clients/test_lm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_lm_chat_respects_max_retries():
1111

1212
assert litellm_completion_api.call_count == 1
1313
assert litellm_completion_api.call_args[1]["max_retries"] == 17
14-
assert litellm_completion_api.call_args[1]["retry_strategy"] == "exponential_backoff_retry"
14+
# assert litellm_completion_api.call_args[1]["retry_strategy"] == "exponential_backoff_retry"
1515

1616

1717
def test_lm_completions_respects_max_retries():
@@ -22,4 +22,4 @@ def test_lm_completions_respects_max_retries():
2222

2323
assert litellm_completion_api.call_count == 1
2424
assert litellm_completion_api.call_args[1]["max_retries"] == 17
25-
assert litellm_completion_api.call_args[1]["retry_strategy"] == "exponential_backoff_retry"
25+
# assert litellm_completion_api.call_args[1]["retry_strategy"] == "exponential_backoff_retry"

0 commit comments

Comments
 (0)