From a6f9772d8567d8a171e82ead50ef8755f1bb3820 Mon Sep 17 00:00:00 2001 From: Shreya Shankar Date: Sun, 29 Sep 2024 20:11:48 -0700 Subject: [PATCH 1/3] Add error messages if model doesnt support tool calling --- docetl/operations/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docetl/operations/utils.py b/docetl/operations/utils.py index 66df5833..82df830a 100644 --- a/docetl/operations/utils.py +++ b/docetl/operations/utils.py @@ -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 @@ -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 @@ -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} From 05ede3ff9ac2b8e36a2263ff2ebcd0088380786e Mon Sep 17 00:00:00 2001 From: Shreya Shankar Date: Sun, 29 Sep 2024 20:32:00 -0700 Subject: [PATCH 2/3] Update version number in init.py --- docetl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docetl/__init__.py b/docetl/__init__.py index fb906ecf..18128f90 100644 --- a/docetl/__init__.py +++ b/docetl/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.0" +__version__ = "0.1.4" from docetl.runner import DSLRunner from docetl.builder import Optimizer From c26994dde8dc69143dc6d99f502f1ae376c0c17e Mon Sep 17 00:00:00 2001 From: Shreya Shankar Date: Sun, 29 Sep 2024 20:42:08 -0700 Subject: [PATCH 3/3] Update version number and fix bug in conditional --- docetl/__init__.py | 2 +- docetl/operations/utils.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docetl/__init__.py b/docetl/__init__.py index 18128f90..8b996359 100644 --- a/docetl/__init__.py +++ b/docetl/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.4" +__version__ = "0.1.5" from docetl.runner import DSLRunner from docetl.builder import Optimizer diff --git a/docetl/operations/utils.py b/docetl/operations/utils.py index 82df830a..30ebffca 100644 --- a/docetl/operations/utils.py +++ b/docetl/operations/utils.py @@ -825,7 +825,7 @@ def parse_llm_response( output_dict = json.loads(tool_call.function.arguments) if "ollama" in response.model: for key, value in output_dict.items(): - if isinstance(value, str): + if not isinstance(value, str): continue try: output_dict[key] = ast.literal_eval(value) diff --git a/pyproject.toml b/pyproject.toml index 0ff20e20..08730e90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "docetl" -version = "0.1.4" +version = "0.1.5" description = "ETL with LLM operations." authors = ["Shreya Shankar "] license = "MIT"