API Reference

LLM API

Messages

class wanga.models.messages.ImageContent(url: str | None = None, base64: str | None = None)[source]

Image embedded in a message. Can either be a URL, or a base64-encoded file.

Models

exception wanga.models.model.AuthenticationError[source]

Raised when the API credentials are invalid.

class wanga.models.model.FinishReason(value)[source]

An enumeration.

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.ModelError[source]

Base class for all exceptions raised by models.

exception wanga.models.model.ModelTimeoutError[source]

Raised when the model takes too long to generate a response.

exception wanga.models.model.PromptError[source]

Raised when the prompt is malformed or uses unsupported features.

exception wanga.models.model.RateLimitError[source]

Raised when the request limit is exceeded.

exception wanga.models.model.ServiceUnvailableError[source]

Raised when the API is down.

class wanga.models.model.ToolUseMode(value)[source]

An enumeration.

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.

exception wanga.schema.SchemaValidationError[source]

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.