declarai
¤
Main interface for declarai.
Decorates the package functionalities and serve as the main interface for the user.
Classes:
Name | Description |
---|---|
Declarai |
Context manager for the Declarai root interface. |
Functions:
Name | Description |
---|---|
azure_openai |
Sets up a Declarai context for the Azure OpenAI provider. |
magic |
This is an empty method used as a potential replacement for using the docstring for passing |
openai |
Sets up a Declarai context for the OpenAI provider. |
register_llm |
Registers an LLM. |
register_operator |
Registers an operator. |
Declarai
¤
Context manager for the Declarai root interface. This class is responsible for setting up tasks and initializing experimental features provided by Declarai.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider |
str
|
The provider name. |
required |
model |
str
|
The model name. |
required |
**kwargs |
Additional keyword arguments passed to the LLM resolver. |
{}
|
Attributes:
Name | Type | Description |
---|---|---|
llm |
LLM
|
Resolved LLM. |
task |
Callable
|
A decorator for task creation. |
experimental |
A namespace for experimental features. |
|
experimental.chat |
Callable
|
A decorator for chat operators. |
Source code in src/declarai/declarai.py
138 139 140 141 142 143 144 145 |
|
azure_openai
¤
azure_openai(
deployment_name: str,
azure_openai_key: str = None,
azure_openai_api_base: str = None,
api_version: str = None,
headers: dict = None,
timeout: int = None,
stream: bool = None,
request_timeout: int = None,
) -> Declarai
Sets up a Declarai context for the Azure OpenAI provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment_name |
str
|
Name of the deployment. |
required |
azure_openai_key |
str
|
Azure OpenAI key. |
None
|
azure_openai_api_base |
str
|
Base API URL for Azure OpenAI. |
None
|
api_version |
str
|
API version. |
None
|
headers |
dict
|
Additional headers for the request. |
None
|
timeout |
int
|
Timeout for the request. |
None
|
stream |
bool
|
Whether to stream the response. |
None
|
request_timeout |
int
|
Request timeout duration. |
None
|
Returns:
Name | Type | Description |
---|---|---|
DeclaraiContext |
Declarai
|
Initialized Declarai context. |
Source code in src/declarai/declarai.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
magic
¤
magic(
return_name: Optional[str] = None,
*,
task_desc: Optional[str] = None,
input_desc: Optional[Dict[str, str]] = None,
output_desc: Optional[str] = None,
**kwargs: Optional[str]
) -> Any
This is an empty method used as a potential replacement for using the docstring for passing parameters to the LLM builder. It can also serve as a fake use of arguments in the defined functions as to simplify handling of lint rules for llms functions.
Example
@openai.task
def add(a: int, b: int) -> int:
return magic(a, b)
Source code in src/declarai/declarai.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
openai
¤
openai(
model: ModelsOpenai,
version: str = None,
openai_token: str = None,
headers: dict = None,
timeout: int = None,
stream: bool = None,
request_timeout: int = None,
) -> Declarai
Sets up a Declarai context for the OpenAI provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
ModelsOpenai
|
The model to be used. |
required |
version |
str
|
Model version. |
None
|
openai_token |
str
|
OpenAI authentication token. |
None
|
headers |
dict
|
Additional headers for the request. |
None
|
timeout |
int
|
Timeout for the request. |
None
|
stream |
bool
|
Whether to stream the response. |
None
|
request_timeout |
int
|
Request timeout duration. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Declarai |
Declarai
|
Initialized Declarai context. |
Source code in src/declarai/declarai.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
register_llm
¤
Registers an LLM. Args: provider: Name of the LLM provider. model: Specific model name (optional). llm_cls: The LLM class to register.
Source code in src/declarai/declarai.py
223 224 225 226 227 228 229 230 231 |
|
register_operator
¤
register_operator(
provider: str,
operator_type: str,
operator_cls: Type[BaseOperator],
model: str = None,
)
Registers an operator. Args: provider: Name of the LLM provider. operator_type: The type of operator (e.g., "chat", "task"). operator_cls: The operator class to register. model: Specific model name
Source code in src/declarai/declarai.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|