Skip to content

Commit

Permalink
Add error messages if model doesnt support tool calling
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashankar committed Sep 30, 2024
1 parent a8c7ac8 commit a6f9772
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docetl/operations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
from concurrent.futures import as_completed
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
import litellm

from dotenv import load_dotenv
from frozendict import frozendict
Expand Down Expand Up @@ -388,6 +389,11 @@ def call_llm(
Raises:
TimeoutError: If the call times out after retrying.
"""
if not litellm.supports_function_calling(model):
raise ValueError(
f"Model {model} does not support function calling (which we use for structured outputs). Please use a different model."
)

key = cache_key(model, op_type, messages, output_schema, scratchpad)

max_retries = max_retries_per_timeout
Expand Down Expand Up @@ -632,6 +638,11 @@ def call_llm_with_gleaning(
Returns:
Tuple[str, float]: A tuple containing the final LLM response and the total cost.
"""
if not litellm.supports_function_calling(model):
raise ValueError(
f"Model {model} does not support function calling (which we use for structured outputs). Please use a different model."
)

props = {key: convert_val(value) for key, value in output_schema.items()}

parameters = {"type": "object", "properties": props}
Expand Down

0 comments on commit a6f9772

Please sign in to comment.