Skip to content

Commit 3e80613

Browse files
committed
Add support for the Outlines model
1 parent bfbf2ca commit 3e80613

File tree

9 files changed

+3233
-29
lines changed

9 files changed

+3233
-29
lines changed

pydantic_ai_slim/pydantic_ai/_output.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,25 +556,29 @@ def __init__(
556556
def mode(self) -> OutputMode:
557557
return 'prompted'
558558

559+
@classmethod
560+
def build_instructions(cls, template: str, object_def: OutputObjectDefinition) -> str:
561+
"""Build instructions from a template and an object definition."""
562+
schema = object_def.json_schema.copy()
563+
if object_def.name:
564+
schema['title'] = object_def.name
565+
if object_def.description:
566+
schema['description'] = object_def.description
567+
568+
if '{schema}' not in template:
569+
template = '\n\n'.join([template, '{schema}'])
570+
571+
return template.format(schema=json.dumps(schema))
572+
559573
def raise_if_unsupported(self, profile: ModelProfile) -> None:
560574
"""Raise an error if the mode is not supported by this model."""
561575
super().raise_if_unsupported(profile)
562576

563577
def instructions(self, default_template: str) -> str:
564578
"""Get instructions to tell model to output JSON matching the schema."""
565579
template = self.template or default_template
566-
567-
if '{schema}' not in template:
568-
template = '\n\n'.join([template, '{schema}'])
569-
570580
object_def = self.object_def
571-
schema = object_def.json_schema.copy()
572-
if object_def.name:
573-
schema['title'] = object_def.name
574-
if object_def.description:
575-
schema['description'] = object_def.description
576-
577-
return template.format(schema=json.dumps(schema))
581+
return self.build_instructions(template, object_def)
578582

579583

580584
@dataclass(init=False)

0 commit comments

Comments
 (0)