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

Extract function name in get_schema_from_signature #878

Merged
merged 2 commits into from
May 8, 2024
Merged
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
11 changes: 10 additions & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import json
import re
import warnings
from typing import Callable, Optional

from jsonschema.protocols import Validator
Expand Down Expand Up @@ -375,6 +376,14 @@ def get_schema_from_signature(fn: Callable) -> str:
else:
arguments[name] = (arg.annotation, ...)

model = create_model("Arguments", **arguments)
try:
fn_name = fn.__name__
except Exception as e:
fn_name = "Arguments"
warnings.warn(
f"The function name could not be determined. Using default name 'Arguments' instead. For debugging, here is exact error:\n{e}",
category=UserWarning,
)
model = create_model(fn_name, **arguments)

return model.model_json_schema()
Loading