Add json_schema decorator
This commit is contained in:
parent
ee288915d7
commit
156eed9024
|
@ -1817,6 +1817,11 @@ class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin):
|
|||
conversations = [conversation]
|
||||
is_batched = False
|
||||
|
||||
# The add_json_schema decorator for tools adds a schema under the `json_schema` attribute. If we're passed
|
||||
# decorated functions, let's extract the schema decoration now
|
||||
if tools is not None:
|
||||
tools = [tool.json_schema if hasattr(tool, "json_schema") else tool for tool in tools]
|
||||
|
||||
rendered = []
|
||||
template_kwargs = {**self.special_tokens_map, **kwargs} # kwargs overwrite special tokens if both are present
|
||||
for chat in conversations:
|
||||
|
|
|
@ -24,6 +24,11 @@ def get_json_schema(func):
|
|||
return {"name": func.__name__, "description": main_doc, "parameters": json_schema}
|
||||
|
||||
|
||||
def add_json_schema(func):
|
||||
func.json_schema = get_json_schema(func)
|
||||
return func
|
||||
|
||||
|
||||
def _get_argument_descriptions_from_docstring(doc):
|
||||
param_pattern = r":param (\w+): (.+)"
|
||||
params = re.findall(param_pattern, doc)
|
||||
|
|
Loading…
Reference in New Issue