Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify method for with_structured_output #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ def __init__(
relationship_properties: Union[bool, List[str]] = False,
ignore_tool_usage: bool = False,
additional_instructions: str = "",
method: str = "json_schema",
efriis marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
# Validate and check allowed relationships input
self._relationship_type = validate_and_get_relationship_type(
Expand All @@ -784,7 +785,7 @@ def __init__(
# Check if the LLM really supports structured output
if self._function_call:
try:
llm.with_structured_output(_Graph)
llm.with_structured_output(_Graph, method=method)
except NotImplementedError:
self._function_call = False
if not self._function_call:
Expand Down Expand Up @@ -824,7 +825,9 @@ def __init__(
relationship_properties,
self._relationship_type,
)
structured_llm = llm.with_structured_output(schema, include_raw=True)
structured_llm = llm.with_structured_output(
schema, method=method, include_raw=True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misunderstood - let's pass this in as a kwarg when it's defined, but let's remove the default of json_schema above.

Also open to something more general like structured_output_kwargs: Optional[dict] where you'd achieve this with structured_output_kwargs={"method": "json_schema"}

)
prompt = prompt or get_default_prompt(additional_instructions)
self.chain = prompt | structured_llm

Expand Down