API Reference
LLM API
Messages
Models
- exception wanga.models.model.AuthenticationError[source]
Raised when the API credentials are invalid.
- exception wanga.models.model.InvalidJsonError[source]
Raised when the model returns a malformed JSON as a response to a function call.
- exception wanga.models.model.ModelTimeoutError[source]
Raised when the model takes too long to generate a response.
Schema extraction and manipulation
Schema Definition
- class wanga.schema.CallableSchema(call_schema: ObjectNode, return_schema: SchemaNode, long_description: str | None)[source]
Complete schema of a function or a class.
- call_schema
Schema of the function call.
- Type:
wanga.schema.schema.ObjectNode
- return_schema
Schema of the return value. None if the function returns None.
- Type:
wanga.schema.schema.SchemaNode
- long_description
Long description extracted from the docstring. It is used to pass tool descriptions to LLMs. It is not used for return values.
- Type:
str | None
- eval(value: str | float | int | bool | None | dict[str, JSON] | list[JSON])[source]
Call the callable with the given JSON value.
- json_schema(flavor: JsonSchemaFlavor, include_long_description: bool = False) AnthropicCallableSchema | OpenAICallableSchema [source]
Extract JSON Schema to use with the LLM function call APIs.
- Parameters:
flavor – Flavor of the JSON Schema syntax accepted by the target API.
include_long_description – Whether to include long_description to the description field of the resulting JSON Schema. Should be set to True for tools, and to False for object constructions.
- class wanga.schema.JsonSchemaFlavor(value)[source]
Top-level layout of the JSON schema as accepted by different LLMS.
- class wanga.schema.SchemaExtractor(exctractor_fns: list[Callable[[Any], CallableSchema | None]] = NOTHING)[source]
Extracts schemas from callables.
Should never be initialized directly by the end user, instead, use wanga.schema.default_schema_extractor. If you want to add new extraction functions, use the register_extract_fn method.
- extractor_functions
List of functions that take type annotation as an input and try to produce the CallableSchema.
- extract_schema(callable: Callable) CallableSchema [source]
Extract schema from a callable.
Schema Extraction
- class wanga.schema.extractor.SchemaExtractor(exctractor_fns: list[Callable[[Any], CallableSchema | None]] = NOTHING)[source]
Extracts schemas from callables.
Should never be initialized directly by the end user, instead, use wanga.schema.default_schema_extractor. If you want to add new extraction functions, use the register_extract_fn method.
- extractor_functions
List of functions that take type annotation as an input and try to produce the CallableSchema.
- extract_schema(callable: Callable) CallableSchema [source]
Extract schema from a callable.