task_operator
¤
Task implementation for openai operator.
Classes:
Name | Description |
---|---|
AzureOpenAITaskOperator |
Task implementation for openai operator that uses Azure as the llm provider. |
OpenAITaskOperator |
Task implementation for openai operator. This is a child of the BaseOperator class. See the BaseOperator class for further documentation. |
AzureOpenAITaskOperator
¤
Bases: OpenAITaskOperator
Task implementation for openai operator that uses Azure as the llm provider.
Attributes:
Name | Type | Description |
---|---|---|
llm |
AzureOpenAILLM
|
AzureOpenAILLM |
Methods:
Name | Description |
---|---|
_compile_input_placeholder |
Creates a placeholder for the input of the function. |
compile |
Implements the compile method of the BaseOperator class. |
compile_template |
Unique compilation method for the OpenAITaskOperator class. |
parse_output |
Parses the raw output from the LLM into the desired format that was set in the parsed object. |
predict |
Executes prediction using the LLM. |
Attributes:
Name | Type | Description |
---|---|---|
streaming |
bool
|
Returns whether the operator is streaming or not |
_compile_input_placeholder
¤
_compile_input_placeholder() -> str
Creates a placeholder for the input of the function. The input format is based on the function input schema.
Example
for example a function signature of:
def foo(a: int, b: str, c: float = 1.0):
will result in the following placeholder:
Inputs:
a: {a}
b: {b}
c: {c}
Source code in src/declarai/operators/openai_operators/task_operator.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
compile
¤
compile(**kwargs) -> CompiledTemplate
Implements the compile method of the BaseOperator class. Args: **kwargs:
Returns:
Type | Description |
---|---|
CompiledTemplate
|
Dict[str, List[Message]]: A dictionary containing a list of messages. |
Source code in src/declarai/operators/operator.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
compile_template
¤
compile_template() -> CompiledTemplate
Unique compilation method for the OpenAITaskOperator class. Uses the InstructFunctionTemplate and StructuredOutputInstructionPrompt templates to create a message. And the _compile_input_placeholder method to create a placeholder for the input of the function. Returns: Dict[str, List[Message]]: A dictionary containing a list of messages.
Source code in src/declarai/operators/openai_operators/task_operator.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
parse_output
¤
Parses the raw output from the LLM into the desired format that was set in the parsed object. Args: output: llm string output
Returns:
Type | Description |
---|---|
Any
|
Any parsed output |
Source code in src/declarai/operators/operator.py
111 112 113 114 115 116 117 118 119 120 |
|
predict
¤
predict(
*,
llm_params: Optional[LLMParamsType] = None,
**kwargs: object
) -> Union[LLMResponse, Iterator[LLMResponse]]
Executes prediction using the LLM.
It first compiles the prompts using the compile
method, and then executes the LLM with the compiled prompts and the llm_params.
Args:
llm_params: The parameters that are passed during runtime. If provided, they will override the ones provided during initialization.
**kwargs: The keyword arguments to pass to the compile
method. Used to format the prompts placeholders.
Returns:
Type | Description |
---|---|
Union[LLMResponse, Iterator[LLMResponse]]
|
The response from the LLM |
Source code in src/declarai/operators/operator.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
OpenAITaskOperator
¤
Bases: BaseOperator
Task implementation for openai operator. This is a child of the BaseOperator class. See the BaseOperator class for further documentation. Implements the compile method which compiles a parsed function into a message. Uses the OpenAILLM to generate a response based on the given template.
Attributes:
Name | Type | Description |
---|---|---|
llm |
OpenAILLM
|
OpenAILLM |
Methods:
Name | Description |
---|---|
_compile_input_placeholder |
Creates a placeholder for the input of the function. |
compile |
Implements the compile method of the BaseOperator class. |
compile_template |
Unique compilation method for the OpenAITaskOperator class. |
parse_output |
Parses the raw output from the LLM into the desired format that was set in the parsed object. |
predict |
Executes prediction using the LLM. |
Attributes:
Name | Type | Description |
---|---|---|
streaming |
bool
|
Returns whether the operator is streaming or not |
_compile_input_placeholder
¤
_compile_input_placeholder() -> str
Creates a placeholder for the input of the function. The input format is based on the function input schema.
Example
for example a function signature of:
def foo(a: int, b: str, c: float = 1.0):
will result in the following placeholder:
Inputs:
a: {a}
b: {b}
c: {c}
Source code in src/declarai/operators/openai_operators/task_operator.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
compile
¤
compile(**kwargs) -> CompiledTemplate
Implements the compile method of the BaseOperator class. Args: **kwargs:
Returns:
Type | Description |
---|---|
CompiledTemplate
|
Dict[str, List[Message]]: A dictionary containing a list of messages. |
Source code in src/declarai/operators/operator.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
compile_template
¤
compile_template() -> CompiledTemplate
Unique compilation method for the OpenAITaskOperator class. Uses the InstructFunctionTemplate and StructuredOutputInstructionPrompt templates to create a message. And the _compile_input_placeholder method to create a placeholder for the input of the function. Returns: Dict[str, List[Message]]: A dictionary containing a list of messages.
Source code in src/declarai/operators/openai_operators/task_operator.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
parse_output
¤
Parses the raw output from the LLM into the desired format that was set in the parsed object. Args: output: llm string output
Returns:
Type | Description |
---|---|
Any
|
Any parsed output |
Source code in src/declarai/operators/operator.py
111 112 113 114 115 116 117 118 119 120 |
|
predict
¤
predict(
*,
llm_params: Optional[LLMParamsType] = None,
**kwargs: object
) -> Union[LLMResponse, Iterator[LLMResponse]]
Executes prediction using the LLM.
It first compiles the prompts using the compile
method, and then executes the LLM with the compiled prompts and the llm_params.
Args:
llm_params: The parameters that are passed during runtime. If provided, they will override the ones provided during initialization.
**kwargs: The keyword arguments to pass to the compile
method. Used to format the prompts placeholders.
Returns:
Type | Description |
---|---|
Union[LLMResponse, Iterator[LLMResponse]]
|
The response from the LLM |
Source code in src/declarai/operators/operator.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|