Skip to content

operators ¤

Operators are the main interface that interacts internally with the LLMs.

Modules:

Name Description
llm

This module defines the base classes for the LLM interface.

message

Message definition for the operators.

openai_operators

OpenAI operators and LLMs.

operator

Operator is a class that is used to wrap the compilation of prompts and the singular execution of the LLM.

registry

Registry for LLMs and Operators.

templates

This module contains the shared templates for the operators.

utils

Functions:

Name Description
resolve_llm

Resolves an LLM instance based on the provider and model name.

resolve_operator

Resolves an operator based on the LLM instance and the operator type.

Attributes:

Name Type Description
ModelsOpenai

All official OpenAI models

ModelsOpenai module-attribute ¤

ModelsOpenai = Literal[
    "gpt-4",
    "gpt-3.5-turbo",
    "gpt-3.5-turbo-16k",
    "text-davinci-003",
    "text-davinci-002",
    "code-davinci-002",
]

All official OpenAI models

resolve_llm ¤

resolve_llm(
    provider: str, model: str = None, **kwargs: str
) -> LLM

Resolves an LLM instance based on the provider and model name.

Parameters:

Name Type Description Default
provider str

Name of the provider

required
model str

Name of the model

None
**kwargs

Additional arguments to pass to the LLM initialization

{}

Returns:

Name Type Description
llm LLM

instance

Source code in src/declarai/operators/__init__.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def resolve_llm(provider: str, model: str = None, **kwargs) -> LLM:
    """
    Resolves an LLM instance based on the provider and model name.

    Args:
        provider: Name of the provider
        model: Name of the model
        **kwargs: Additional arguments to pass to the LLM initialization

    Returns:
        llm (LLM): instance
    """
    if provider == ProviderOpenai:
        model = LLMSettings(
            provider=provider,
            model=model,
            version=kwargs.pop("version", None),
            **kwargs,
        ).model

    llm_instance = llm_registry.resolve(provider, model, **kwargs)
    return llm_instance

resolve_operator ¤

resolve_operator(llm_instance: LLM, operator_type: str)

Resolves an operator based on the LLM instance and the operator type.

Parameters:

Name Type Description Default
llm_instance LLM

instance of initialized LLM

required
operator_type Type[BaseOperator]

task or chat

required

Returns:

Type Description

Operator type class

Source code in src/declarai/operators/__init__.py
75
76
77
78
79
80
81
82
83
84
85
86
87
def resolve_operator(llm_instance: LLM, operator_type: str):
    """
    Resolves an operator based on the LLM instance and the operator type.

    Args:
        llm_instance: instance of initialized LLM
        operator_type (Type[BaseOperator]): task or chat

    Returns:
        Operator type class

    """
    return operator_registry.resolve(llm_instance, operator_type)