MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / _build_parameters_schema

Function _build_parameters_schema

utils/function_catalog.py:195–225  ·  view source on GitHub ↗
(signature: inspect.Signature, annotations: Mapping[str, Any])

Source from the content-addressed store, hash-verified

193
194
195def _build_parameters_schema(signature: inspect.Signature, annotations: Mapping[str, Any]) -> Dict[str, Any]:
196 properties: Dict[str, Any] = {}
197 required: List[str] = []
198
199 for param in signature.parameters.values():
200 if param.name.startswith("_"):
201 continue
202 if param.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
203 continue
204
205 annotation = annotations.get(param.name, inspect._empty)
206 annotation, meta = _unwrap_annotation(annotation)
207 annotation, optional_from_type = _strip_optional(annotation)
208 schema = _annotation_to_schema(annotation)
209 schema = _apply_param_meta(schema, meta)
210
211 if param.default is not inspect._empty:
212 schema.setdefault("default", param.default)
213
214 properties[param.name] = schema
215 is_required = param.default is inspect._empty and not optional_from_type
216 if is_required:
217 required.append(param.name)
218
219 payload: Dict[str, Any] = {
220 "type": "object",
221 "properties": properties,
222 }
223 if required:
224 payload["required"] = required
225 return payload
226
227
228def _unwrap_annotation(annotation: Any) -> Tuple[Any, ParamMeta | None]:

Callers 1

_build_function_metadataFunction · 0.85

Calls 5

_unwrap_annotationFunction · 0.85
_strip_optionalFunction · 0.85
_annotation_to_schemaFunction · 0.85
_apply_param_metaFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected