Skip to content

Commit 16afc75

Browse files
authored
[bugf][agent][fall back instead of raising when the model id is unmapped] (kyegomez#1813)
1 parent 06413eb commit 16afc75

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

swarms/structs/agent.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,10 +3096,19 @@ def _default_max_tokens(self) -> int:
30963096
Returns:
30973097
int: The maximum number of output tokens for the model. Returns 16000 if undetermined.
30983098
"""
3099-
return (
3100-
get_model_info(self.model_name).get("max_output_tokens")
3101-
or 16000
3102-
)
3099+
# get_model_info raises for an unmapped model id rather than
3100+
# returning an empty mapping, so an unknown, custom or self-hosted
3101+
# model would otherwise take down Agent.__init__. The sibling
3102+
# _default_context_length guards the same call the same way.
3103+
try:
3104+
return (
3105+
get_model_info(self.model_name).get(
3106+
"max_output_tokens"
3107+
)
3108+
or 16000
3109+
)
3110+
except Exception:
3111+
return 16000
31033112

31043113
def reliability_check(self):
31053114

0 commit comments

Comments
 (0)