OpenAITool

OpenAITool is a class in the OpenAI language learning model (LLM) that helps in using the OpenAI agent. By standardizing the necessary components like the properties and required attributes needed for OpenAI functions, it offers structured integration and usage of OpenAI.

Overview

OpenAITool helps streamline operations with the OpenAI agent. It holds the properties required to use the OpenAI function. The required properties and a list of optional properties are stored in a dictionary, with the function and its description stored separately. Upon initialization, the function, name, description, properties, and the required list are passed to set up the tool.

Example

The following is an example demonstrating how to use the OpenAITool class.

from automata.llm.providers.openai_llm import OpenAITool

def my_function(input_string):
    # insert function logic here
    pass

properties = {
    'property_1': {'description': 'description', 'type': 'str'},
    'property_2': {'description': 'description', 'type': 'int'}
}

openai_tool = OpenAITool(
   function=my_function,
   name="OpenAI Tool",
   description="This is a generic function description.",
   properties=properties,
   required=['property_1', 'property_2']
)

In this example, we have created a new instance of OpenAITool with a dummy function my_function, a name, description, a dictionary of properties and a list of required properties.

Limitations

The OpenAITool class relies on the OpenAIFunction for its functioning. It ensures the required properties for the OpenAI function are available and correctly formatted. However, it doesn’t provide explicit error handling or checks for the function itself. As such, it assumes that the function provided during instantiation is correct and valid. Any errors within the function can lead to a breakdown in the operations of the OpenAITool object.

Follow-up Questions:

  • How is error handling performed within OpenAITool beyond property validation?

  • Is there a way to update the properties of OpenAITool instances after creation?

  • Could we improve the OpenAITool class by adding type checking for the input function during instantiation?