Skip to content

WecoAI Client

WecoAI

A client for the WecoAI function builder API that allows users to build and query specialized functions for GenAI tasks and features. The user must simply provide a task description to build a function, and then query the function with an input to get the result they need. Our client supports both synchronous and asynchronous request paradigms and uses HTTP/2 for faster communication with the API. Support for structured outputs, multimodality, grounding through web search and reasoning is included. For maximum control/flexibility, we recommend that users build functions on the WecoAI platform to leverage the full power of the API, then deploy it in production using this client.

__init__

__init__(api_key=None, timeout=120.0, http2=True)

Initializes the WecoAI client.

Parameters:

Name Type Description Default
api_key str

The API key used for authentication. If not provided, the client will attempt to read it from the environment variable - WECO_API_KEY.

None
timeout float

The timeout for the HTTP requests in seconds. Default is 120.

120.0
http2 bool

Whether to use HTTP/2 protocol for the HTTP requests. Default is True.

True

Raises:

Type Description
ValueError

If the API key is not provided to the client, is not set as an environment variable (WECO_API_KEY) or is not a string.

abuild async

abuild(task_description)

Build a specialized function for a task.

Parameters:

Name Type Description Default
task_description str

The description of the task for which the function is being built.

required

Returns:

Type Description
tuple[str, int, str]

A tuple containing the name, version number and description of the function.

aquery async

aquery(fn_name, version=-1, text_input='', images_input=[], return_reasoning=False, strict=False)

Queries a specific function with the input (text, images or both) asynchronously.

Parameters:

Name Type Description Default
fn_name str

The name of the function to query.

required
version Optional[Union[str, int]]

The version alias/number of the function to query. Default is -1 which results in the latest version being used.

-1
text_input str

The text input to the function.

''
images_input List[str]

A list of image URLs or base64 encoded images to be used as input to

[]
return_reasoning bool

A flag to indicate if the reasoning should be returned. Default is False.

False
strict bool

A flag to indicate if the function should be queried in strict mode where the inputs provided should match the input modalities of the LLM chosen for this function. For example, when strict is True, a text-image query to a function that uses a text-only LLM will raise an error. When strict is False, the function will attempt to handle the input by dropping the image components. Default is False.

False

Returns:

Type Description
dict

A dictionary containing the output of the function, the number of input tokens, the number of output tokens, and the latency in milliseconds.

batch_query

batch_query(fn_name, batch_inputs, version=-1, return_reasoning=False, strict=False)

Performs batch queries on a specified function version.

This method processes multiple inputs concurrently using asynchronous queries, ensuring that results are returned in the same order as the inputs.

Parameters:

Name Type Description Default
fn_name str

The name of the function to query.

required
batch_inputs List[Dict[str, Any]]

A list of input dictionaries for the function. Each dictionary can include: - "text_input": A string for text input. - "images_input": A list of image URLs or base64 encoded images.

required
version Union[str, int]

The version alias or number of the function to query. Defaults to -1 for the latest version.

-1
return_reasoning bool

If True, includes reasoning in the response. Defaults to False.

False
strict bool

A flag to indicate if the function should be queried in strict mode where the inputs provided should match the input modalities of the LLM chosen for this function. For example, when strict is True, a text-image query to a function that uses a text-only LLM will raise an error. When strict is False, the function will attempt to handle the input by dropping the image components. Default is False.

False

Returns:

Type Description
List[Dict[str, Any]]

A list of dictionaries, each containing the result of a function query, including: - The function's output. - The number of input tokens. - The number of output tokens. - The latency in milliseconds.

build

build(task_description)

Build a specialized function for a task.

Parameters:

Name Type Description Default
task_description str

The description of the task for which the function is being built.

required

Returns:

Type Description
tuple[str, int, str]

A tuple containing the name, version number and description of the function.

query

query(fn_name, version=-1, text_input='', images_input=[], return_reasoning=False, strict=False)

Queries a specific function with the input (text, images or both).

Parameters:

Name Type Description Default
fn_name str

The name of the function to query.

required
version str | int

The version alias/number of the function to query. Default is -1 which results in the latest version being used.

-1
text_input str

The text input to the function.

''
images_input List[str]

A list of image URLs or base64 encoded images to be used as input to the function.

[]
return_reasoning bool

A flag to indicate if the reasoning should be returned. Default is False.

False
strict bool

A flag to indicate if the function should be queried in strict mode where the inputs provided should match the input modalities of the LLM chosen for this function. For example, when strict is True, a text-image query to a function that uses a text-only LLM will raise an error. When strict is False, the function will attempt to handle the input by dropping the image components. Default is False.

False

Returns:

Type Description
dict

A dictionary containing the output of the function, the number of input tokens, the number of output tokens, and the latency in milliseconds.