Skip to content

Commit 26f9f21

Browse files
punitvararlouf
authored andcommitted
Add support for OpenAI style function call support
User should pass OpenAI style dictionary of function and it should be internally converted to same json schema as callable function (#1376)
1 parent ac49f57 commit 26f9f21

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

outlines/generate/json.py

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def json(
7171
regex_str = build_regex_from_schema(schema, whitespace_pattern)
7272
generator = regex(model, regex_str, sampler)
7373
generator.format_sequence = lambda x: pyjson.loads(x)
74+
elif isinstance(schema_object, dict) and schema_object.get("type") == "function":
75+
# Handle OpenAI function call format
76+
schema = pyjson.dumps(schema_object["function"]["parameters"])
77+
regex_str = build_regex_from_schema(schema, whitespace_pattern)
78+
generator = regex(model, regex_str, sampler)
79+
generator.format_sequence = lambda x: pyjson.loads(x)
7480
else:
7581
raise ValueError(
7682
f"Cannot parse schema {schema_object}. The schema must be either "

0 commit comments

Comments
 (0)