Skip to content

Commit

Permalink
Use a more general name (#31)
Browse files Browse the repository at this point in the history
Fixed tool call to work with vLLM and OCI DataScience Model Deployment API

Co-authored-by: Anup Ojah <aojah1@yahoo.com>
  • Loading branch information
hinthornw and aojah1 committed Jan 31, 2025
1 parent 0c27fe5 commit 213ef53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"jsonpatch<2.0,>=1.33",
]
name = "trustcall"
version = "0.0.32"
version = "0.0.34"
description = "Tenacious & trustworthy tool calling built on LangGraph."
readme = "README.md"

Expand Down
11 changes: 4 additions & 7 deletions tests/unit_tests/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,13 @@ def test_validate_existing(existing, tools, is_valid):
extractor._validate_existing(existing)


@pytest.mark.asyncio
@pytest.mark.parametrize("strict_mode", [True, False, "ignore"])
async def test_e2e_existing_schema_policy_behavior(strict_mode):
class MyRecognizedSchema(BaseModel):
"""A recognized schema that the pipeline can handle."""

user_id: str
notes: str
user_id: str # type: ignore
notes: str # type: ignore

# Our existing data includes 2 top-level keys: recognized, unknown
existing_schemas = {
Expand Down Expand Up @@ -537,14 +536,13 @@ class MyRecognizedSchema(BaseModel):
assert recognized_item.notes == "updated notes"


@pytest.mark.asyncio
@pytest.mark.parametrize("strict_mode", [True, False, "ignore"])
async def test_e2e_existing_schema_policy_tuple_behavior(strict_mode):
class MyRecognizedSchema(BaseModel):
"""A recognized schema that the pipeline can handle."""

user_id: str
notes: str
user_id: str # type: ignore
notes: str # type: ignore

existing_schemas = [
(
Expand Down Expand Up @@ -655,7 +653,6 @@ class MyRecognizedSchema(BaseModel):
assert recognized_item.notes == "updated notes"


@pytest.mark.asyncio
@pytest.mark.parametrize("enable_inserts", [True, False])
async def test_enable_deletes_flow(enable_inserts: bool) -> None:
class MySchema(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/test_strict_existing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from unittest.mock import patch

import pytest
from langchain_openai import ChatOpenAI
Expand Down Expand Up @@ -260,7 +261,8 @@ def test_validate_existing_strictness(
):
"""Test various scenarios of validation."""
tools = {"DummySchema": DummySchema}
llm = ChatOpenAI(model="gpt-4o-mini")
with patch.dict("os.environ", {"OPENAI_API_KEY": "fake-api-key"}):
llm = ChatOpenAI(model="gpt-4o-mini")
extractor = _ExtractUpdates(
llm=llm, # We won't actually call the LLM here but we need it for parsing.
tools=tools,
Expand Down
8 changes: 5 additions & 3 deletions trustcall/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def __init__(
existing_schema_policy: bool | Literal["ignore"] = True,
):
new_tools: list = [PatchDoc]
tool_choice = PatchDoc.__name__ if not enable_deletes else "any"
tool_choice = "PatchDoc" if not enable_deletes else "any"
if enable_inserts: # Also let the LLM know that we can extract NEW schemas.
tools_ = [
schema
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def _tear_down(

async def ainvoke(
self, state: ExtendedExtractState, config: RunnableConfig
) -> dict:
) -> Command[Literal["sync", "__end__"]]:
"""Generate a JSONPatch to correct the validation error and heal the tool call.
Assumptions:
Expand All @@ -1075,7 +1075,9 @@ async def ainvoke(
goto=("sync",),
)

def invoke(self, state: ExtendedExtractState, config: RunnableConfig) -> dict:
def invoke(
self, state: ExtendedExtractState, config: RunnableConfig
) -> Command[Literal["sync", "__end__"]]:
try:
msg = self.bound.invoke(state.messages, config)
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 213ef53

Please sign in to comment.