praisonaiagents 0.0.60__py3-none-any.whl → 0.0.61__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- praisonaiagents/__init__.py +2 -0
- praisonaiagents/agent/__init__.py +2 -1
- praisonaiagents/agent/agent.py +0 -1
- praisonaiagents/agent/image_agent.py +213 -0
- praisonaiagents/agents/autoagents.py +2 -2
- praisonaiagents/llm/llm.py +1 -1
- praisonaiagents/tools/train/data/generatecot.py +2 -4
- {praisonaiagents-0.0.60.dist-info → praisonaiagents-0.0.61.dist-info}/METADATA +1 -1
- {praisonaiagents-0.0.60.dist-info → praisonaiagents-0.0.61.dist-info}/RECORD +11 -10
- {praisonaiagents-0.0.60.dist-info → praisonaiagents-0.0.61.dist-info}/WHEEL +0 -0
- {praisonaiagents-0.0.60.dist-info → praisonaiagents-0.0.61.dist-info}/top_level.txt +0 -0
praisonaiagents/__init__.py
CHANGED
@@ -3,6 +3,7 @@ Praison AI Agents - A package for hierarchical AI agent task execution
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
from .agent.agent import Agent
|
6
|
+
from .agent.image_agent import ImageAgent
|
6
7
|
from .agents.agents import PraisonAIAgents
|
7
8
|
from .task.task import Task
|
8
9
|
from .tools.tools import Tools
|
@@ -30,6 +31,7 @@ Agents = PraisonAIAgents
|
|
30
31
|
|
31
32
|
__all__ = [
|
32
33
|
'Agent',
|
34
|
+
'ImageAgent',
|
33
35
|
'PraisonAIAgents',
|
34
36
|
'Agents',
|
35
37
|
'Tools',
|
praisonaiagents/agent/agent.py
CHANGED
@@ -0,0 +1,213 @@
|
|
1
|
+
"""
|
2
|
+
ImageAgent - A specialized agent class for generating images using AI models.
|
3
|
+
|
4
|
+
This class extends the base Agent class to provide specific functionality for image generation,
|
5
|
+
including support for different image models, sizes, and quality settings.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from typing import Optional, Any, Dict, Union, List
|
9
|
+
from ..agent.agent import Agent
|
10
|
+
from pydantic import BaseModel, Field
|
11
|
+
import logging
|
12
|
+
import warnings
|
13
|
+
|
14
|
+
# Filter out Pydantic warning about fields
|
15
|
+
warnings.filterwarnings("ignore", "Valid config keys have changed in V2", UserWarning)
|
16
|
+
|
17
|
+
from rich.console import Console
|
18
|
+
from rich.panel import Panel
|
19
|
+
from rich.progress import Progress, SpinnerColumn, TextColumn
|
20
|
+
|
21
|
+
class ImageGenerationConfig(BaseModel):
|
22
|
+
"""Configuration for image generation settings."""
|
23
|
+
style: str = Field(default="natural", description="Style of the generated image")
|
24
|
+
response_format: str = Field(default="url", description="Format of the response (url or b64_json)")
|
25
|
+
timeout: int = Field(default=600, description="Timeout in seconds for the API call")
|
26
|
+
api_base: Optional[str] = Field(default=None, description="Optional API base URL")
|
27
|
+
api_key: Optional[str] = Field(default=None, description="Optional API key")
|
28
|
+
api_version: Optional[str] = Field(default=None, description="Optional API version (required for Azure dall-e-3)")
|
29
|
+
|
30
|
+
class ImageAgent(Agent):
|
31
|
+
"""
|
32
|
+
A specialized agent for generating images using AI models.
|
33
|
+
|
34
|
+
This agent extends the base Agent class with specific functionality for image generation,
|
35
|
+
including support for different models, sizes, and quality settings.
|
36
|
+
"""
|
37
|
+
|
38
|
+
def __init__(
|
39
|
+
self,
|
40
|
+
name: Optional[str] = None,
|
41
|
+
role: Optional[str] = None,
|
42
|
+
goal: Optional[str] = None,
|
43
|
+
backstory: Optional[str] = None,
|
44
|
+
instructions: Optional[str] = None,
|
45
|
+
llm: Optional[Union[str, Any]] = None,
|
46
|
+
style: str = "natural",
|
47
|
+
response_format: str = "url",
|
48
|
+
timeout: int = 600,
|
49
|
+
api_base: Optional[str] = None,
|
50
|
+
api_key: Optional[str] = None,
|
51
|
+
api_version: Optional[str] = None,
|
52
|
+
verbose: Union[bool, int] = True,
|
53
|
+
**kwargs
|
54
|
+
):
|
55
|
+
"""Initialize ImageAgent with parameters."""
|
56
|
+
# Set default role and goal if not provided
|
57
|
+
role = role or "Image Generation Assistant"
|
58
|
+
goal = goal or "Generate high-quality images based on text descriptions"
|
59
|
+
backstory = backstory or "I am an AI assistant specialized in generating images from textual descriptions"
|
60
|
+
|
61
|
+
# Initialize the base agent
|
62
|
+
super().__init__(
|
63
|
+
name=name,
|
64
|
+
role=role,
|
65
|
+
goal=goal,
|
66
|
+
backstory=backstory,
|
67
|
+
instructions=instructions,
|
68
|
+
llm=llm,
|
69
|
+
verbose=verbose,
|
70
|
+
**kwargs
|
71
|
+
)
|
72
|
+
|
73
|
+
# Store image generation configuration
|
74
|
+
self.image_config = ImageGenerationConfig(
|
75
|
+
style=style,
|
76
|
+
response_format=response_format,
|
77
|
+
timeout=timeout,
|
78
|
+
api_base=api_base,
|
79
|
+
api_key=api_key,
|
80
|
+
api_version=api_version
|
81
|
+
)
|
82
|
+
|
83
|
+
# Lazy load litellm
|
84
|
+
self._litellm = None
|
85
|
+
|
86
|
+
# Configure logging based on verbose level
|
87
|
+
self._configure_logging(verbose)
|
88
|
+
|
89
|
+
def _configure_logging(self, verbose: Union[bool, int]) -> None:
|
90
|
+
"""Configure logging levels based on verbose setting."""
|
91
|
+
# Only suppress logs if not in debug mode
|
92
|
+
if not isinstance(verbose, bool) and verbose >= 10:
|
93
|
+
# Enable detailed debug logging
|
94
|
+
logging.getLogger("asyncio").setLevel(logging.DEBUG)
|
95
|
+
logging.getLogger("selector_events").setLevel(logging.DEBUG)
|
96
|
+
logging.getLogger("litellm.utils").setLevel(logging.DEBUG)
|
97
|
+
logging.getLogger("litellm.main").setLevel(logging.DEBUG)
|
98
|
+
if hasattr(self, 'litellm'):
|
99
|
+
self.litellm.suppress_debug_messages = False
|
100
|
+
self.litellm.set_verbose = True
|
101
|
+
# Don't filter warnings in debug mode
|
102
|
+
warnings.resetwarnings()
|
103
|
+
else:
|
104
|
+
# Suppress debug logging for normal operation
|
105
|
+
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
106
|
+
logging.getLogger("selector_events").setLevel(logging.WARNING)
|
107
|
+
logging.getLogger("litellm.utils").setLevel(logging.WARNING)
|
108
|
+
logging.getLogger("litellm.main").setLevel(logging.WARNING)
|
109
|
+
logging.getLogger("httpx").setLevel(logging.WARNING)
|
110
|
+
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
111
|
+
if hasattr(self, 'litellm'):
|
112
|
+
self.litellm.suppress_debug_messages = True
|
113
|
+
self.litellm._logging._disable_debugging()
|
114
|
+
# Suppress all warnings including Pydantic's
|
115
|
+
warnings.filterwarnings("ignore", category=RuntimeWarning)
|
116
|
+
warnings.filterwarnings("ignore", category=UserWarning)
|
117
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
118
|
+
|
119
|
+
@property
|
120
|
+
def litellm(self):
|
121
|
+
"""Lazy load litellm module when needed."""
|
122
|
+
if self._litellm is None:
|
123
|
+
try:
|
124
|
+
import litellm
|
125
|
+
from litellm import image_generation
|
126
|
+
|
127
|
+
# Configure litellm to disable success handler logs
|
128
|
+
litellm.success_callback = []
|
129
|
+
litellm._logging._disable_debugging()
|
130
|
+
|
131
|
+
self._litellm = image_generation
|
132
|
+
# Configure logging after litellm is loaded
|
133
|
+
self._configure_logging(self.verbose)
|
134
|
+
except ImportError:
|
135
|
+
raise ImportError(
|
136
|
+
"litellm is required for image generation. "
|
137
|
+
"Please install it with: pip install litellm"
|
138
|
+
)
|
139
|
+
return self._litellm
|
140
|
+
|
141
|
+
def generate_image(self, prompt: str, **kwargs) -> Dict[str, Any]:
|
142
|
+
"""Generate an image based on the provided prompt."""
|
143
|
+
# Merge default config with any provided kwargs
|
144
|
+
config = self.image_config.dict(exclude_none=True)
|
145
|
+
config.update(kwargs)
|
146
|
+
|
147
|
+
# Use llm parameter as the model
|
148
|
+
config['model'] = self.llm
|
149
|
+
|
150
|
+
with Progress(
|
151
|
+
SpinnerColumn(),
|
152
|
+
TextColumn("[progress.description]{task.description}"),
|
153
|
+
transient=True
|
154
|
+
) as progress:
|
155
|
+
try:
|
156
|
+
# Add a task for image generation
|
157
|
+
task = progress.add_task(f"[cyan]Generating image with {self.llm}...", total=None)
|
158
|
+
|
159
|
+
# Use litellm's image generation
|
160
|
+
response = self.litellm(
|
161
|
+
prompt=prompt,
|
162
|
+
**config
|
163
|
+
)
|
164
|
+
|
165
|
+
# Mark task as complete
|
166
|
+
progress.update(task, completed=True)
|
167
|
+
return response
|
168
|
+
|
169
|
+
except Exception as e:
|
170
|
+
error_msg = f"Error generating image: {str(e)}"
|
171
|
+
if self.verbose:
|
172
|
+
self.console.print(f"[red]{error_msg}[/red]")
|
173
|
+
logging.error(error_msg)
|
174
|
+
raise
|
175
|
+
|
176
|
+
async def agenerate_image(self, prompt: str, **kwargs) -> Dict[str, Any]:
|
177
|
+
"""Async wrapper for generate_image."""
|
178
|
+
return self.generate_image(prompt, **kwargs)
|
179
|
+
|
180
|
+
def chat(self, prompt: str, **kwargs) -> Dict[str, Any]:
|
181
|
+
"""Generate an image from the prompt."""
|
182
|
+
try:
|
183
|
+
result = self.generate_image(prompt, **kwargs)
|
184
|
+
if self.verbose:
|
185
|
+
self.console.print(f"[green]Successfully generated image from prompt[/green]")
|
186
|
+
return result
|
187
|
+
except Exception as e:
|
188
|
+
error_msg = f"Failed to generate image: {str(e)}"
|
189
|
+
if self.verbose:
|
190
|
+
self.console.print(f"[red]{error_msg}[/red]")
|
191
|
+
return {"error": str(e)}
|
192
|
+
|
193
|
+
async def achat(
|
194
|
+
self,
|
195
|
+
prompt: str,
|
196
|
+
temperature: float = 0.2,
|
197
|
+
tools: Optional[List[Any]] = None,
|
198
|
+
output_json: Optional[str] = None,
|
199
|
+
output_pydantic: Optional[Any] = None,
|
200
|
+
reasoning_steps: bool = False,
|
201
|
+
**kwargs
|
202
|
+
) -> Union[str, Dict[str, Any]]:
|
203
|
+
"""Async chat method for image generation."""
|
204
|
+
try:
|
205
|
+
image_result = await self.agenerate_image(prompt, **kwargs)
|
206
|
+
if self.verbose:
|
207
|
+
self.console.print(f"[green]Successfully generated image from prompt[/green]")
|
208
|
+
return image_result
|
209
|
+
except Exception as e:
|
210
|
+
error_msg = f"Failed to generate image: {str(e)}"
|
211
|
+
if self.verbose:
|
212
|
+
self.console.print(f"[red]{error_msg}[/red]")
|
213
|
+
return {"error": str(e)}
|
@@ -8,10 +8,10 @@ It automatically handles agent creation, task setup, and execution flow.
|
|
8
8
|
from .agents import PraisonAIAgents
|
9
9
|
from ..agent.agent import Agent
|
10
10
|
from ..task.task import Task
|
11
|
-
from typing import List, Any, Optional, Dict
|
11
|
+
from typing import List, Any, Optional, Dict
|
12
12
|
import logging
|
13
13
|
import os
|
14
|
-
from pydantic import BaseModel
|
14
|
+
from pydantic import BaseModel
|
15
15
|
from ..main import display_instruction, display_tool_call, display_interaction, client
|
16
16
|
|
17
17
|
# Define Pydantic models for structured output
|
praisonaiagents/llm/llm.py
CHANGED
@@ -1128,7 +1128,7 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
|
1128
1128
|
raise
|
1129
1129
|
|
1130
1130
|
# Async version of response function. Response without tool calls
|
1131
|
-
async def
|
1131
|
+
async def aresponse(
|
1132
1132
|
self,
|
1133
1133
|
prompt: Union[str, List[Dict]],
|
1134
1134
|
system_prompt: Optional[str] = None,
|
@@ -1,8 +1,6 @@
|
|
1
1
|
from typing import Dict, Optional, Union, Any
|
2
2
|
import json
|
3
3
|
from datetime import datetime
|
4
|
-
from openai import OpenAI
|
5
|
-
from pydantic import BaseModel
|
6
4
|
import os
|
7
5
|
import logging
|
8
6
|
|
@@ -124,7 +122,7 @@ class GenerateCOT:
|
|
124
122
|
try:
|
125
123
|
score = float(self._ask_ai(prompt))
|
126
124
|
return min(max(score, 0), 1)
|
127
|
-
except:
|
125
|
+
except ValueError:
|
128
126
|
return 0.0
|
129
127
|
|
130
128
|
def cot_run(self, question: str) -> str:
|
@@ -336,6 +334,7 @@ class GenerateCOT:
|
|
336
334
|
) -> Optional[str]:
|
337
335
|
"""Export solutions in CSV format."""
|
338
336
|
try:
|
337
|
+
import csv
|
339
338
|
self._is_qa_pairs(qa_pairs) # Validate format
|
340
339
|
if qa_pairs:
|
341
340
|
self.qa_pairs.update(qa_pairs)
|
@@ -425,7 +424,6 @@ class GenerateCOT:
|
|
425
424
|
logger.debug(f"Attempting to upload {filepath} to HuggingFace as {dataset_name}")
|
426
425
|
try:
|
427
426
|
from datasets import Dataset
|
428
|
-
from huggingface_hub import HfApi, login
|
429
427
|
import pandas as pd
|
430
428
|
|
431
429
|
logger.debug(f"Loading data from {filepath}")
|
@@ -1,15 +1,16 @@
|
|
1
|
-
praisonaiagents/__init__.py,sha256=
|
1
|
+
praisonaiagents/__init__.py,sha256=frdIvimDY-kU9j-9yXV1z4NtXypfPvyvlnac5mgBCuQ,1288
|
2
2
|
praisonaiagents/main.py,sha256=0kB9gn9meXtr4EIrdgA2lAioKIHCRJ61audsGDwuTm4,14428
|
3
|
-
praisonaiagents/agent/__init__.py,sha256=
|
4
|
-
praisonaiagents/agent/agent.py,sha256=
|
3
|
+
praisonaiagents/agent/__init__.py,sha256=j0T19TVNbfZcClvpbZDDinQxZ0oORgsMrMqx16jZ-bA,128
|
4
|
+
praisonaiagents/agent/agent.py,sha256=_v8WrWK1oP4OpPgp30nH4xbPyREnjOnRT1cyHUa2T9Q,57582
|
5
|
+
praisonaiagents/agent/image_agent.py,sha256=-5MXG594HVwSpFMcidt16YBp7udtik-Cp7eXlzLE1fY,8696
|
5
6
|
praisonaiagents/agents/__init__.py,sha256=_1d6Pqyk9EoBSo7E68sKyd1jDRlN1vxvVIRpoMc0Jcw,168
|
6
7
|
praisonaiagents/agents/agents.py,sha256=94YPQl-hl-EPY6-Xk2Rj9wlIs9YtiLQbsutSOXWX8QI,36156
|
7
|
-
praisonaiagents/agents/autoagents.py,sha256=
|
8
|
+
praisonaiagents/agents/autoagents.py,sha256=olYDn--rlJp-SckxILqmREkkgNlzCgEEcAUzfMj-54E,13518
|
8
9
|
praisonaiagents/knowledge/__init__.py,sha256=xL1Eh-a3xsHyIcU4foOWF-JdWYIYBALJH9bge0Ujuto,246
|
9
10
|
praisonaiagents/knowledge/chunking.py,sha256=FzoNY0q8MkvG4gADqk4JcRhmH3lcEHbRdonDgitQa30,6624
|
10
11
|
praisonaiagents/knowledge/knowledge.py,sha256=fQNREDiwdoisfIxJBLVkteXgq_8Gbypfc3UaZbxf5QY,13210
|
11
12
|
praisonaiagents/llm/__init__.py,sha256=ttPQQJQq6Tah-0updoEXDZFKWtJAM93rBWRoIgxRWO8,689
|
12
|
-
praisonaiagents/llm/llm.py,sha256=
|
13
|
+
praisonaiagents/llm/llm.py,sha256=SYfiMOmduEOhwraewmXSydu6tNBb9n5uKRxnO9moGYM,58151
|
13
14
|
praisonaiagents/memory/memory.py,sha256=I8dOTkrl1i-GgQbDcrFOsSruzJ7MiI6Ys37DK27wrUs,35537
|
14
15
|
praisonaiagents/process/__init__.py,sha256=lkYbL7Hn5a0ldvJtkdH23vfIIZLIcanK-65C0MwaorY,52
|
15
16
|
praisonaiagents/process/process.py,sha256=HPw84OhnKQW3EyrDkpoQu0DcpxThbrzR2hWUgwQh9Pw,59955
|
@@ -35,8 +36,8 @@ praisonaiagents/tools/wikipedia_tools.py,sha256=pGko-f33wqXgxJTv8db7TbizY5XnzBQR
|
|
35
36
|
praisonaiagents/tools/xml_tools.py,sha256=iYTMBEk5l3L3ryQ1fkUnNVYK-Nnua2Kx2S0dxNMMs1A,17122
|
36
37
|
praisonaiagents/tools/yaml_tools.py,sha256=uogAZrhXV9O7xvspAtcTfpKSQYL2nlOTvCQXN94-G9A,14215
|
37
38
|
praisonaiagents/tools/yfinance_tools.py,sha256=s2PBj_1v7oQnOobo2fDbQBACEHl61ftG4beG6Z979ZE,8529
|
38
|
-
praisonaiagents/tools/train/data/generatecot.py,sha256=
|
39
|
-
praisonaiagents-0.0.
|
40
|
-
praisonaiagents-0.0.
|
41
|
-
praisonaiagents-0.0.
|
42
|
-
praisonaiagents-0.0.
|
39
|
+
praisonaiagents/tools/train/data/generatecot.py,sha256=H6bNh-E2hqL5MW6kX3hqZ05g9ETKN2-kudSjiuU_SD8,19403
|
40
|
+
praisonaiagents-0.0.61.dist-info/METADATA,sha256=I_883Gdgeer-wm8RVmBk-kAdkHQloL0ewZ96wqwW26c,830
|
41
|
+
praisonaiagents-0.0.61.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
42
|
+
praisonaiagents-0.0.61.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
|
43
|
+
praisonaiagents-0.0.61.dist-info/RECORD,,
|
File without changes
|
File without changes
|