Source code for langchain.chains.openai_functions.utils
fromtypingimportAny,Dictdef_resolve_schema_references(schema:Any,definitions:Dict[str,Any])->Any:""" Resolve the $ref keys in a JSON schema object using the provided definitions. """ifisinstance(schema,list):fori,iteminenumerate(schema):schema[i]=_resolve_schema_references(item,definitions)elifisinstance(schema,dict):if"$ref"inschema:ref_key=schema.pop("$ref").split("/")[-1]ref=definitions.get(ref_key,{})schema.update(ref)else:forkey,valueinschema.items():schema[key]=_resolve_schema_references(value,definitions)returnschemadef_convert_schema(schema:dict)->dict:props={k:{"title":k,**v}fork,vinschema["properties"].items()}return{"type":"object","properties":props,"required":schema.get("required",[]),}
[docs]defget_llm_kwargs(function:dict)->dict:"""Return the kwargs for the LLMChain constructor. Args: function: The function to use. Returns: The kwargs for the LLMChain constructor. """return{"functions":[function],"function_call":{"name":function["name"]}}