API Reference¶
AutoGenerator
¶
Source code in praisonai/auto.py
27 28 29 30 31 32 33 34 35 36 37 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 182 183 184 185 186 |
|
__init__(topic='Movie Story writing about AI', agent_file='test.yaml', framework='crewai', config_list=None)
¶
Initialize the AutoGenerator class with the specified topic, agent file, and framework. Note: autogen framework is different from this AutoGenerator class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
The topic for the generated team structure. Defaults to "Movie Story writing about AI". |
'Movie Story writing about AI'
|
agent_file |
str
|
The name of the YAML file to save the generated team structure. Defaults to "test.yaml". |
'test.yaml'
|
framework |
str
|
The framework for the generated team structure. Defaults to "crewai". |
'crewai'
|
config_list |
Optional[List[Dict]]
|
A list containing the configuration details for the OpenAI API. If None, it defaults to using environment variables or hardcoded values. |
None
|
Attributes: config_list (list): A list containing the configuration details for the OpenAI API. topic (str): The specified topic for the generated team structure. agent_file (str): The specified name of the YAML file to save the generated team structure. framework (str): The specified framework for the generated team structure. client (instructor.Client): An instance of the instructor.Client class initialized with the specified OpenAI API configuration.
Source code in praisonai/auto.py
28 29 30 31 32 33 34 35 36 37 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 |
|
convert_and_save(json_data)
¶
Converts the provided JSON data into the desired YAML format and saves it to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data |
dict
|
The JSON data representing the team structure. |
required |
topic |
str
|
The topic to be inserted into the YAML. Defaults to "Artificial Intelligence". |
required |
agent_file |
str
|
The name of the YAML file to save. Defaults to "test.yaml". |
required |
Source code in praisonai/auto.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
generate()
¶
Generates a team structure for the specified topic.
Returns:
Name | Type | Description |
---|---|---|
str |
The full path of the YAML file containing the generated team structure. |
Raises:
Type | Description |
---|---|
Exception
|
If the generation process fails. |
Usage
generator = AutoGenerator(framework="crewai", topic="Create a movie script about Cat in Mars") path = generator.generate() print(path)
Source code in praisonai/auto.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
get_user_content()
¶
Generates a prompt for the OpenAI API to generate a team structure.
Returns:
Name | Type | Description |
---|---|---|
str |
The prompt for the OpenAI API. |
Usage
generator = AutoGenerator(framework="crewai", topic="Create a movie script about Cat in Mars") prompt = generator.get_user_content() print(prompt)
Source code in praisonai/auto.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 182 183 184 185 186 |
|
AgentsGenerator
¶
Source code in praisonai/agents_generator.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 182 183 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
__init__(agent_file, framework, config_list, log_level=None, agent_callback=None, task_callback=None, agent_yaml=None)
¶
Initialize the AgentsGenerator object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_file |
str
|
The path to the agent file. |
required |
framework |
str
|
The framework to be used for the agents. |
required |
config_list |
list
|
A list of configurations for the agents. |
required |
log_level |
int
|
The logging level to use. Defaults to logging.INFO. |
None
|
agent_callback |
callable
|
A callback function to be executed after each agent step. |
None
|
task_callback |
callable
|
A callback function to be executed after each tool run. |
None
|
agent_yaml |
str
|
The content of the YAML file. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
agent_file |
str
|
The path to the agent file. |
framework |
str
|
The framework to be used for the agents. |
config_list |
list
|
A list of configurations for the agents. |
log_level |
int
|
The logging level to use. |
agent_callback |
callable
|
A callback function to be executed after each agent step. |
task_callback |
callable
|
A callback function to be executed after each tool run. |
Source code in praisonai/agents_generator.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
generate_crew_and_kickoff()
¶
Generates a crew of agents and initiates tasks based on the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_file |
str
|
The path to the agent file. |
required |
framework |
str
|
The framework to be used for the agents. |
required |
config_list |
list
|
A list of configurations for the agents. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The output of the tasks performed by the crew of agents. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified agent file does not exist. |
This function first loads the agent configuration from the specified file. It then initializes the tools required for the agents based on the specified framework. If the specified framework is "autogen", it loads the LLM configuration dynamically and creates an AssistantAgent for each role in the configuration. It then adds tools to the agents if specified in the configuration. Finally, it prepares tasks for the agents based on the configuration and initiates the tasks using the crew of agents. If the specified framework is not "autogen", it creates a crew of agents and initiates tasks based on the configuration.
Source code in praisonai/agents_generator.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
is_function_or_decorated(obj)
¶
Checks if the given object is a function or has a call method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
object
|
The object to be checked. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the object is a function or has a call method, False otherwise. |
Source code in praisonai/agents_generator.py
86 87 88 89 90 91 92 93 94 95 96 |
|
load_tools_from_module(module_path)
¶
Loads tools from a specified module path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_path |
str
|
The path to the module containing the tools. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the names of the tools as keys and the corresponding functions or objects as values. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified module path does not exist. |
Source code in praisonai/agents_generator.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
load_tools_from_module_class(module_path)
¶
Loads tools from a specified module path containing classes that inherit from BaseTool or are part of langchain_community.tools package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_path |
str
|
The path to the module containing the tools. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the names of the tools as keys and the corresponding initialized instances of the classes as values. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified module path does not exist. |
Source code in praisonai/agents_generator.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
load_tools_from_package(package_path)
¶
Loads tools from a specified package path containing modules with functions or classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_path |
str
|
The path to the package containing the tools. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the names of the tools as keys and the corresponding initialized instances of the classes as values. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified package path does not exist. |
This function iterates through all the .py files in the specified package path, excluding those that start with "__". For each file, it imports the corresponding module and checks if it contains any functions or classes that can be loaded as tools. The function then returns a dictionary containing the names of the tools as keys and the corresponding initialized instances of the classes as values.
Source code in praisonai/agents_generator.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
PraisonAI
¶
Source code in praisonai/cli.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 182 183 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
__init__(agent_file='agents.yaml', framework='', auto=False, init=False, agent_yaml=None)
¶
Initialize the PraisonAI object with default parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_file |
str
|
The default agent file to use. Defaults to "agents.yaml". |
'agents.yaml'
|
framework |
str
|
The default framework to use. Defaults to "crewai". |
''
|
auto |
bool
|
A flag indicating whether to enable auto mode. Defaults to False. |
False
|
init |
bool
|
A flag indicating whether to enable initialization mode. Defaults to False. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
config_list |
list
|
A list of configuration dictionaries for the OpenAI API. |
agent_file |
str
|
The agent file to use. |
framework |
str
|
The framework to use. |
auto |
bool
|
A flag indicating whether to enable auto mode. |
init |
bool
|
A flag indicating whether to enable initialization mode. |
agent_yaml |
str
|
The content of the YAML file. Defaults to None. |
Source code in praisonai/cli.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
create_chainlit_chat_interface()
¶
Create a Chainlit interface for the chat application.
This function sets up a Chainlit application that listens for messages. When a message is received, it runs PraisonAI with the provided message as the topic. The generated agents are then used to perform tasks.
Returns:
Name | Type | Description |
---|---|---|
None |
This function does not return any value. It starts the Chainlit application. |
Source code in praisonai/cli.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
create_chainlit_interface()
¶
Create a Chainlit interface for generating agents and performing tasks.
This function sets up a Chainlit application that listens for messages. When a message is received, it runs PraisonAI with the provided message as the topic. The generated agents are then used to perform tasks.
Returns:
Name | Type | Description |
---|---|---|
None |
This function does not return any value. It starts the Chainlit application. |
Source code in praisonai/cli.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
create_code_interface()
¶
Create a Chainlit interface for the code application.
This function sets up a Chainlit application that listens for messages. When a message is received, it runs PraisonAI with the provided message as the topic. The generated agents are then used to perform tasks.
Returns:
Name | Type | Description |
---|---|---|
None |
This function does not return any value. It starts the Chainlit application. |
Source code in praisonai/cli.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
create_gradio_interface()
¶
Create a Gradio interface for generating agents and performing tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
PraisonAI
|
An instance of the PraisonAI class. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
This method does not return any value. It launches the Gradio interface. |
Raises:
Type | Description |
---|---|
None
|
This method does not raise any exceptions. |
Example
praison_ai.create_gradio_interface()
Source code in praisonai/cli.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
create_realtime_interface()
¶
Create a Chainlit interface for the realtime voice interaction application.
Source code in praisonai/cli.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
main()
¶
The main function of the PraisonAI object. It parses the command-line arguments, initializes the necessary attributes, and then calls the appropriate methods based on the provided arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
PraisonAI
|
An instance of the PraisonAI class. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Depending on the arguments provided, the function may return a result from the |
|
AgentsGenerator, a deployment result from the CloudDeployer, or a message indicating |
||
the successful creation of a file. |
Source code in praisonai/cli.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 182 183 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 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
parse_args()
¶
Parse the command-line arguments for the PraisonAI CLI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
PraisonAI
|
An instance of the PraisonAI class. |
required |
Returns:
Type | Description |
---|---|
argparse.Namespace: An object containing the parsed command-line arguments. |
Raises:
Type | Description |
---|---|
ArgumentError
|
If the arguments provided are invalid. |
Example
args = praison_ai.parse_args() print(args.agent_file) # Output: 'agents.yaml'
Source code in praisonai/cli.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
run()
¶
Run the PraisonAI application.
Source code in praisonai/cli.py
94 95 96 97 98 |
|
stream_subprocess(command, env=None)
¶
Execute a subprocess command and stream the output to the terminal in real-time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
list
|
A list containing the command and its arguments. |
required |
env |
dict
|
Environment variables for the subprocess. |
None
|
Source code in praisonai/cli.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
CloudDeployer
¶
A class for deploying a cloud-based application.
Methods:
Name | Description |
---|---|
__init__ |
Loads environment variables from .env file or system and sets them. |
Source code in praisonai/deploy.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
__init__()
¶
Loads environment variables from .env file or system and sets them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
An instance of the CloudDeployer class. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in praisonai/deploy.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
create_api_file()
¶
Creates an API file for the application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
CloudDeployer
|
An instance of the CloudDeployer class. |
required |
Returns:
Type | Description |
---|---|
None |
This method creates an API file named "api.py" in the current directory. The file contains a basic Flask application that uses the PraisonAI library to run a simple agent and returns the output as an HTML page. The application listens on the root path ("/") and uses the Markdown library to format the output.
Source code in praisonai/deploy.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
create_dockerfile()
¶
Creates a Dockerfile for the application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
An instance of the CloudDeployer class. |
required |
Returns:
Type | Description |
---|---|
None |
This method creates a Dockerfile in the current directory with the specified content. The Dockerfile is used to build a Docker image for the application. The content of the Dockerfile includes instructions to use the Python 3.11-slim base image, set the working directory to /app, copy the current directory contents into the container, install the required Python packages (flask, praisonai, gunicorn, and markdown), expose port 8080, and run the application using Gunicorn.
Source code in praisonai/deploy.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
run_commands()
¶
Sets environment variables with fallback to .env values or defaults.
Returns:
Type | Description |
---|---|
None |
This method sets environment variables for the application. It uses the os.environ
dictionary to set the following environment variables:
OPENAI_MODEL_NAME
: The name of the OpenAI model to use. If not specified in the .env file, it defaults to "gpt-4o".OPENAI_API_KEY
: The API key for accessing the OpenAI API. If not specified in the .env file, it defaults to "Enter your API key".OPENAI_API_BASE
: The base URL for the OpenAI API. If not specified in the .env file, it defaults to "https://api.openai.com/v1".
Source code in praisonai/deploy.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
set_environment_variables()
¶
Sets environment variables with fallback to .env values or defaults.
Source code in praisonai/deploy.py
91 92 93 94 95 |
|