mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-09 17:31:52 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2882af376e | ||
|
|
19482e9163 | ||
|
|
0741b523b8 | ||
|
|
d63d564649 | ||
|
|
88ae3a26fb | ||
|
|
74ef96b9f6 | ||
|
|
12270a56d7 | ||
|
|
c79eedc8ec |
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.39" \
|
||||
"praisonai>=2.2.40" \
|
||||
"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.39" \
|
||||
"praisonai>=2.2.40" \
|
||||
"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.39" \
|
||||
"praisonai>=2.2.40" \
|
||||
"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.39" \
|
||||
"praisonai>=2.2.40" \
|
||||
"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.39`
|
||||
- PraisonAI: `>=2.2.40`
|
||||
- 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.39" "praisonaiagents==0.0.92"
|
||||
RUN pip install "praisonai==2.2.40" "praisonaiagents==0.0.92"
|
||||
```
|
||||
|
||||
## 🌐 Production Deployment
|
||||
|
||||
@@ -364,6 +364,66 @@ class LLM:
|
||||
|
||||
return messages, original_prompt
|
||||
|
||||
def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List[Dict]]:
|
||||
"""Format tools for LiteLLM - handles all tool formats.
|
||||
|
||||
Supports:
|
||||
- Pre-formatted OpenAI tools (dicts with type='function')
|
||||
- Lists of pre-formatted tools
|
||||
- Callable functions
|
||||
- String function names
|
||||
|
||||
Args:
|
||||
tools: List of tools in various formats
|
||||
|
||||
Returns:
|
||||
List of formatted tools or None
|
||||
"""
|
||||
if not tools:
|
||||
return None
|
||||
|
||||
formatted_tools = []
|
||||
for tool in tools:
|
||||
# Check if the tool is already in OpenAI format (e.g. from MCP.to_openai_tool())
|
||||
if isinstance(tool, dict) and 'type' in tool and tool['type'] == 'function':
|
||||
# Validate nested dictionary structure before accessing
|
||||
if 'function' in tool and isinstance(tool['function'], dict) and 'name' in tool['function']:
|
||||
logging.debug(f"Using pre-formatted OpenAI tool: {tool['function']['name']}")
|
||||
formatted_tools.append(tool)
|
||||
else:
|
||||
logging.debug(f"Skipping malformed OpenAI tool: missing function or name")
|
||||
# Handle lists of tools (e.g. from MCP.to_openai_tool())
|
||||
elif isinstance(tool, list):
|
||||
for subtool in tool:
|
||||
if isinstance(subtool, dict) and 'type' in subtool and subtool['type'] == 'function':
|
||||
# Validate nested dictionary structure before accessing
|
||||
if 'function' in subtool and isinstance(subtool['function'], dict) and 'name' in subtool['function']:
|
||||
logging.debug(f"Using pre-formatted OpenAI tool from list: {subtool['function']['name']}")
|
||||
formatted_tools.append(subtool)
|
||||
else:
|
||||
logging.debug(f"Skipping malformed OpenAI tool in list: missing function or name")
|
||||
elif callable(tool):
|
||||
tool_def = self._generate_tool_definition(tool)
|
||||
if tool_def:
|
||||
formatted_tools.append(tool_def)
|
||||
elif isinstance(tool, str):
|
||||
tool_def = self._generate_tool_definition(tool)
|
||||
if tool_def:
|
||||
formatted_tools.append(tool_def)
|
||||
else:
|
||||
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
|
||||
|
||||
# Validate JSON serialization before returning
|
||||
if formatted_tools:
|
||||
try:
|
||||
import json
|
||||
json.dumps(formatted_tools) # Validate serialization
|
||||
except (TypeError, ValueError) as e:
|
||||
logging.error(f"Tools are not JSON serializable: {e}")
|
||||
return None
|
||||
|
||||
return formatted_tools if formatted_tools else None
|
||||
|
||||
def get_response(
|
||||
self,
|
||||
prompt: Union[str, List[Dict]],
|
||||
@@ -445,33 +505,7 @@ class LLM:
|
||||
litellm.set_verbose = False
|
||||
|
||||
# Format tools if provided
|
||||
formatted_tools = None
|
||||
if tools:
|
||||
formatted_tools = []
|
||||
for tool in tools:
|
||||
# Check if the tool is already in OpenAI format (e.g. from MCP.to_openai_tool())
|
||||
if isinstance(tool, dict) and 'type' in tool and tool['type'] == 'function':
|
||||
logging.debug(f"Using pre-formatted OpenAI tool: {tool['function']['name']}")
|
||||
formatted_tools.append(tool)
|
||||
# Handle lists of tools (e.g. from MCP.to_openai_tool())
|
||||
elif isinstance(tool, list):
|
||||
for subtool in tool:
|
||||
if isinstance(subtool, dict) and 'type' in subtool and subtool['type'] == 'function':
|
||||
logging.debug(f"Using pre-formatted OpenAI tool from list: {subtool['function']['name']}")
|
||||
formatted_tools.append(subtool)
|
||||
elif callable(tool):
|
||||
tool_def = self._generate_tool_definition(tool.__name__)
|
||||
if tool_def:
|
||||
formatted_tools.append(tool_def)
|
||||
elif isinstance(tool, str):
|
||||
tool_def = self._generate_tool_definition(tool)
|
||||
if tool_def:
|
||||
formatted_tools.append(tool_def)
|
||||
else:
|
||||
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
|
||||
|
||||
if not formatted_tools:
|
||||
formatted_tools = None
|
||||
formatted_tools = self._format_tools_for_litellm(tools)
|
||||
|
||||
# Build messages list using shared helper
|
||||
messages, original_prompt = self._build_messages(
|
||||
@@ -1202,74 +1236,8 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
start_time = time.time()
|
||||
reflection_count = 0
|
||||
|
||||
# Format tools for LiteLLM
|
||||
formatted_tools = None
|
||||
if tools:
|
||||
logging.debug(f"Starting tool formatting for {len(tools)} tools")
|
||||
formatted_tools = []
|
||||
for tool in tools:
|
||||
logging.debug(f"Processing tool: {tool.__name__ if hasattr(tool, '__name__') else str(tool)}")
|
||||
if hasattr(tool, '__name__'):
|
||||
tool_name = tool.__name__
|
||||
tool_doc = tool.__doc__ or "No description available"
|
||||
# Get function signature
|
||||
import inspect
|
||||
sig = inspect.signature(tool)
|
||||
logging.debug(f"Tool signature: {sig}")
|
||||
params = {}
|
||||
required = []
|
||||
for name, param in sig.parameters.items():
|
||||
logging.debug(f"Processing parameter: {name} with annotation: {param.annotation}")
|
||||
param_type = "string"
|
||||
if param.annotation != inspect.Parameter.empty:
|
||||
if param.annotation == int:
|
||||
param_type = "integer"
|
||||
elif param.annotation == float:
|
||||
param_type = "number"
|
||||
elif param.annotation == bool:
|
||||
param_type = "boolean"
|
||||
elif param.annotation == Dict:
|
||||
param_type = "object"
|
||||
elif param.annotation == List:
|
||||
param_type = "array"
|
||||
elif hasattr(param.annotation, "__name__"):
|
||||
param_type = param.annotation.__name__.lower()
|
||||
params[name] = {"type": param_type}
|
||||
if param.default == inspect.Parameter.empty:
|
||||
required.append(name)
|
||||
|
||||
logging.debug(f"Generated parameters: {params}")
|
||||
logging.debug(f"Required parameters: {required}")
|
||||
|
||||
tool_def = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": tool_name,
|
||||
"description": tool_doc,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": params,
|
||||
"required": required
|
||||
}
|
||||
}
|
||||
}
|
||||
# Ensure tool definition is JSON serializable
|
||||
try:
|
||||
json.dumps(tool_def) # Test serialization
|
||||
logging.debug(f"Generated tool definition: {tool_def}")
|
||||
formatted_tools.append(tool_def)
|
||||
except TypeError as e:
|
||||
logging.error(f"Tool definition not JSON serializable: {e}")
|
||||
continue
|
||||
|
||||
# Validate final tools list
|
||||
if formatted_tools:
|
||||
try:
|
||||
json.dumps(formatted_tools) # Final serialization check
|
||||
logging.debug(f"Final formatted tools: {json.dumps(formatted_tools, indent=2)}")
|
||||
except TypeError as e:
|
||||
logging.error(f"Final tools list not JSON serializable: {e}")
|
||||
formatted_tools = None
|
||||
# Format tools for LiteLLM using the shared helper
|
||||
formatted_tools = self._format_tools_for_litellm(tools)
|
||||
|
||||
response_text = ""
|
||||
if reasoning_steps:
|
||||
@@ -2070,36 +2038,44 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
||||
display_error(f"Error in response_async: {str(error)}")
|
||||
raise
|
||||
|
||||
def _generate_tool_definition(self, function_name: str) -> Optional[Dict]:
|
||||
"""Generate a tool definition from a function name."""
|
||||
logging.debug(f"Attempting to generate tool definition for: {function_name}")
|
||||
|
||||
# First try to get the tool definition if it exists
|
||||
tool_def_name = f"{function_name}_definition"
|
||||
tool_def = globals().get(tool_def_name)
|
||||
logging.debug(f"Looking for {tool_def_name} in globals: {tool_def is not None}")
|
||||
|
||||
if not tool_def:
|
||||
import __main__
|
||||
tool_def = getattr(__main__, tool_def_name, None)
|
||||
logging.debug(f"Looking for {tool_def_name} in __main__: {tool_def is not None}")
|
||||
|
||||
if tool_def:
|
||||
logging.debug(f"Found tool definition: {tool_def}")
|
||||
return tool_def
|
||||
def _generate_tool_definition(self, function_or_name) -> Optional[Dict]:
|
||||
"""Generate a tool definition from a function or function name."""
|
||||
if callable(function_or_name):
|
||||
# Function object passed directly
|
||||
func = function_or_name
|
||||
function_name = func.__name__
|
||||
logging.debug(f"Generating tool definition for callable: {function_name}")
|
||||
else:
|
||||
# Function name string passed
|
||||
function_name = function_or_name
|
||||
logging.debug(f"Attempting to generate tool definition for: {function_name}")
|
||||
|
||||
# First try to get the tool definition if it exists
|
||||
tool_def_name = f"{function_name}_definition"
|
||||
tool_def = globals().get(tool_def_name)
|
||||
logging.debug(f"Looking for {tool_def_name} in globals: {tool_def is not None}")
|
||||
|
||||
if not tool_def:
|
||||
import __main__
|
||||
tool_def = getattr(__main__, tool_def_name, None)
|
||||
logging.debug(f"Looking for {tool_def_name} in __main__: {tool_def is not None}")
|
||||
|
||||
if tool_def:
|
||||
logging.debug(f"Found tool definition: {tool_def}")
|
||||
return tool_def
|
||||
|
||||
# Try to find the function
|
||||
func = globals().get(function_name)
|
||||
logging.debug(f"Looking for {function_name} in globals: {func is not None}")
|
||||
|
||||
if not func:
|
||||
import __main__
|
||||
func = getattr(__main__, function_name, None)
|
||||
logging.debug(f"Looking for {function_name} in __main__: {func is not None}")
|
||||
|
||||
if not func or not callable(func):
|
||||
logging.debug(f"Function {function_name} not found or not callable")
|
||||
return None
|
||||
# Try to find the function
|
||||
func = globals().get(function_name)
|
||||
logging.debug(f"Looking for {function_name} in globals: {func is not None}")
|
||||
|
||||
if not func:
|
||||
import __main__
|
||||
func = getattr(__main__, function_name, None)
|
||||
logging.debug(f"Looking for {function_name} in __main__: {func is not None}")
|
||||
|
||||
if not func or not callable(func):
|
||||
logging.debug(f"Function {function_name} not found or not callable")
|
||||
return None
|
||||
|
||||
import inspect
|
||||
# Handle Langchain and CrewAI tools
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.112"
|
||||
version = "0.0.113"
|
||||
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
|
||||
requires-python = ">=3.10"
|
||||
authors = [
|
||||
|
||||
Generated
+1
-1
@@ -2375,7 +2375,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.112"
|
||||
version = "0.0.113"
|
||||
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.39.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.39.tar.gz | shasum -a 256`.split.first
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.40.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.2.40.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.39 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.2.40 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.39"
|
||||
version = "2.2.40"
|
||||
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.112",
|
||||
"praisonaiagents>=0.0.113",
|
||||
"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.39"
|
||||
version = "2.2.40"
|
||||
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.112"
|
||||
praisonaiagents = ">=0.0.113"
|
||||
python-dotenv = ">=0.19.0"
|
||||
instructor = ">=1.3.3"
|
||||
PyYAML = ">=6.0"
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
"""Test script to verify Phase 2 refactoring maintains backward compatibility"""
|
||||
|
||||
import asyncio
|
||||
from src.praisonai_agents.praisonaiagents.llm.llm import LLM
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the correct path for imports
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src/praisonai-agents'))
|
||||
|
||||
from praisonaiagents.llm import LLM
|
||||
|
||||
def test_sync_methods():
|
||||
"""Test synchronous methods still work correctly"""
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify async method supports all tool formats after refactoring.
|
||||
Tests sync vs async parity for all tool format types.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
# Add the source directory to path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../../praisonai-agents'))
|
||||
|
||||
from praisonaiagents.llm import LLM
|
||||
|
||||
# Test function 1: Simple callable
|
||||
def search_tool(query: str) -> str:
|
||||
"""Search for information."""
|
||||
return f"Search results for: {query}"
|
||||
|
||||
# Test function 2: Complex types
|
||||
def complex_tool(data: Dict[str, int], items: List[str], optional: Optional[str] = None) -> Dict:
|
||||
"""Process complex data types."""
|
||||
return {"processed": True, "item_count": len(items)}
|
||||
|
||||
# Pre-formatted OpenAI tool (simulating MCP.to_openai_tool() output)
|
||||
pre_formatted_tool = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "weather_tool",
|
||||
"description": "Get weather information",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {"type": "string", "description": "City name"},
|
||||
"units": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
||||
},
|
||||
"required": ["location"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# List of pre-formatted tools
|
||||
tool_list = [
|
||||
pre_formatted_tool,
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "calculator",
|
||||
"description": "Perform calculations",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"expression": {"type": "string"}
|
||||
},
|
||||
"required": ["expression"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def test_sync_tool_formatting():
|
||||
"""Test sync method tool formatting."""
|
||||
print("\n=== Testing Sync Tool Formatting ===")
|
||||
|
||||
# Use a dummy model that doesn't require actual API calls
|
||||
llm = LLM(model="openai/gpt-3.5-turbo", api_key="test")
|
||||
|
||||
# Test 1: Callable tools
|
||||
print("\n1. Testing callable tools...")
|
||||
formatted = llm._format_tools_for_litellm([search_tool, complex_tool])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 2
|
||||
assert formatted[0]["function"]["name"] == "search_tool"
|
||||
assert formatted[1]["function"]["name"] == "complex_tool"
|
||||
print("✓ Callable tools formatted correctly")
|
||||
|
||||
# Test 2: Pre-formatted tools
|
||||
print("\n2. Testing pre-formatted tools...")
|
||||
formatted = llm._format_tools_for_litellm([pre_formatted_tool])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 1
|
||||
assert formatted[0]["function"]["name"] == "weather_tool"
|
||||
print("✓ Pre-formatted tools passed through correctly")
|
||||
|
||||
# Test 3: List of tools
|
||||
print("\n3. Testing list of tools...")
|
||||
formatted = llm._format_tools_for_litellm([tool_list])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 2
|
||||
assert formatted[0]["function"]["name"] == "weather_tool"
|
||||
assert formatted[1]["function"]["name"] == "calculator"
|
||||
print("✓ Tool lists flattened correctly")
|
||||
|
||||
# Test 4: String tool names
|
||||
print("\n4. Testing string tool names...")
|
||||
# This would need the function to exist in globals
|
||||
globals()['test_string_tool'] = search_tool
|
||||
formatted = llm._format_tools_for_litellm(['test_string_tool'])
|
||||
if formatted: # May not work without proper setup
|
||||
print("✓ String tool names resolved")
|
||||
else:
|
||||
print("⚠ String tool names need proper global setup")
|
||||
|
||||
# Test 5: Mixed formats
|
||||
print("\n5. Testing mixed tool formats...")
|
||||
mixed_tools = [
|
||||
search_tool, # Callable
|
||||
pre_formatted_tool, # Pre-formatted
|
||||
tool_list, # List
|
||||
]
|
||||
formatted = llm._format_tools_for_litellm(mixed_tools)
|
||||
assert formatted is not None
|
||||
assert len(formatted) >= 3 # At least 3 tools
|
||||
print("✓ Mixed formats handled correctly")
|
||||
|
||||
return True
|
||||
|
||||
async def test_async_tool_formatting():
|
||||
"""Test async method tool formatting."""
|
||||
print("\n=== Testing Async Tool Formatting ===")
|
||||
|
||||
# Use a dummy model
|
||||
llm = LLM(model="openai/gpt-3.5-turbo", api_key="test")
|
||||
|
||||
# Test 1: Callable tools (previously the only supported format)
|
||||
print("\n1. Testing callable tools...")
|
||||
formatted = llm._format_tools_for_litellm([search_tool, complex_tool])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 2
|
||||
print("✓ Callable tools formatted correctly")
|
||||
|
||||
# Test 2: Pre-formatted tools (NEW - previously unsupported)
|
||||
print("\n2. Testing pre-formatted tools...")
|
||||
formatted = llm._format_tools_for_litellm([pre_formatted_tool])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 1
|
||||
assert formatted[0]["function"]["name"] == "weather_tool"
|
||||
print("✓ Pre-formatted tools NOW SUPPORTED! ✅")
|
||||
|
||||
# Test 3: List of tools (NEW - previously unsupported)
|
||||
print("\n3. Testing list of tools...")
|
||||
formatted = llm._format_tools_for_litellm([tool_list])
|
||||
assert formatted is not None
|
||||
assert len(formatted) == 2
|
||||
print("✓ Tool lists NOW SUPPORTED! ✅")
|
||||
|
||||
# Test 4: Mixed formats (NEW capability)
|
||||
print("\n4. Testing mixed tool formats...")
|
||||
mixed_tools = [
|
||||
search_tool,
|
||||
pre_formatted_tool,
|
||||
tool_list,
|
||||
]
|
||||
formatted = llm._format_tools_for_litellm(mixed_tools)
|
||||
assert formatted is not None
|
||||
assert len(formatted) >= 3
|
||||
print("✓ Mixed formats NOW SUPPORTED! ✅")
|
||||
|
||||
return True
|
||||
|
||||
def compare_implementations():
|
||||
"""Compare sync and async implementations."""
|
||||
print("\n=== Comparing Sync vs Async ===")
|
||||
|
||||
llm = LLM(model="openai/gpt-3.5-turbo", api_key="test")
|
||||
|
||||
test_tools = [
|
||||
search_tool,
|
||||
pre_formatted_tool,
|
||||
tool_list,
|
||||
]
|
||||
|
||||
# Format with the shared helper (used by both sync and async now)
|
||||
formatted = llm._format_tools_for_litellm(test_tools)
|
||||
|
||||
print(f"\nTotal tools formatted: {len(formatted) if formatted else 0}")
|
||||
print("\nFormatted tools:")
|
||||
if formatted:
|
||||
for tool in formatted:
|
||||
print(f" - {tool['function']['name']}: {tool['function']['description']}")
|
||||
|
||||
print("\n✅ Both sync and async now use the SAME formatting logic!")
|
||||
print("✅ Async now supports ALL tool formats that sync supports!")
|
||||
|
||||
def main():
|
||||
"""Run all tests."""
|
||||
print("Testing Async Tool Format Support")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
# Test sync formatting
|
||||
test_sync_tool_formatting()
|
||||
|
||||
# Test async formatting
|
||||
asyncio.run(test_async_tool_formatting())
|
||||
|
||||
# Compare implementations
|
||||
compare_implementations()
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("✅ ALL TESTS PASSED!")
|
||||
print("\nSummary of changes:")
|
||||
print("- Created _format_tools_for_litellm() helper method")
|
||||
print("- Async now supports pre-formatted tools ✅")
|
||||
print("- Async now supports lists of tools ✅")
|
||||
print("- Async now supports string tool names ✅")
|
||||
print("- Removed ~95 lines of duplicate code")
|
||||
print("- Zero breaking changes - all existing functionality preserved")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Test failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
||||
Generated
+5
-5
@@ -3931,7 +3931,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonai"
|
||||
version = "2.2.39"
|
||||
version = "2.2.40"
|
||||
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.112" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.0.113" },
|
||||
{ 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.112"
|
||||
version = "0.0.113"
|
||||
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/b8/f0/f03a2e64ee0f78824a78275b8a2350f2086a37dd75601b43e740f7a55c3b/praisonaiagents-0.0.112.tar.gz", hash = "sha256:504efc8a427b80a2e4865831c651c834239fb33b7766792e2f3d1157518ac09a", size = 166924 }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/2d/84/9667fa38bcf2956006b993d8c3a62348c694a16981be7e2a1544da8b1b9e/praisonaiagents-0.0.113.tar.gz", hash = "sha256:d09c4b84fd5f0ed319a25b58a87c675d744375df82411ae81c04bcad1e078cab", size = 166496 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/f8/da/83271d3671e468f855e225c9c23fe19b7a5be654ab8f8b0fc305bf1b10f1/praisonaiagents-0.0.112-py3-none-any.whl", hash = "sha256:b402af5eb7e3ffca702aeae89ca01f8f4c223aa194b743a3d9d1feb71e5efd6e", size = 186397 },
|
||||
{ url = "https://files.pythonhosted.org/packages/5e/a7/5c2028e2d07e2095b95385d45e08d4d6cb352d86c637b0cd27b0b1c81a96/praisonaiagents-0.0.113-py3-none-any.whl", hash = "sha256:cc61305147319f67638d68384feecdd6e47cfbe8f6b76adfc540838396d58117", size = 185963 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in new issue
Block a user