mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-07 17:33:33 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0213dea12b | ||
|
|
c0d495fd48 | ||
|
|
0e51ed0d6c | ||
|
|
32dce14f96 | ||
|
|
27aaac80c6 | ||
|
|
5a0a3983e4 | ||
|
|
400a4c934e | ||
|
|
e88b0fd47b | ||
|
|
e6c1c0679f | ||
|
|
108aee0a54 | ||
|
|
cb017aad70 | ||
|
|
ea29d3181b | ||
|
|
7f0f265671 | ||
|
|
bc1c508419 | ||
|
|
bd108ba3e7 | ||
|
|
ac5f2649df | ||
|
|
1b64762d54 | ||
|
|
df402bcfdb | ||
|
|
061c8d58b4 | ||
|
|
117c02cf30 | ||
|
|
82c9ff80a7 | ||
|
|
f44b15d73b | ||
|
|
f2c89c2012 | ||
|
|
f3f5f63b22 | ||
|
|
ccf9470f41 | ||
|
|
d228a742b7 |
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
flask \
|
||||
"praisonai>=2.2.45" \
|
||||
"praisonai>=2.2.47" \
|
||||
"praisonai[api]" \
|
||||
gunicorn \
|
||||
markdown
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.2.45" \
|
||||
"praisonai>=2.2.47" \
|
||||
"praisonai[chat]" \
|
||||
"embedchain[github,youtube]"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.2.45" \
|
||||
"praisonai>=2.2.47" \
|
||||
"praisonai[ui]" \
|
||||
"praisonai[chat]" \
|
||||
"praisonai[realtime]" \
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.2.45" \
|
||||
"praisonai>=2.2.47" \
|
||||
"praisonai[ui]" \
|
||||
"praisonai[crewai]"
|
||||
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ healthcheck:
|
||||
## 📦 Package Versions
|
||||
|
||||
All Docker images use consistent, up-to-date versions:
|
||||
- PraisonAI: `>=2.2.45`
|
||||
- PraisonAI: `>=2.2.47`
|
||||
- PraisonAI Agents: `>=0.0.92`
|
||||
- Python: `3.11-slim`
|
||||
|
||||
@@ -218,7 +218,7 @@ docker-compose up -d
|
||||
### Version Pinning
|
||||
To use specific versions, update the Dockerfile:
|
||||
```dockerfile
|
||||
RUN pip install "praisonai==2.2.45" "praisonaiagents==0.0.92"
|
||||
RUN pip install "praisonai==2.2.47" "praisonaiagents==0.0.92"
|
||||
```
|
||||
|
||||
## 🌐 Production Deployment
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
from praisonaiagents import AutoAgents
|
||||
from praisonaiagents.tools import duckduckgo
|
||||
|
||||
# Create AutoAgents instance
|
||||
agents = AutoAgents(
|
||||
instructions="Search for information about AI Agents",
|
||||
tools=[duckduckgo],
|
||||
process="sequential",
|
||||
verbose=True,
|
||||
max_agents=3 # Maximum number of agents to create
|
||||
)
|
||||
|
||||
# Start the agents
|
||||
result = agents.start()
|
||||
print(result)
|
||||
|
||||
##or
|
||||
|
||||
from praisonaiagents import AutoAgents
|
||||
from praisonaiagents.tools import (
|
||||
evaluate, solve_equation, convert_units,
|
||||
calculate_statistics, calculate_financial
|
||||
)
|
||||
|
||||
|
||||
def get_stock_price(company_name: str) -> str:
|
||||
"""
|
||||
Get the stock price of a company
|
||||
|
||||
Args:
|
||||
company_name (str): The name of the company
|
||||
|
||||
Returns:
|
||||
str: The stock price of the company
|
||||
"""
|
||||
|
||||
if company_name.lower() == "apple" or company_name.lower() == "aapl":
|
||||
return f"The stock price of {company_name} is 100"
|
||||
elif company_name.lower() == "google" or company_name.lower() == "googl":
|
||||
return f"The stock price of {company_name} is 200"
|
||||
else:
|
||||
return f"The stock price of {company_name} is 50"
|
||||
|
||||
# Create AutoAgents instance
|
||||
agents = AutoAgents(
|
||||
instructions="Get the stock price of google and compare it to the stock price of apple",
|
||||
tools=[evaluate, get_stock_price],
|
||||
process="sequential",
|
||||
llm="gemini/gemini-2.5-flash-lite-preview-06-17",
|
||||
self_reflect=False,
|
||||
verbose=False,
|
||||
max_agents=3 # Maximum number of agents to create
|
||||
)
|
||||
|
||||
# Start the agents
|
||||
result = agents.start()
|
||||
print(result)
|
||||
@@ -0,0 +1,6 @@
|
||||
from praisonaiagents import Agent, Agents, Tools
|
||||
|
||||
research_agent = Agent(name="Research", instructions="You are a research agent to search internet about AI 2024", tools=[Tools.internet_search])
|
||||
summarise_agent = Agent(name="Summarise", instructions="You are a summarize agent to summarise in points")
|
||||
agents = Agents(agents=[research_agent, summarise_agent])
|
||||
agents.launch(path="/agents", port=3030)
|
||||
@@ -1233,7 +1233,8 @@ Your Goal: {self.goal}
|
||||
# Add to chat history and return raw response
|
||||
self.chat_history.append({"role": "user", "content": original_prompt})
|
||||
self.chat_history.append({"role": "assistant", "content": response_text})
|
||||
if self.verbose:
|
||||
# Only display interaction if not using custom LLM (to avoid double output) and verbose is True
|
||||
if self.verbose and not self._using_custom_llm:
|
||||
display_interaction(original_prompt, response_text, markdown=self.markdown,
|
||||
generation_time=time.time() - start_time, console=self.console)
|
||||
return response_text
|
||||
@@ -1243,7 +1244,9 @@ Your Goal: {self.goal}
|
||||
self.chat_history.append({"role": "assistant", "content": response_text})
|
||||
if self.verbose:
|
||||
logging.debug(f"Agent {self.name} final response: {response_text}")
|
||||
display_interaction(original_prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Only display interaction if not using custom LLM (to avoid double output) and verbose is True
|
||||
if self.verbose and not self._using_custom_llm:
|
||||
display_interaction(original_prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Return only reasoning content if reasoning_steps is True
|
||||
if reasoning_steps and hasattr(response.choices[0].message, 'reasoning_content'):
|
||||
# Apply guardrail to reasoning content
|
||||
@@ -1279,7 +1282,9 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
# Return the original response without reflection
|
||||
self.chat_history.append({"role": "user", "content": prompt})
|
||||
self.chat_history.append({"role": "assistant", "content": response_text})
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Only display interaction if not using custom LLM (to avoid double output) and verbose is True
|
||||
if self.verbose and not self._using_custom_llm:
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
return response_text
|
||||
|
||||
reflection_response = self._openai_client.sync_client.beta.chat.completions.parse(
|
||||
@@ -1302,7 +1307,9 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
display_self_reflection("Agent marked the response as satisfactory after meeting minimum reflections", console=self.console)
|
||||
self.chat_history.append({"role": "user", "content": prompt})
|
||||
self.chat_history.append({"role": "assistant", "content": response_text})
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Only display interaction if not using custom LLM (to avoid double output) and verbose is True
|
||||
if self.verbose and not self._using_custom_llm:
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Apply guardrail validation after satisfactory reflection
|
||||
try:
|
||||
validated_response = self._apply_guardrail_with_retry(response_text, prompt, temperature, tools)
|
||||
@@ -1317,7 +1324,9 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
display_self_reflection("Maximum reflection count reached, returning current response", console=self.console)
|
||||
self.chat_history.append({"role": "user", "content": prompt})
|
||||
self.chat_history.append({"role": "assistant", "content": response_text})
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Only display interaction if not using custom LLM (to avoid double output) and verbose is True
|
||||
if self.verbose and not self._using_custom_llm:
|
||||
display_interaction(prompt, response_text, markdown=self.markdown, generation_time=time.time() - start_time, console=self.console)
|
||||
# Apply guardrail validation after max reflections
|
||||
try:
|
||||
validated_response = self._apply_guardrail_with_retry(response_text, prompt, temperature, tools)
|
||||
|
||||
@@ -13,7 +13,8 @@ import logging
|
||||
import os
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from ..main import display_instruction, display_tool_call, display_interaction
|
||||
from ..llm import get_openai_client
|
||||
from ..llm import get_openai_client, LLM, OpenAIClient
|
||||
import json
|
||||
|
||||
# Define Pydantic models for structured output
|
||||
class TaskConfig(BaseModel):
|
||||
@@ -108,6 +109,8 @@ class AutoAgents(PraisonAIAgents):
|
||||
self.max_execution_time = max_execution_time
|
||||
self.max_iter = max_iter
|
||||
self.reflect_llm = reflect_llm
|
||||
self.base_url = base_url
|
||||
self.api_key = api_key
|
||||
|
||||
# Display initial instruction
|
||||
if self.verbose:
|
||||
@@ -238,33 +241,77 @@ Return the configuration in a structured JSON format matching the AutoAgentsConf
|
||||
"""
|
||||
|
||||
try:
|
||||
# Get OpenAI client
|
||||
# Try to use OpenAI's structured output if available
|
||||
use_openai_structured = False
|
||||
client = None
|
||||
|
||||
try:
|
||||
client = get_openai_client()
|
||||
except ValueError as e:
|
||||
# AutoAgents requires OpenAI for structured output generation
|
||||
raise ValueError(
|
||||
"AutoAgents requires OpenAI API for automatic agent generation. "
|
||||
"Please set OPENAI_API_KEY environment variable or use PraisonAIAgents class directly "
|
||||
"with manually configured agents for non-OpenAI providers."
|
||||
) from e
|
||||
# Check if we have OpenAI API and the model supports structured output
|
||||
if self.llm and (self.llm.startswith('gpt-') or self.llm.startswith('o1-') or self.llm.startswith('o3-')):
|
||||
# Create a new client instance if custom parameters are provided
|
||||
if self.api_key or self.base_url:
|
||||
client = OpenAIClient(api_key=self.api_key, base_url=self.base_url)
|
||||
else:
|
||||
client = get_openai_client()
|
||||
use_openai_structured = True
|
||||
except:
|
||||
# If OpenAI client is not available, we'll use the LLM class
|
||||
pass
|
||||
|
||||
if use_openai_structured and client:
|
||||
# Use OpenAI's structured output for OpenAI models (backward compatibility)
|
||||
config = client.parse_structured_output(
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant designed to generate AI agent configurations."},
|
||||
{"role": "user", "content": prompt}
|
||||
],
|
||||
response_format=AutoAgentsConfig,
|
||||
model=self.llm
|
||||
)
|
||||
else:
|
||||
# Use LLM class for all other providers (Gemini, Anthropic, etc.)
|
||||
llm_instance = LLM(
|
||||
model=self.llm,
|
||||
base_url=self.base_url,
|
||||
api_key=self.api_key
|
||||
)
|
||||
|
||||
response = client.beta.chat.completions.parse(
|
||||
model=self.llm,
|
||||
response_format=AutoAgentsConfig,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant designed to generate AI agent configurations."},
|
||||
{"role": "user", "content": prompt}
|
||||
]
|
||||
)
|
||||
response_text = llm_instance.response(
|
||||
prompt=prompt,
|
||||
system_prompt="You are a helpful assistant designed to generate AI agent configurations.",
|
||||
output_pydantic=AutoAgentsConfig,
|
||||
temperature=0.7,
|
||||
stream=False,
|
||||
verbose=False
|
||||
)
|
||||
|
||||
# Parse the JSON response
|
||||
try:
|
||||
# First try to parse as is
|
||||
config_dict = json.loads(response_text)
|
||||
config = AutoAgentsConfig(**config_dict)
|
||||
except json.JSONDecodeError:
|
||||
# If that fails, try to extract JSON from the response
|
||||
# Handle cases where the model might wrap JSON in markdown blocks
|
||||
cleaned_response = response_text.strip()
|
||||
if cleaned_response.startswith("```json"):
|
||||
cleaned_response = cleaned_response[7:]
|
||||
if cleaned_response.startswith("```"):
|
||||
cleaned_response = cleaned_response[3:]
|
||||
if cleaned_response.endswith("```"):
|
||||
cleaned_response = cleaned_response[:-3]
|
||||
cleaned_response = cleaned_response.strip()
|
||||
|
||||
config_dict = json.loads(cleaned_response)
|
||||
config = AutoAgentsConfig(**config_dict)
|
||||
|
||||
# Ensure we have exactly max_agents number of agents
|
||||
if len(response.choices[0].message.parsed.agents) > self.max_agents:
|
||||
response.choices[0].message.parsed.agents = response.choices[0].message.parsed.agents[:self.max_agents]
|
||||
elif len(response.choices[0].message.parsed.agents) < self.max_agents:
|
||||
logging.warning(f"Generated {len(response.choices[0].message.parsed.agents)} agents, expected {self.max_agents}")
|
||||
if len(config.agents) > self.max_agents:
|
||||
config.agents = config.agents[:self.max_agents]
|
||||
elif len(config.agents) < self.max_agents:
|
||||
logging.warning(f"Generated {len(config.agents)} agents, expected {self.max_agents}")
|
||||
|
||||
return response.choices[0].message.parsed
|
||||
return config
|
||||
except Exception as e:
|
||||
logging.error(f"Error generating configuration: {e}")
|
||||
raise
|
||||
@@ -308,7 +355,9 @@ Return the configuration in a structured JSON format matching the AutoAgentsConf
|
||||
max_rpm=self.max_rpm,
|
||||
max_execution_time=self.max_execution_time,
|
||||
max_iter=self.max_iter,
|
||||
reflect_llm=self.reflect_llm
|
||||
reflect_llm=self.reflect_llm,
|
||||
base_url=self.base_url,
|
||||
api_key=self.api_key
|
||||
)
|
||||
agents.append(agent)
|
||||
|
||||
|
||||
@@ -87,6 +87,65 @@ class LLM:
|
||||
"llama-3.2-90b-text-preview": 6144 # 8,192 actual
|
||||
}
|
||||
|
||||
def _log_llm_config(self, method_name: str, **config):
|
||||
"""Centralized debug logging for LLM configuration and parameters.
|
||||
|
||||
Args:
|
||||
method_name: The name of the method calling this logger (e.g., '__init__', 'get_response')
|
||||
**config: Configuration parameters to log
|
||||
"""
|
||||
# Check for debug logging - either global debug level OR explicit verbose mode
|
||||
verbose = config.get('verbose', self.verbose if hasattr(self, 'verbose') else False)
|
||||
should_log = logging.getLogger().getEffectiveLevel() == logging.DEBUG or (not isinstance(verbose, bool) and verbose >= 10)
|
||||
|
||||
if should_log:
|
||||
# Mask sensitive information
|
||||
safe_config = config.copy()
|
||||
if 'api_key' in safe_config:
|
||||
safe_config['api_key'] = "***" if safe_config['api_key'] is not None else None
|
||||
if 'extra_settings' in safe_config and isinstance(safe_config['extra_settings'], dict):
|
||||
safe_config['extra_settings'] = {k: v for k, v in safe_config['extra_settings'].items() if k not in ["api_key"]}
|
||||
|
||||
# Handle special formatting for certain fields
|
||||
if 'prompt' in safe_config:
|
||||
prompt = safe_config['prompt']
|
||||
# Convert to string first for consistent logging behavior
|
||||
prompt_str = str(prompt) if not isinstance(prompt, str) else prompt
|
||||
if len(prompt_str) > 100:
|
||||
safe_config['prompt'] = prompt_str[:100] + "..."
|
||||
else:
|
||||
safe_config['prompt'] = prompt_str
|
||||
if 'system_prompt' in safe_config:
|
||||
sp = safe_config['system_prompt']
|
||||
if sp and isinstance(sp, str) and len(sp) > 100:
|
||||
safe_config['system_prompt'] = sp[:100] + "..."
|
||||
if 'chat_history' in safe_config:
|
||||
ch = safe_config['chat_history']
|
||||
safe_config['chat_history'] = f"[{len(ch)} messages]" if ch else None
|
||||
if 'tools' in safe_config:
|
||||
tools = safe_config['tools']
|
||||
# Check if tools is iterable before processing
|
||||
if tools and hasattr(tools, '__iter__') and not isinstance(tools, str):
|
||||
safe_config['tools'] = [t.__name__ if hasattr(t, "__name__") else str(t) for t in tools]
|
||||
else:
|
||||
safe_config['tools'] = None
|
||||
if 'output_json' in safe_config:
|
||||
oj = safe_config['output_json']
|
||||
safe_config['output_json'] = str(oj.__class__.__name__) if oj else None
|
||||
if 'output_pydantic' in safe_config:
|
||||
op = safe_config['output_pydantic']
|
||||
safe_config['output_pydantic'] = str(op.__class__.__name__) if op else None
|
||||
|
||||
# Log based on method name - check more specific conditions first
|
||||
if method_name == '__init__':
|
||||
logging.debug(f"LLM instance initialized with: {json.dumps(safe_config, indent=2, default=str)}")
|
||||
elif "parameters" in method_name:
|
||||
logging.debug(f"{method_name}: {json.dumps(safe_config, indent=2, default=str)}")
|
||||
elif "_async" in method_name:
|
||||
logging.debug(f"LLM async instance configuration: {json.dumps(safe_config, indent=2, default=str)}")
|
||||
else:
|
||||
logging.debug(f"{method_name} configuration: {json.dumps(safe_config, indent=2, default=str)}")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model: str,
|
||||
@@ -181,35 +240,34 @@ class LLM:
|
||||
litellm.modify_params = True
|
||||
self._setup_event_tracking(events)
|
||||
|
||||
# Log all initialization parameters when in debug mode
|
||||
if not isinstance(verbose, bool) and verbose >= 10:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": self.temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"logit_bias": self.logit_bias,
|
||||
"response_format": self.response_format,
|
||||
"seed": self.seed,
|
||||
"logprobs": self.logprobs,
|
||||
"top_logprobs": self.top_logprobs,
|
||||
"api_version": self.api_version,
|
||||
"stop_phrases": self.stop_phrases,
|
||||
"api_key": "***" if self.api_key else None, # Mask API key for security
|
||||
"base_url": self.base_url,
|
||||
"verbose": self.verbose,
|
||||
"markdown": self.markdown,
|
||||
"self_reflect": self.self_reflect,
|
||||
"max_reflect": self.max_reflect,
|
||||
"min_reflect": self.min_reflect,
|
||||
"reasoning_steps": self.reasoning_steps,
|
||||
"extra_settings": {k: v for k, v in self.extra_settings.items() if k not in ["api_key"]}
|
||||
}
|
||||
logging.debug(f"LLM instance initialized with: {json.dumps(debug_info, indent=2, default=str)}")
|
||||
# Log all initialization parameters when in debug mode or verbose >= 10
|
||||
self._log_llm_config(
|
||||
'__init__',
|
||||
model=self.model,
|
||||
timeout=self.timeout,
|
||||
temperature=self.temperature,
|
||||
top_p=self.top_p,
|
||||
n=self.n,
|
||||
max_tokens=self.max_tokens,
|
||||
presence_penalty=self.presence_penalty,
|
||||
frequency_penalty=self.frequency_penalty,
|
||||
logit_bias=self.logit_bias,
|
||||
response_format=self.response_format,
|
||||
seed=self.seed,
|
||||
logprobs=self.logprobs,
|
||||
top_logprobs=self.top_logprobs,
|
||||
api_version=self.api_version,
|
||||
stop_phrases=self.stop_phrases,
|
||||
api_key=self.api_key,
|
||||
base_url=self.base_url,
|
||||
verbose=self.verbose,
|
||||
markdown=self.markdown,
|
||||
self_reflect=self.self_reflect,
|
||||
max_reflect=self.max_reflect,
|
||||
min_reflect=self.min_reflect,
|
||||
reasoning_steps=self.reasoning_steps,
|
||||
extra_settings=self.extra_settings
|
||||
)
|
||||
|
||||
def _is_ollama_provider(self) -> bool:
|
||||
"""Detect if this is an Ollama provider regardless of naming convention"""
|
||||
@@ -229,6 +287,39 @@ class LLM:
|
||||
|
||||
return any(endpoint in base_url or endpoint in api_base for endpoint in ollama_endpoints)
|
||||
|
||||
def _process_stream_delta(self, delta, response_text: str, tool_calls: List[Dict], formatted_tools: Optional[List] = None) -> tuple:
|
||||
"""
|
||||
Process a streaming delta chunk to extract content and tool calls.
|
||||
|
||||
Args:
|
||||
delta: The delta object from a streaming chunk
|
||||
response_text: The accumulated response text so far
|
||||
tool_calls: The accumulated tool calls list so far
|
||||
formatted_tools: Optional list of formatted tools for tool call support check
|
||||
|
||||
Returns:
|
||||
tuple: (updated_response_text, updated_tool_calls)
|
||||
"""
|
||||
# Process content
|
||||
if delta.content:
|
||||
response_text += delta.content
|
||||
|
||||
# Capture tool calls from streaming chunks if provider supports it
|
||||
if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
|
||||
return response_text, tool_calls
|
||||
|
||||
def _parse_tool_call_arguments(self, tool_call: Dict, is_ollama: bool = False) -> tuple:
|
||||
"""
|
||||
Safely parse tool call arguments with proper error handling
|
||||
@@ -497,54 +588,53 @@ class LLM:
|
||||
"""Enhanced get_response with all OpenAI-like features"""
|
||||
logging.info(f"Getting response from {self.model}")
|
||||
# Log all self values when in debug mode
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": self.temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"logit_bias": self.logit_bias,
|
||||
"response_format": self.response_format,
|
||||
"seed": self.seed,
|
||||
"logprobs": self.logprobs,
|
||||
"top_logprobs": self.top_logprobs,
|
||||
"api_version": self.api_version,
|
||||
"stop_phrases": self.stop_phrases,
|
||||
"api_key": "***" if self.api_key else None, # Mask API key for security
|
||||
"base_url": self.base_url,
|
||||
"verbose": self.verbose,
|
||||
"markdown": self.markdown,
|
||||
"self_reflect": self.self_reflect,
|
||||
"max_reflect": self.max_reflect,
|
||||
"min_reflect": self.min_reflect,
|
||||
"reasoning_steps": self.reasoning_steps
|
||||
}
|
||||
logging.debug(f"LLM instance configuration: {json.dumps(debug_info, indent=2, default=str)}")
|
||||
|
||||
# Log the parameter values passed to get_response
|
||||
param_info = {
|
||||
"prompt": str(prompt)[:100] + "..." if isinstance(prompt, str) and len(str(prompt)) > 100 else str(prompt),
|
||||
"system_prompt": system_prompt[:100] + "..." if system_prompt and len(system_prompt) > 100 else system_prompt,
|
||||
"chat_history": f"[{len(chat_history)} messages]" if chat_history else None,
|
||||
"temperature": temperature,
|
||||
"tools": [t.__name__ if hasattr(t, "__name__") else str(t) for t in tools] if tools else None,
|
||||
"output_json": str(output_json.__class__.__name__) if output_json else None,
|
||||
"output_pydantic": str(output_pydantic.__class__.__name__) if output_pydantic else None,
|
||||
"verbose": verbose,
|
||||
"markdown": markdown,
|
||||
"self_reflect": self_reflect,
|
||||
"max_reflect": max_reflect,
|
||||
"min_reflect": min_reflect,
|
||||
"agent_name": agent_name,
|
||||
"agent_role": agent_role,
|
||||
"agent_tools": agent_tools,
|
||||
"kwargs": str(kwargs)
|
||||
}
|
||||
logging.debug(f"get_response parameters: {json.dumps(param_info, indent=2, default=str)}")
|
||||
self._log_llm_config(
|
||||
'LLM instance',
|
||||
model=self.model,
|
||||
timeout=self.timeout,
|
||||
temperature=self.temperature,
|
||||
top_p=self.top_p,
|
||||
n=self.n,
|
||||
max_tokens=self.max_tokens,
|
||||
presence_penalty=self.presence_penalty,
|
||||
frequency_penalty=self.frequency_penalty,
|
||||
logit_bias=self.logit_bias,
|
||||
response_format=self.response_format,
|
||||
seed=self.seed,
|
||||
logprobs=self.logprobs,
|
||||
top_logprobs=self.top_logprobs,
|
||||
api_version=self.api_version,
|
||||
stop_phrases=self.stop_phrases,
|
||||
api_key=self.api_key,
|
||||
base_url=self.base_url,
|
||||
verbose=self.verbose,
|
||||
markdown=self.markdown,
|
||||
self_reflect=self.self_reflect,
|
||||
max_reflect=self.max_reflect,
|
||||
min_reflect=self.min_reflect,
|
||||
reasoning_steps=self.reasoning_steps
|
||||
)
|
||||
|
||||
# Log the parameter values passed to get_response
|
||||
self._log_llm_config(
|
||||
'get_response parameters',
|
||||
prompt=prompt,
|
||||
system_prompt=system_prompt,
|
||||
chat_history=chat_history,
|
||||
temperature=temperature,
|
||||
tools=tools,
|
||||
output_json=output_json,
|
||||
output_pydantic=output_pydantic,
|
||||
verbose=verbose,
|
||||
markdown=markdown,
|
||||
self_reflect=self_reflect,
|
||||
max_reflect=max_reflect,
|
||||
min_reflect=min_reflect,
|
||||
agent_name=agent_name,
|
||||
agent_role=agent_role,
|
||||
agent_tools=agent_tools,
|
||||
kwargs=str(kwargs)
|
||||
)
|
||||
try:
|
||||
import litellm
|
||||
# This below **kwargs** is passed to .completion() directly. so reasoning_steps has to be popped. OR find alternate best way of handling this.
|
||||
@@ -651,23 +741,12 @@ class LLM:
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta:
|
||||
delta = chunk.choices[0].delta
|
||||
response_text, tool_calls = self._process_stream_delta(
|
||||
delta, response_text, tool_calls, formatted_tools
|
||||
)
|
||||
if delta.content:
|
||||
response_text += delta.content
|
||||
live.update(display_generating(response_text, current_time))
|
||||
|
||||
# Capture tool calls from streaming chunks if provider supports it
|
||||
if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
|
||||
else:
|
||||
# Non-verbose streaming
|
||||
for chunk in litellm.completion(
|
||||
@@ -685,18 +764,8 @@ class LLM:
|
||||
response_text += delta.content
|
||||
|
||||
# Capture tool calls from streaming chunks if provider supports it
|
||||
if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
if formatted_tools and self._supports_streaming_tools():
|
||||
tool_calls = self._process_tool_calls_from_stream(delta, tool_calls)
|
||||
|
||||
response_text = response_text.strip()
|
||||
|
||||
@@ -737,20 +806,7 @@ class LLM:
|
||||
# Handle tool calls - Sequential tool calling logic
|
||||
if tool_calls and execute_tool_fn:
|
||||
# Convert tool_calls to a serializable format for all providers
|
||||
serializable_tool_calls = []
|
||||
for tc in tool_calls:
|
||||
if isinstance(tc, dict):
|
||||
serializable_tool_calls.append(tc) # Already a dict
|
||||
else:
|
||||
# Convert object to dict
|
||||
serializable_tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": getattr(tc, 'type', "function"),
|
||||
"function": {
|
||||
"name": tc.function.name,
|
||||
"arguments": tc.function.arguments
|
||||
}
|
||||
})
|
||||
serializable_tool_calls = self._serialize_tool_calls(tool_calls)
|
||||
messages.append({
|
||||
"role": "assistant",
|
||||
"content": response_text,
|
||||
@@ -761,20 +817,8 @@ class LLM:
|
||||
tool_results = [] # Store all tool results
|
||||
for tool_call in tool_calls:
|
||||
# Handle both object and dict access patterns
|
||||
if isinstance(tool_call, dict):
|
||||
is_ollama = self._is_ollama_provider()
|
||||
function_name, arguments, tool_call_id = self._parse_tool_call_arguments(tool_call, is_ollama)
|
||||
else:
|
||||
# Handle object-style tool calls
|
||||
try:
|
||||
function_name = tool_call.function.name
|
||||
arguments = json.loads(tool_call.function.arguments) if tool_call.function.arguments else {}
|
||||
tool_call_id = tool_call.id
|
||||
except (json.JSONDecodeError, AttributeError) as e:
|
||||
logging.error(f"Error parsing object-style tool call: {e}")
|
||||
function_name = "unknown_function"
|
||||
arguments = {}
|
||||
tool_call_id = f"tool_{id(tool_call)}"
|
||||
is_ollama = self._is_ollama_provider()
|
||||
function_name, arguments, tool_call_id = self._extract_tool_call_info(tool_call, is_ollama)
|
||||
|
||||
logging.debug(f"[TOOL_EXEC_DEBUG] About to execute tool {function_name} with args: {arguments}")
|
||||
tool_result = execute_tool_fn(function_name, arguments)
|
||||
@@ -1178,54 +1222,53 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
import litellm
|
||||
logging.info(f"Getting async response from {self.model}")
|
||||
# Log all self values when in debug mode
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": self.temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"logit_bias": self.logit_bias,
|
||||
"response_format": self.response_format,
|
||||
"seed": self.seed,
|
||||
"logprobs": self.logprobs,
|
||||
"top_logprobs": self.top_logprobs,
|
||||
"api_version": self.api_version,
|
||||
"stop_phrases": self.stop_phrases,
|
||||
"api_key": "***" if self.api_key else None, # Mask API key for security
|
||||
"base_url": self.base_url,
|
||||
"verbose": self.verbose,
|
||||
"markdown": self.markdown,
|
||||
"self_reflect": self.self_reflect,
|
||||
"max_reflect": self.max_reflect,
|
||||
"min_reflect": self.min_reflect,
|
||||
"reasoning_steps": self.reasoning_steps
|
||||
}
|
||||
logging.debug(f"LLM async instance configuration: {json.dumps(debug_info, indent=2, default=str)}")
|
||||
|
||||
# Log the parameter values passed to get_response_async
|
||||
param_info = {
|
||||
"prompt": str(prompt)[:100] + "..." if isinstance(prompt, str) and len(str(prompt)) > 100 else str(prompt),
|
||||
"system_prompt": system_prompt[:100] + "..." if system_prompt and len(system_prompt) > 100 else system_prompt,
|
||||
"chat_history": f"[{len(chat_history)} messages]" if chat_history else None,
|
||||
"temperature": temperature,
|
||||
"tools": [t.__name__ if hasattr(t, "__name__") else str(t) for t in tools] if tools else None,
|
||||
"output_json": str(output_json.__class__.__name__) if output_json else None,
|
||||
"output_pydantic": str(output_pydantic.__class__.__name__) if output_pydantic else None,
|
||||
"verbose": verbose,
|
||||
"markdown": markdown,
|
||||
"self_reflect": self_reflect,
|
||||
"max_reflect": max_reflect,
|
||||
"min_reflect": min_reflect,
|
||||
"agent_name": agent_name,
|
||||
"agent_role": agent_role,
|
||||
"agent_tools": agent_tools,
|
||||
"kwargs": str(kwargs)
|
||||
}
|
||||
logging.debug(f"get_response_async parameters: {json.dumps(param_info, indent=2, default=str)}")
|
||||
self._log_llm_config(
|
||||
'get_response_async',
|
||||
model=self.model,
|
||||
timeout=self.timeout,
|
||||
temperature=self.temperature,
|
||||
top_p=self.top_p,
|
||||
n=self.n,
|
||||
max_tokens=self.max_tokens,
|
||||
presence_penalty=self.presence_penalty,
|
||||
frequency_penalty=self.frequency_penalty,
|
||||
logit_bias=self.logit_bias,
|
||||
response_format=self.response_format,
|
||||
seed=self.seed,
|
||||
logprobs=self.logprobs,
|
||||
top_logprobs=self.top_logprobs,
|
||||
api_version=self.api_version,
|
||||
stop_phrases=self.stop_phrases,
|
||||
api_key=self.api_key,
|
||||
base_url=self.base_url,
|
||||
verbose=self.verbose,
|
||||
markdown=self.markdown,
|
||||
self_reflect=self.self_reflect,
|
||||
max_reflect=self.max_reflect,
|
||||
min_reflect=self.min_reflect,
|
||||
reasoning_steps=self.reasoning_steps
|
||||
)
|
||||
|
||||
# Log the parameter values passed to get_response_async
|
||||
self._log_llm_config(
|
||||
'get_response_async parameters',
|
||||
prompt=prompt,
|
||||
system_prompt=system_prompt,
|
||||
chat_history=chat_history,
|
||||
temperature=temperature,
|
||||
tools=tools,
|
||||
output_json=output_json,
|
||||
output_pydantic=output_pydantic,
|
||||
verbose=verbose,
|
||||
markdown=markdown,
|
||||
self_reflect=self_reflect,
|
||||
max_reflect=max_reflect,
|
||||
min_reflect=min_reflect,
|
||||
agent_name=agent_name,
|
||||
agent_role=agent_role,
|
||||
agent_tools=agent_tools,
|
||||
kwargs=str(kwargs)
|
||||
)
|
||||
reasoning_steps = kwargs.pop('reasoning_steps', self.reasoning_steps)
|
||||
litellm.set_verbose = False
|
||||
|
||||
@@ -1297,24 +1340,13 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta:
|
||||
delta = chunk.choices[0].delta
|
||||
response_text, tool_calls = self._process_stream_delta(
|
||||
delta, response_text, tool_calls, formatted_tools
|
||||
)
|
||||
if delta.content:
|
||||
response_text += delta.content
|
||||
print("\033[K", end="\r")
|
||||
print(f"Generating... {time.time() - start_time:.1f}s", end="\r")
|
||||
|
||||
# Capture tool calls from streaming chunks if provider supports it
|
||||
if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
|
||||
else:
|
||||
# Non-verbose streaming
|
||||
async for chunk in await litellm.acompletion(
|
||||
@@ -1332,18 +1364,8 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
response_text += delta.content
|
||||
|
||||
# Capture tool calls from streaming chunks if provider supports it
|
||||
if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
if formatted_tools and self._supports_streaming_tools():
|
||||
tool_calls = self._process_tool_calls_from_stream(delta, tool_calls)
|
||||
|
||||
response_text = response_text.strip()
|
||||
|
||||
@@ -1378,20 +1400,7 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
|
||||
if tool_calls:
|
||||
# Convert tool_calls to a serializable format for all providers
|
||||
serializable_tool_calls = []
|
||||
for tc in tool_calls:
|
||||
if isinstance(tc, dict):
|
||||
serializable_tool_calls.append(tc) # Already a dict
|
||||
else:
|
||||
# Convert object to dict
|
||||
serializable_tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": getattr(tc, 'type', "function"),
|
||||
"function": {
|
||||
"name": tc.function.name,
|
||||
"arguments": tc.function.arguments
|
||||
}
|
||||
})
|
||||
serializable_tool_calls = self._serialize_tool_calls(tool_calls)
|
||||
messages.append({
|
||||
"role": "assistant",
|
||||
"content": response_text,
|
||||
@@ -1401,20 +1410,8 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
tool_results = [] # Store all tool results
|
||||
for tool_call in tool_calls:
|
||||
# Handle both object and dict access patterns
|
||||
if isinstance(tool_call, dict):
|
||||
is_ollama = self._is_ollama_provider()
|
||||
function_name, arguments, tool_call_id = self._parse_tool_call_arguments(tool_call, is_ollama)
|
||||
else:
|
||||
# Handle object-style tool calls
|
||||
try:
|
||||
function_name = tool_call.function.name
|
||||
arguments = json.loads(tool_call.function.arguments) if tool_call.function.arguments else {}
|
||||
tool_call_id = tool_call.id
|
||||
except (json.JSONDecodeError, AttributeError) as e:
|
||||
logging.error(f"Error parsing object-style tool call: {e}")
|
||||
function_name = "unknown_function"
|
||||
arguments = {}
|
||||
tool_call_id = f"tool_{id(tool_call)}"
|
||||
is_ollama = self._is_ollama_provider()
|
||||
function_name, arguments, tool_call_id = self._extract_tool_call_info(tool_call, is_ollama)
|
||||
|
||||
tool_result = await execute_tool_fn(function_name, arguments)
|
||||
tool_results.append(tool_result) # Store the result
|
||||
@@ -1860,6 +1857,90 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
|
||||
return params
|
||||
|
||||
def _prepare_response_logging(self, temperature: float, stream: bool, verbose: bool, markdown: bool, **kwargs) -> Optional[Dict[str, Any]]:
|
||||
"""Prepare debug logging information for response methods"""
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"stream": stream,
|
||||
"verbose": verbose,
|
||||
"markdown": markdown,
|
||||
"kwargs": str(kwargs)
|
||||
}
|
||||
return debug_info
|
||||
return None
|
||||
|
||||
def _process_streaming_chunk(self, chunk) -> Optional[str]:
|
||||
"""Extract content from a streaming chunk"""
|
||||
if chunk and chunk.choices and chunk.choices[0].delta.content:
|
||||
return chunk.choices[0].delta.content
|
||||
return None
|
||||
|
||||
def _process_tool_calls_from_stream(self, delta, tool_calls: List[Dict]) -> List[Dict]:
|
||||
"""Process tool calls from streaming delta chunks.
|
||||
|
||||
This handles the accumulation of tool call data from streaming chunks,
|
||||
building up the complete tool call information incrementally.
|
||||
"""
|
||||
if hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tc in delta.tool_calls:
|
||||
if tc.index >= len(tool_calls):
|
||||
tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": "function",
|
||||
"function": {"name": "", "arguments": ""}
|
||||
})
|
||||
if tc.function.name:
|
||||
tool_calls[tc.index]["function"]["name"] = tc.function.name
|
||||
if tc.function.arguments:
|
||||
tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
|
||||
return tool_calls
|
||||
|
||||
def _serialize_tool_calls(self, tool_calls) -> List[Dict]:
|
||||
"""Convert tool calls to a serializable format for all providers."""
|
||||
serializable_tool_calls = []
|
||||
for tc in tool_calls:
|
||||
if isinstance(tc, dict):
|
||||
serializable_tool_calls.append(tc) # Already a dict
|
||||
else:
|
||||
# Convert object to dict
|
||||
serializable_tool_calls.append({
|
||||
"id": tc.id,
|
||||
"type": getattr(tc, 'type', "function"),
|
||||
"function": {
|
||||
"name": tc.function.name,
|
||||
"arguments": tc.function.arguments
|
||||
}
|
||||
})
|
||||
return serializable_tool_calls
|
||||
|
||||
def _extract_tool_call_info(self, tool_call, is_ollama: bool = False) -> tuple:
|
||||
"""Extract function name, arguments, and tool_call_id from a tool call.
|
||||
|
||||
Handles both dict and object formats for tool calls.
|
||||
"""
|
||||
if isinstance(tool_call, dict):
|
||||
return self._parse_tool_call_arguments(tool_call, is_ollama)
|
||||
else:
|
||||
# Handle object-style tool calls
|
||||
try:
|
||||
function_name = tool_call.function.name
|
||||
arguments = json.loads(tool_call.function.arguments) if tool_call.function.arguments else {}
|
||||
tool_call_id = tool_call.id
|
||||
except (json.JSONDecodeError, AttributeError) as e:
|
||||
logging.error(f"Error parsing object-style tool call: {e}")
|
||||
function_name = "unknown_function"
|
||||
arguments = {}
|
||||
tool_call_id = f"tool_{id(tool_call)}"
|
||||
return function_name, arguments, tool_call_id
|
||||
|
||||
# Response without tool calls
|
||||
def response(
|
||||
self,
|
||||
@@ -1884,22 +1965,21 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
logger.debug("Using synchronous response function")
|
||||
|
||||
# Log all self values when in debug mode
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"stream": stream,
|
||||
"verbose": verbose,
|
||||
"markdown": markdown,
|
||||
"kwargs": str(kwargs)
|
||||
}
|
||||
logger.debug(f"Response method configuration: {json.dumps(debug_info, indent=2, default=str)}")
|
||||
self._log_llm_config(
|
||||
'Response method',
|
||||
model=self.model,
|
||||
timeout=self.timeout,
|
||||
temperature=temperature,
|
||||
top_p=self.top_p,
|
||||
n=self.n,
|
||||
max_tokens=self.max_tokens,
|
||||
presence_penalty=self.presence_penalty,
|
||||
frequency_penalty=self.frequency_penalty,
|
||||
stream=stream,
|
||||
verbose=verbose,
|
||||
markdown=markdown,
|
||||
kwargs=str(kwargs)
|
||||
)
|
||||
|
||||
# Build messages list using shared helper (simplified version without JSON output)
|
||||
messages, _ = self._build_messages(
|
||||
@@ -1908,42 +1988,29 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
)
|
||||
|
||||
# Get response from LiteLLM
|
||||
response_text = ""
|
||||
completion_params = self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=stream,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if stream:
|
||||
response_text = ""
|
||||
if verbose:
|
||||
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
|
||||
for chunk in litellm.completion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=True,
|
||||
**kwargs
|
||||
)
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta.content:
|
||||
content = chunk.choices[0].delta.content
|
||||
for chunk in litellm.completion(**completion_params):
|
||||
content = self._process_streaming_chunk(chunk)
|
||||
if content:
|
||||
response_text += content
|
||||
live.update(display_generating(response_text, start_time))
|
||||
else:
|
||||
for chunk in litellm.completion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=True,
|
||||
**kwargs
|
||||
)
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta.content:
|
||||
response_text += chunk.choices[0].delta.content
|
||||
for chunk in litellm.completion(**completion_params):
|
||||
content = self._process_streaming_chunk(chunk)
|
||||
if content:
|
||||
response_text += content
|
||||
else:
|
||||
response = litellm.completion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=False,
|
||||
**kwargs
|
||||
)
|
||||
)
|
||||
response = litellm.completion(**completion_params)
|
||||
response_text = response.choices[0].message.content.strip()
|
||||
|
||||
if verbose:
|
||||
@@ -1984,23 +2051,23 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
|
||||
logger.debug("Using asynchronous response function")
|
||||
|
||||
|
||||
# Log all self values when in debug mode
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
debug_info = {
|
||||
"model": self.model,
|
||||
"timeout": self.timeout,
|
||||
"temperature": temperature,
|
||||
"top_p": self.top_p,
|
||||
"n": self.n,
|
||||
"max_tokens": self.max_tokens,
|
||||
"presence_penalty": self.presence_penalty,
|
||||
"frequency_penalty": self.frequency_penalty,
|
||||
"stream": stream,
|
||||
"verbose": verbose,
|
||||
"markdown": markdown,
|
||||
"kwargs": str(kwargs)
|
||||
}
|
||||
logger.debug(f"Async response method configuration: {json.dumps(debug_info, indent=2, default=str)}")
|
||||
self._log_llm_config(
|
||||
'Async response method',
|
||||
model=self.model,
|
||||
timeout=self.timeout,
|
||||
temperature=temperature,
|
||||
top_p=self.top_p,
|
||||
n=self.n,
|
||||
max_tokens=self.max_tokens,
|
||||
presence_penalty=self.presence_penalty,
|
||||
frequency_penalty=self.frequency_penalty,
|
||||
stream=stream,
|
||||
verbose=verbose,
|
||||
markdown=markdown,
|
||||
kwargs=str(kwargs)
|
||||
)
|
||||
|
||||
# Build messages list using shared helper (simplified version without JSON output)
|
||||
messages, _ = self._build_messages(
|
||||
@@ -2009,42 +2076,29 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
)
|
||||
|
||||
# Get response from LiteLLM
|
||||
response_text = ""
|
||||
completion_params = self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=stream,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if stream:
|
||||
response_text = ""
|
||||
if verbose:
|
||||
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
|
||||
async for chunk in await litellm.acompletion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=True,
|
||||
**kwargs
|
||||
)
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta.content:
|
||||
content = chunk.choices[0].delta.content
|
||||
async for chunk in await litellm.acompletion(**completion_params):
|
||||
content = self._process_streaming_chunk(chunk)
|
||||
if content:
|
||||
response_text += content
|
||||
live.update(display_generating(response_text, start_time))
|
||||
else:
|
||||
async for chunk in await litellm.acompletion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=True,
|
||||
**kwargs
|
||||
)
|
||||
):
|
||||
if chunk and chunk.choices and chunk.choices[0].delta.content:
|
||||
response_text += chunk.choices[0].delta.content
|
||||
async for chunk in await litellm.acompletion(**completion_params):
|
||||
content = self._process_streaming_chunk(chunk)
|
||||
if content:
|
||||
response_text += content
|
||||
else:
|
||||
response = await litellm.acompletion(
|
||||
**self._build_completion_params(
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
stream=False,
|
||||
**kwargs
|
||||
)
|
||||
)
|
||||
response = await litellm.acompletion(**completion_params)
|
||||
response_text = response.choices[0].message.content.strip()
|
||||
|
||||
if verbose:
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.118"
|
||||
version = "0.0.121"
|
||||
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
|
||||
requires-python = ">=3.10"
|
||||
authors = [
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from praisonaiagents import Agent, MCP
|
||||
|
||||
search_agent = Agent(
|
||||
instructions="""You are a Tweet.""",
|
||||
llm="openai/gpt-4o-mini",
|
||||
tools=MCP("http://localhost:8080/sse")
|
||||
)
|
||||
search_agent.launch(path="/tweet", port=3030)
|
||||
@@ -0,0 +1,4 @@
|
||||
from praisonaiagents import Agent
|
||||
|
||||
agent = Agent(instructions="Create a Tweet")
|
||||
agent.launch(port=8080, protocol="mcp")
|
||||
Generated
+1
-1
@@ -2375,7 +2375,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.118"
|
||||
version = "0.0.121"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "mcp" },
|
||||
|
||||
@@ -3,8 +3,8 @@ class Praisonai < Formula
|
||||
|
||||
desc "AI tools for various AI applications"
|
||||
homepage "https://github.com/MervinPraison/PraisonAI"
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.45.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.45.tar.gz | shasum -a 256`.split.first
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.47.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.47.tar.gz | shasum -a 256`.split.first
|
||||
license "MIT"
|
||||
|
||||
depends_on "[email protected]"
|
||||
|
||||
@@ -57,7 +57,7 @@ class CloudDeployer:
|
||||
file.write("FROM python:3.11-slim\n")
|
||||
file.write("WORKDIR /app\n")
|
||||
file.write("COPY . .\n")
|
||||
file.write("RUN pip install flask praisonai==2.2.45 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.2.47 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "PraisonAI"
|
||||
version = "2.2.45"
|
||||
version = "2.2.47"
|
||||
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
|
||||
readme = "README.md"
|
||||
license = ""
|
||||
@@ -12,7 +12,7 @@ dependencies = [
|
||||
"rich>=13.7",
|
||||
"markdown>=3.5",
|
||||
"pyparsing>=3.0.0",
|
||||
"praisonaiagents>=0.0.118",
|
||||
"praisonaiagents>=0.0.121",
|
||||
"python-dotenv>=0.19.0",
|
||||
"instructor>=1.3.3",
|
||||
"PyYAML>=6.0",
|
||||
@@ -95,7 +95,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.15", "crewai"]
|
||||
|
||||
[tool.poetry]
|
||||
name = "PraisonAI"
|
||||
version = "2.2.45"
|
||||
version = "2.2.47"
|
||||
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
|
||||
authors = ["Mervin Praison"]
|
||||
license = ""
|
||||
@@ -113,7 +113,7 @@ python = ">=3.10,<3.13"
|
||||
rich = ">=13.7"
|
||||
markdown = ">=3.5"
|
||||
pyparsing = ">=3.0.0"
|
||||
praisonaiagents = ">=0.0.118"
|
||||
praisonaiagents = ">=0.0.121"
|
||||
python-dotenv = ">=0.19.0"
|
||||
instructor = ">=1.3.3"
|
||||
PyYAML = ">=6.0"
|
||||
|
||||
Generated
+5
-5
@@ -3931,7 +3931,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonai"
|
||||
version = "2.2.45"
|
||||
version = "2.2.47"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "instructor" },
|
||||
@@ -4073,7 +4073,7 @@ requires-dist = [
|
||||
{ name = "plotly", marker = "extra == 'realtime'", specifier = ">=5.24.0" },
|
||||
{ name = "praisonai-tools", marker = "extra == 'autogen'", specifier = ">=0.0.15" },
|
||||
{ name = "praisonai-tools", marker = "extra == 'crewai'", specifier = ">=0.0.15" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.0.118" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.0.121" },
|
||||
{ name = "pyautogen", marker = "extra == 'autogen'", specifier = ">=0.2.19" },
|
||||
{ name = "pydantic", marker = "extra == 'chat'", specifier = "<=2.10.1" },
|
||||
{ name = "pydantic", marker = "extra == 'code'", specifier = "<=2.10.1" },
|
||||
@@ -4130,7 +4130,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.118"
|
||||
version = "0.0.121"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "mcp" },
|
||||
@@ -4139,9 +4139,9 @@ dependencies = [
|
||||
{ name = "pydantic" },
|
||||
{ name = "rich" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ba/53/0363b4e986b3916a246af2798cecaba08d47d46acc5faf313789d8de07cf/praisonaiagents-0.0.118.tar.gz", hash = "sha256:0e7cb593fc1733e33c6f17d55e4670ca973cfe4233c86747c7d97be41347a3da", size = 172108 }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/a6/3f/249dc75d8d66c692a2f487286907358afc5f92a9d52ffb2fbee140213be8/praisonaiagents-0.0.121.tar.gz", hash = "sha256:ca121d455f78b30afe5c41ae785ff4b4273b4dfd058b43d326f0255471a828c2", size = 172455 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/9a/a1/605677f442a983259be11079b492fff2a1cca78686c8a6385f8adcdea285/praisonaiagents-0.0.118-py3-none-any.whl", hash = "sha256:5e3f27ffc9af64c2db1726dc1174f348b5bb0dea07b110651fcde6f480ca36a1", size = 192626 },
|
||||
{ url = "https://files.pythonhosted.org/packages/c2/52/2fad476c91c5ff848d844773c045a8302a9336860e6fdc5cf10636ed79f1/praisonaiagents-0.0.121-py3-none-any.whl", hash = "sha256:4ad623a2ece1ecc5dd1c02e3bba3e79847fe6129bcbafafb380670b383abf299", size = 193136 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in new issue
Block a user