PraisonAI 3.0.0__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.
- praisonai/__init__.py +54 -0
- praisonai/__main__.py +15 -0
- praisonai/acp/__init__.py +54 -0
- praisonai/acp/config.py +159 -0
- praisonai/acp/server.py +587 -0
- praisonai/acp/session.py +219 -0
- praisonai/adapters/__init__.py +50 -0
- praisonai/adapters/readers.py +395 -0
- praisonai/adapters/rerankers.py +315 -0
- praisonai/adapters/retrievers.py +394 -0
- praisonai/adapters/vector_stores.py +409 -0
- praisonai/agent_scheduler.py +337 -0
- praisonai/agents_generator.py +903 -0
- praisonai/api/call.py +292 -0
- praisonai/auto.py +1197 -0
- praisonai/capabilities/__init__.py +275 -0
- praisonai/capabilities/a2a.py +140 -0
- praisonai/capabilities/assistants.py +283 -0
- praisonai/capabilities/audio.py +320 -0
- praisonai/capabilities/batches.py +469 -0
- praisonai/capabilities/completions.py +336 -0
- praisonai/capabilities/container_files.py +155 -0
- praisonai/capabilities/containers.py +93 -0
- praisonai/capabilities/embeddings.py +158 -0
- praisonai/capabilities/files.py +467 -0
- praisonai/capabilities/fine_tuning.py +293 -0
- praisonai/capabilities/guardrails.py +182 -0
- praisonai/capabilities/images.py +330 -0
- praisonai/capabilities/mcp.py +190 -0
- praisonai/capabilities/messages.py +270 -0
- praisonai/capabilities/moderations.py +154 -0
- praisonai/capabilities/ocr.py +217 -0
- praisonai/capabilities/passthrough.py +204 -0
- praisonai/capabilities/rag.py +207 -0
- praisonai/capabilities/realtime.py +160 -0
- praisonai/capabilities/rerank.py +165 -0
- praisonai/capabilities/responses.py +266 -0
- praisonai/capabilities/search.py +109 -0
- praisonai/capabilities/skills.py +133 -0
- praisonai/capabilities/vector_store_files.py +334 -0
- praisonai/capabilities/vector_stores.py +304 -0
- praisonai/capabilities/videos.py +141 -0
- praisonai/chainlit_ui.py +304 -0
- praisonai/chat/__init__.py +106 -0
- praisonai/chat/app.py +125 -0
- praisonai/cli/__init__.py +26 -0
- praisonai/cli/app.py +213 -0
- praisonai/cli/commands/__init__.py +75 -0
- praisonai/cli/commands/acp.py +70 -0
- praisonai/cli/commands/completion.py +333 -0
- praisonai/cli/commands/config.py +166 -0
- praisonai/cli/commands/debug.py +142 -0
- praisonai/cli/commands/diag.py +55 -0
- praisonai/cli/commands/doctor.py +166 -0
- praisonai/cli/commands/environment.py +179 -0
- praisonai/cli/commands/lsp.py +112 -0
- praisonai/cli/commands/mcp.py +210 -0
- praisonai/cli/commands/profile.py +457 -0
- praisonai/cli/commands/run.py +228 -0
- praisonai/cli/commands/schedule.py +150 -0
- praisonai/cli/commands/serve.py +97 -0
- praisonai/cli/commands/session.py +212 -0
- praisonai/cli/commands/traces.py +145 -0
- praisonai/cli/commands/version.py +101 -0
- praisonai/cli/configuration/__init__.py +18 -0
- praisonai/cli/configuration/loader.py +353 -0
- praisonai/cli/configuration/paths.py +114 -0
- praisonai/cli/configuration/schema.py +164 -0
- praisonai/cli/features/__init__.py +268 -0
- praisonai/cli/features/acp.py +236 -0
- praisonai/cli/features/action_orchestrator.py +546 -0
- praisonai/cli/features/agent_scheduler.py +773 -0
- praisonai/cli/features/agent_tools.py +474 -0
- praisonai/cli/features/agents.py +375 -0
- praisonai/cli/features/at_mentions.py +471 -0
- praisonai/cli/features/auto_memory.py +182 -0
- praisonai/cli/features/autonomy_mode.py +490 -0
- praisonai/cli/features/background.py +356 -0
- praisonai/cli/features/base.py +168 -0
- praisonai/cli/features/capabilities.py +1326 -0
- praisonai/cli/features/checkpoints.py +338 -0
- praisonai/cli/features/code_intelligence.py +652 -0
- praisonai/cli/features/compaction.py +294 -0
- praisonai/cli/features/compare.py +534 -0
- praisonai/cli/features/cost_tracker.py +514 -0
- praisonai/cli/features/debug.py +810 -0
- praisonai/cli/features/deploy.py +517 -0
- praisonai/cli/features/diag.py +289 -0
- praisonai/cli/features/doctor/__init__.py +63 -0
- praisonai/cli/features/doctor/checks/__init__.py +24 -0
- praisonai/cli/features/doctor/checks/acp_checks.py +240 -0
- praisonai/cli/features/doctor/checks/config_checks.py +366 -0
- praisonai/cli/features/doctor/checks/db_checks.py +366 -0
- praisonai/cli/features/doctor/checks/env_checks.py +543 -0
- praisonai/cli/features/doctor/checks/lsp_checks.py +199 -0
- praisonai/cli/features/doctor/checks/mcp_checks.py +349 -0
- praisonai/cli/features/doctor/checks/memory_checks.py +268 -0
- praisonai/cli/features/doctor/checks/network_checks.py +251 -0
- praisonai/cli/features/doctor/checks/obs_checks.py +328 -0
- praisonai/cli/features/doctor/checks/performance_checks.py +235 -0
- praisonai/cli/features/doctor/checks/permissions_checks.py +259 -0
- praisonai/cli/features/doctor/checks/selftest_checks.py +322 -0
- praisonai/cli/features/doctor/checks/serve_checks.py +426 -0
- praisonai/cli/features/doctor/checks/skills_checks.py +231 -0
- praisonai/cli/features/doctor/checks/tools_checks.py +371 -0
- praisonai/cli/features/doctor/engine.py +266 -0
- praisonai/cli/features/doctor/formatters.py +310 -0
- praisonai/cli/features/doctor/handler.py +397 -0
- praisonai/cli/features/doctor/models.py +264 -0
- praisonai/cli/features/doctor/registry.py +239 -0
- praisonai/cli/features/endpoints.py +1019 -0
- praisonai/cli/features/eval.py +560 -0
- praisonai/cli/features/external_agents.py +231 -0
- praisonai/cli/features/fast_context.py +410 -0
- praisonai/cli/features/flow_display.py +566 -0
- praisonai/cli/features/git_integration.py +651 -0
- praisonai/cli/features/guardrail.py +171 -0
- praisonai/cli/features/handoff.py +185 -0
- praisonai/cli/features/hooks.py +583 -0
- praisonai/cli/features/image.py +384 -0
- praisonai/cli/features/interactive_runtime.py +585 -0
- praisonai/cli/features/interactive_tools.py +380 -0
- praisonai/cli/features/interactive_tui.py +603 -0
- praisonai/cli/features/jobs.py +632 -0
- praisonai/cli/features/knowledge.py +531 -0
- praisonai/cli/features/lite.py +244 -0
- praisonai/cli/features/lsp_cli.py +225 -0
- praisonai/cli/features/mcp.py +169 -0
- praisonai/cli/features/message_queue.py +587 -0
- praisonai/cli/features/metrics.py +211 -0
- praisonai/cli/features/n8n.py +673 -0
- praisonai/cli/features/observability.py +293 -0
- praisonai/cli/features/ollama.py +361 -0
- praisonai/cli/features/output_style.py +273 -0
- praisonai/cli/features/package.py +631 -0
- praisonai/cli/features/performance.py +308 -0
- praisonai/cli/features/persistence.py +636 -0
- praisonai/cli/features/profile.py +226 -0
- praisonai/cli/features/profiler/__init__.py +81 -0
- praisonai/cli/features/profiler/core.py +558 -0
- praisonai/cli/features/profiler/optimizations.py +652 -0
- praisonai/cli/features/profiler/suite.py +386 -0
- praisonai/cli/features/profiling.py +350 -0
- praisonai/cli/features/queue/__init__.py +73 -0
- praisonai/cli/features/queue/manager.py +395 -0
- praisonai/cli/features/queue/models.py +286 -0
- praisonai/cli/features/queue/persistence.py +564 -0
- praisonai/cli/features/queue/scheduler.py +484 -0
- praisonai/cli/features/queue/worker.py +372 -0
- praisonai/cli/features/recipe.py +1723 -0
- praisonai/cli/features/recipes.py +449 -0
- praisonai/cli/features/registry.py +229 -0
- praisonai/cli/features/repo_map.py +860 -0
- praisonai/cli/features/router.py +466 -0
- praisonai/cli/features/sandbox_executor.py +515 -0
- praisonai/cli/features/serve.py +829 -0
- praisonai/cli/features/session.py +222 -0
- praisonai/cli/features/skills.py +856 -0
- praisonai/cli/features/slash_commands.py +650 -0
- praisonai/cli/features/telemetry.py +179 -0
- praisonai/cli/features/templates.py +1384 -0
- praisonai/cli/features/thinking.py +305 -0
- praisonai/cli/features/todo.py +334 -0
- praisonai/cli/features/tools.py +680 -0
- praisonai/cli/features/tui/__init__.py +83 -0
- praisonai/cli/features/tui/app.py +580 -0
- praisonai/cli/features/tui/cli.py +566 -0
- praisonai/cli/features/tui/debug.py +511 -0
- praisonai/cli/features/tui/events.py +99 -0
- praisonai/cli/features/tui/mock_provider.py +328 -0
- praisonai/cli/features/tui/orchestrator.py +652 -0
- praisonai/cli/features/tui/screens/__init__.py +50 -0
- praisonai/cli/features/tui/screens/main.py +245 -0
- praisonai/cli/features/tui/screens/queue.py +174 -0
- praisonai/cli/features/tui/screens/session.py +124 -0
- praisonai/cli/features/tui/screens/settings.py +148 -0
- praisonai/cli/features/tui/widgets/__init__.py +56 -0
- praisonai/cli/features/tui/widgets/chat.py +261 -0
- praisonai/cli/features/tui/widgets/composer.py +224 -0
- praisonai/cli/features/tui/widgets/queue_panel.py +200 -0
- praisonai/cli/features/tui/widgets/status.py +167 -0
- praisonai/cli/features/tui/widgets/tool_panel.py +248 -0
- praisonai/cli/features/workflow.py +720 -0
- praisonai/cli/legacy.py +236 -0
- praisonai/cli/main.py +5559 -0
- praisonai/cli/schedule_cli.py +54 -0
- praisonai/cli/state/__init__.py +31 -0
- praisonai/cli/state/identifiers.py +161 -0
- praisonai/cli/state/sessions.py +313 -0
- praisonai/code/__init__.py +93 -0
- praisonai/code/agent_tools.py +344 -0
- praisonai/code/diff/__init__.py +21 -0
- praisonai/code/diff/diff_strategy.py +432 -0
- praisonai/code/tools/__init__.py +27 -0
- praisonai/code/tools/apply_diff.py +221 -0
- praisonai/code/tools/execute_command.py +275 -0
- praisonai/code/tools/list_files.py +274 -0
- praisonai/code/tools/read_file.py +206 -0
- praisonai/code/tools/search_replace.py +248 -0
- praisonai/code/tools/write_file.py +217 -0
- praisonai/code/utils/__init__.py +46 -0
- praisonai/code/utils/file_utils.py +307 -0
- praisonai/code/utils/ignore_utils.py +308 -0
- praisonai/code/utils/text_utils.py +276 -0
- praisonai/db/__init__.py +64 -0
- praisonai/db/adapter.py +531 -0
- praisonai/deploy/__init__.py +62 -0
- praisonai/deploy/api.py +231 -0
- praisonai/deploy/docker.py +454 -0
- praisonai/deploy/doctor.py +367 -0
- praisonai/deploy/main.py +327 -0
- praisonai/deploy/models.py +179 -0
- praisonai/deploy/providers/__init__.py +33 -0
- praisonai/deploy/providers/aws.py +331 -0
- praisonai/deploy/providers/azure.py +358 -0
- praisonai/deploy/providers/base.py +101 -0
- praisonai/deploy/providers/gcp.py +314 -0
- praisonai/deploy/schema.py +208 -0
- praisonai/deploy.py +185 -0
- praisonai/endpoints/__init__.py +53 -0
- praisonai/endpoints/a2u_server.py +410 -0
- praisonai/endpoints/discovery.py +165 -0
- praisonai/endpoints/providers/__init__.py +28 -0
- praisonai/endpoints/providers/a2a.py +253 -0
- praisonai/endpoints/providers/a2u.py +208 -0
- praisonai/endpoints/providers/agents_api.py +171 -0
- praisonai/endpoints/providers/base.py +231 -0
- praisonai/endpoints/providers/mcp.py +263 -0
- praisonai/endpoints/providers/recipe.py +206 -0
- praisonai/endpoints/providers/tools_mcp.py +150 -0
- praisonai/endpoints/registry.py +131 -0
- praisonai/endpoints/server.py +161 -0
- praisonai/inbuilt_tools/__init__.py +24 -0
- praisonai/inbuilt_tools/autogen_tools.py +117 -0
- praisonai/inc/__init__.py +2 -0
- praisonai/inc/config.py +96 -0
- praisonai/inc/models.py +155 -0
- praisonai/integrations/__init__.py +56 -0
- praisonai/integrations/base.py +303 -0
- praisonai/integrations/claude_code.py +270 -0
- praisonai/integrations/codex_cli.py +255 -0
- praisonai/integrations/cursor_cli.py +195 -0
- praisonai/integrations/gemini_cli.py +222 -0
- praisonai/jobs/__init__.py +67 -0
- praisonai/jobs/executor.py +425 -0
- praisonai/jobs/models.py +230 -0
- praisonai/jobs/router.py +314 -0
- praisonai/jobs/server.py +186 -0
- praisonai/jobs/store.py +203 -0
- praisonai/llm/__init__.py +66 -0
- praisonai/llm/registry.py +382 -0
- praisonai/mcp_server/__init__.py +152 -0
- praisonai/mcp_server/adapters/__init__.py +74 -0
- praisonai/mcp_server/adapters/agents.py +128 -0
- praisonai/mcp_server/adapters/capabilities.py +168 -0
- praisonai/mcp_server/adapters/cli_tools.py +568 -0
- praisonai/mcp_server/adapters/extended_capabilities.py +462 -0
- praisonai/mcp_server/adapters/knowledge.py +93 -0
- praisonai/mcp_server/adapters/memory.py +104 -0
- praisonai/mcp_server/adapters/prompts.py +306 -0
- praisonai/mcp_server/adapters/resources.py +124 -0
- praisonai/mcp_server/adapters/tools_bridge.py +280 -0
- praisonai/mcp_server/auth/__init__.py +48 -0
- praisonai/mcp_server/auth/api_key.py +291 -0
- praisonai/mcp_server/auth/oauth.py +460 -0
- praisonai/mcp_server/auth/oidc.py +289 -0
- praisonai/mcp_server/auth/scopes.py +260 -0
- praisonai/mcp_server/cli.py +852 -0
- praisonai/mcp_server/elicitation.py +445 -0
- praisonai/mcp_server/icons.py +302 -0
- praisonai/mcp_server/recipe_adapter.py +573 -0
- praisonai/mcp_server/recipe_cli.py +824 -0
- praisonai/mcp_server/registry.py +703 -0
- praisonai/mcp_server/sampling.py +422 -0
- praisonai/mcp_server/server.py +490 -0
- praisonai/mcp_server/tasks.py +443 -0
- praisonai/mcp_server/transports/__init__.py +18 -0
- praisonai/mcp_server/transports/http_stream.py +376 -0
- praisonai/mcp_server/transports/stdio.py +132 -0
- praisonai/persistence/__init__.py +84 -0
- praisonai/persistence/config.py +238 -0
- praisonai/persistence/conversation/__init__.py +25 -0
- praisonai/persistence/conversation/async_mysql.py +427 -0
- praisonai/persistence/conversation/async_postgres.py +410 -0
- praisonai/persistence/conversation/async_sqlite.py +371 -0
- praisonai/persistence/conversation/base.py +151 -0
- praisonai/persistence/conversation/json_store.py +250 -0
- praisonai/persistence/conversation/mysql.py +387 -0
- praisonai/persistence/conversation/postgres.py +401 -0
- praisonai/persistence/conversation/singlestore.py +240 -0
- praisonai/persistence/conversation/sqlite.py +341 -0
- praisonai/persistence/conversation/supabase.py +203 -0
- praisonai/persistence/conversation/surrealdb.py +287 -0
- praisonai/persistence/factory.py +301 -0
- praisonai/persistence/hooks/__init__.py +18 -0
- praisonai/persistence/hooks/agent_hooks.py +297 -0
- praisonai/persistence/knowledge/__init__.py +26 -0
- praisonai/persistence/knowledge/base.py +144 -0
- praisonai/persistence/knowledge/cassandra.py +232 -0
- praisonai/persistence/knowledge/chroma.py +295 -0
- praisonai/persistence/knowledge/clickhouse.py +242 -0
- praisonai/persistence/knowledge/cosmosdb_vector.py +438 -0
- praisonai/persistence/knowledge/couchbase.py +286 -0
- praisonai/persistence/knowledge/lancedb.py +216 -0
- praisonai/persistence/knowledge/langchain_adapter.py +291 -0
- praisonai/persistence/knowledge/lightrag_adapter.py +212 -0
- praisonai/persistence/knowledge/llamaindex_adapter.py +256 -0
- praisonai/persistence/knowledge/milvus.py +277 -0
- praisonai/persistence/knowledge/mongodb_vector.py +306 -0
- praisonai/persistence/knowledge/pgvector.py +335 -0
- praisonai/persistence/knowledge/pinecone.py +253 -0
- praisonai/persistence/knowledge/qdrant.py +301 -0
- praisonai/persistence/knowledge/redis_vector.py +291 -0
- praisonai/persistence/knowledge/singlestore_vector.py +299 -0
- praisonai/persistence/knowledge/surrealdb_vector.py +309 -0
- praisonai/persistence/knowledge/upstash_vector.py +266 -0
- praisonai/persistence/knowledge/weaviate.py +223 -0
- praisonai/persistence/migrations/__init__.py +10 -0
- praisonai/persistence/migrations/manager.py +251 -0
- praisonai/persistence/orchestrator.py +406 -0
- praisonai/persistence/state/__init__.py +21 -0
- praisonai/persistence/state/async_mongodb.py +200 -0
- praisonai/persistence/state/base.py +107 -0
- praisonai/persistence/state/dynamodb.py +226 -0
- praisonai/persistence/state/firestore.py +175 -0
- praisonai/persistence/state/gcs.py +155 -0
- praisonai/persistence/state/memory.py +245 -0
- praisonai/persistence/state/mongodb.py +158 -0
- praisonai/persistence/state/redis.py +190 -0
- praisonai/persistence/state/upstash.py +144 -0
- praisonai/persistence/tests/__init__.py +3 -0
- praisonai/persistence/tests/test_all_backends.py +633 -0
- praisonai/profiler.py +1214 -0
- praisonai/recipe/__init__.py +134 -0
- praisonai/recipe/bridge.py +278 -0
- praisonai/recipe/core.py +893 -0
- praisonai/recipe/exceptions.py +54 -0
- praisonai/recipe/history.py +402 -0
- praisonai/recipe/models.py +266 -0
- praisonai/recipe/operations.py +440 -0
- praisonai/recipe/policy.py +422 -0
- praisonai/recipe/registry.py +849 -0
- praisonai/recipe/runtime.py +214 -0
- praisonai/recipe/security.py +711 -0
- praisonai/recipe/serve.py +859 -0
- praisonai/recipe/server.py +613 -0
- praisonai/scheduler/__init__.py +45 -0
- praisonai/scheduler/agent_scheduler.py +552 -0
- praisonai/scheduler/base.py +124 -0
- praisonai/scheduler/daemon_manager.py +225 -0
- praisonai/scheduler/state_manager.py +155 -0
- praisonai/scheduler/yaml_loader.py +193 -0
- praisonai/scheduler.py +194 -0
- praisonai/setup/__init__.py +1 -0
- praisonai/setup/build.py +21 -0
- praisonai/setup/post_install.py +23 -0
- praisonai/setup/setup_conda_env.py +25 -0
- praisonai/setup.py +16 -0
- praisonai/templates/__init__.py +116 -0
- praisonai/templates/cache.py +364 -0
- praisonai/templates/dependency_checker.py +358 -0
- praisonai/templates/discovery.py +391 -0
- praisonai/templates/loader.py +564 -0
- praisonai/templates/registry.py +511 -0
- praisonai/templates/resolver.py +206 -0
- praisonai/templates/security.py +327 -0
- praisonai/templates/tool_override.py +498 -0
- praisonai/templates/tools_doctor.py +256 -0
- praisonai/test.py +105 -0
- praisonai/train.py +562 -0
- praisonai/train_vision.py +306 -0
- praisonai/ui/agents.py +824 -0
- praisonai/ui/callbacks.py +57 -0
- praisonai/ui/chainlit_compat.py +246 -0
- praisonai/ui/chat.py +532 -0
- praisonai/ui/code.py +717 -0
- praisonai/ui/colab.py +474 -0
- praisonai/ui/colab_chainlit.py +81 -0
- praisonai/ui/components/aicoder.py +284 -0
- praisonai/ui/context.py +283 -0
- praisonai/ui/database_config.py +56 -0
- praisonai/ui/db.py +294 -0
- praisonai/ui/realtime.py +488 -0
- praisonai/ui/realtimeclient/__init__.py +756 -0
- praisonai/ui/realtimeclient/tools.py +242 -0
- praisonai/ui/sql_alchemy.py +710 -0
- praisonai/upload_vision.py +140 -0
- praisonai/version.py +1 -0
- praisonai-3.0.0.dist-info/METADATA +3493 -0
- praisonai-3.0.0.dist-info/RECORD +393 -0
- praisonai-3.0.0.dist-info/WHEEL +5 -0
- praisonai-3.0.0.dist-info/entry_points.txt +4 -0
- praisonai-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1326 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Capabilities CLI Handler
|
|
3
|
+
|
|
4
|
+
Provides CLI commands for all LiteLLM endpoint capabilities.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Optional, List
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CapabilitiesHandler:
|
|
13
|
+
"""Handler for capabilities CLI commands."""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def handle_audio(args, unknown_args):
|
|
17
|
+
"""Handle audio subcommands (transcribe, speech)."""
|
|
18
|
+
if not unknown_args:
|
|
19
|
+
print("Usage: praisonai audio <transcribe|speech> [options]")
|
|
20
|
+
print("\nSubcommands:")
|
|
21
|
+
print(" transcribe Transcribe audio to text")
|
|
22
|
+
print(" speech Convert text to speech")
|
|
23
|
+
return 1
|
|
24
|
+
|
|
25
|
+
subcommand = unknown_args[0]
|
|
26
|
+
remaining_args = unknown_args[1:]
|
|
27
|
+
|
|
28
|
+
if subcommand == "transcribe":
|
|
29
|
+
return CapabilitiesHandler._handle_audio_transcribe(args, remaining_args)
|
|
30
|
+
elif subcommand == "speech":
|
|
31
|
+
return CapabilitiesHandler._handle_audio_speech(args, remaining_args)
|
|
32
|
+
else:
|
|
33
|
+
print(f"Unknown audio subcommand: {subcommand}")
|
|
34
|
+
return 1
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def _handle_audio_transcribe(args, remaining_args):
|
|
38
|
+
"""Handle: praisonai audio transcribe <file> [options]"""
|
|
39
|
+
parser = argparse.ArgumentParser(prog="praisonai audio transcribe")
|
|
40
|
+
parser.add_argument("file", help="Audio file to transcribe")
|
|
41
|
+
parser.add_argument("--model", "-m", default="whisper-1", help="Model to use")
|
|
42
|
+
parser.add_argument("--language", "-l", help="Language code (e.g., en, es)")
|
|
43
|
+
parser.add_argument("--format", "-f", default="text",
|
|
44
|
+
choices=["json", "text", "srt", "vtt", "verbose_json"],
|
|
45
|
+
help="Output format")
|
|
46
|
+
parser.add_argument("--output", "-o", help="Output file path")
|
|
47
|
+
parser.add_argument("--prompt", "-p", help="Prompt to guide transcription")
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
parsed = parser.parse_args(remaining_args)
|
|
51
|
+
except SystemExit:
|
|
52
|
+
return 1
|
|
53
|
+
|
|
54
|
+
from praisonai.capabilities.audio import transcribe
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
result = transcribe(
|
|
58
|
+
audio=parsed.file,
|
|
59
|
+
model=parsed.model,
|
|
60
|
+
language=parsed.language,
|
|
61
|
+
prompt=parsed.prompt,
|
|
62
|
+
response_format=parsed.format,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if parsed.output:
|
|
66
|
+
with open(parsed.output, 'w') as f:
|
|
67
|
+
f.write(result.text)
|
|
68
|
+
print(f"Transcription saved to: {parsed.output}")
|
|
69
|
+
else:
|
|
70
|
+
print(result.text)
|
|
71
|
+
|
|
72
|
+
return 0
|
|
73
|
+
except Exception as e:
|
|
74
|
+
print(f"Error: {e}")
|
|
75
|
+
return 1
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def _handle_audio_speech(args, remaining_args):
|
|
79
|
+
"""Handle: praisonai audio speech <text> [options]"""
|
|
80
|
+
parser = argparse.ArgumentParser(prog="praisonai audio speech")
|
|
81
|
+
parser.add_argument("text", help="Text to convert to speech")
|
|
82
|
+
parser.add_argument("--model", "-m", default="tts-1", help="Model to use")
|
|
83
|
+
parser.add_argument("--voice", "-v", default="alloy",
|
|
84
|
+
choices=["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
|
|
85
|
+
help="Voice to use")
|
|
86
|
+
parser.add_argument("--format", "-f", default="mp3",
|
|
87
|
+
choices=["mp3", "opus", "aac", "flac", "wav", "pcm"],
|
|
88
|
+
help="Output format")
|
|
89
|
+
parser.add_argument("--output", "-o", default="output.mp3", help="Output file path")
|
|
90
|
+
parser.add_argument("--speed", "-s", type=float, default=1.0, help="Speed (0.25-4.0)")
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
parsed = parser.parse_args(remaining_args)
|
|
94
|
+
except SystemExit:
|
|
95
|
+
return 1
|
|
96
|
+
|
|
97
|
+
from praisonai.capabilities.audio import speech
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
result = speech(
|
|
101
|
+
text=parsed.text,
|
|
102
|
+
model=parsed.model,
|
|
103
|
+
voice=parsed.voice,
|
|
104
|
+
response_format=parsed.format,
|
|
105
|
+
speed=parsed.speed,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
result.save(parsed.output)
|
|
109
|
+
print(f"Audio saved to: {parsed.output}")
|
|
110
|
+
|
|
111
|
+
return 0
|
|
112
|
+
except Exception as e:
|
|
113
|
+
print(f"Error: {e}")
|
|
114
|
+
return 1
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def handle_images(args, unknown_args):
|
|
118
|
+
"""Handle images subcommands."""
|
|
119
|
+
if not unknown_args:
|
|
120
|
+
print("Usage: praisonai images <generate|edit> [options]")
|
|
121
|
+
print("\nSubcommands:")
|
|
122
|
+
print(" generate Generate images from text")
|
|
123
|
+
print(" edit Edit an existing image")
|
|
124
|
+
return 1
|
|
125
|
+
|
|
126
|
+
subcommand = unknown_args[0]
|
|
127
|
+
remaining_args = unknown_args[1:]
|
|
128
|
+
|
|
129
|
+
if subcommand == "generate":
|
|
130
|
+
return CapabilitiesHandler._handle_images_generate(args, remaining_args)
|
|
131
|
+
elif subcommand == "edit":
|
|
132
|
+
return CapabilitiesHandler._handle_images_edit(args, remaining_args)
|
|
133
|
+
else:
|
|
134
|
+
print(f"Unknown images subcommand: {subcommand}")
|
|
135
|
+
return 1
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def _handle_images_generate(args, remaining_args):
|
|
139
|
+
"""Handle: praisonai images generate <prompt> [options]"""
|
|
140
|
+
parser = argparse.ArgumentParser(prog="praisonai images generate")
|
|
141
|
+
parser.add_argument("prompt", help="Text description of the image")
|
|
142
|
+
parser.add_argument("--model", "-m", default="dall-e-3", help="Model to use")
|
|
143
|
+
parser.add_argument("--size", "-s", default="1024x1024", help="Image size")
|
|
144
|
+
parser.add_argument("--quality", "-q", default="standard", choices=["standard", "hd"])
|
|
145
|
+
parser.add_argument("--output", "-o", default="output.png", help="Output file path")
|
|
146
|
+
parser.add_argument("--n", type=int, default=1, help="Number of images")
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
parsed = parser.parse_args(remaining_args)
|
|
150
|
+
except SystemExit:
|
|
151
|
+
return 1
|
|
152
|
+
|
|
153
|
+
from praisonai.capabilities.images import image_generate
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
results = image_generate(
|
|
157
|
+
prompt=parsed.prompt,
|
|
158
|
+
model=parsed.model,
|
|
159
|
+
size=parsed.size,
|
|
160
|
+
quality=parsed.quality,
|
|
161
|
+
n=parsed.n,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
for i, result in enumerate(results):
|
|
165
|
+
output_path = parsed.output if len(results) == 1 else f"{parsed.output.rsplit('.', 1)[0]}_{i}.{parsed.output.rsplit('.', 1)[1]}"
|
|
166
|
+
result.save(output_path)
|
|
167
|
+
print(f"Image saved to: {output_path}")
|
|
168
|
+
|
|
169
|
+
return 0
|
|
170
|
+
except Exception as e:
|
|
171
|
+
print(f"Error: {e}")
|
|
172
|
+
return 1
|
|
173
|
+
|
|
174
|
+
@staticmethod
|
|
175
|
+
def _handle_images_edit(args, remaining_args):
|
|
176
|
+
"""Handle: praisonai images edit <image> <prompt> [options]"""
|
|
177
|
+
parser = argparse.ArgumentParser(prog="praisonai images edit")
|
|
178
|
+
parser.add_argument("image", help="Image file to edit")
|
|
179
|
+
parser.add_argument("prompt", help="Edit description")
|
|
180
|
+
parser.add_argument("--mask", help="Mask image file")
|
|
181
|
+
parser.add_argument("--output", "-o", default="output.png", help="Output file path")
|
|
182
|
+
|
|
183
|
+
try:
|
|
184
|
+
parsed = parser.parse_args(remaining_args)
|
|
185
|
+
except SystemExit:
|
|
186
|
+
return 1
|
|
187
|
+
|
|
188
|
+
from praisonai.capabilities.images import image_edit
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
results = image_edit(
|
|
192
|
+
image=parsed.image,
|
|
193
|
+
prompt=parsed.prompt,
|
|
194
|
+
mask=parsed.mask,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
for i, result in enumerate(results):
|
|
198
|
+
output_path = parsed.output if len(results) == 1 else f"{parsed.output.rsplit('.', 1)[0]}_{i}.{parsed.output.rsplit('.', 1)[1]}"
|
|
199
|
+
result.save(output_path)
|
|
200
|
+
print(f"Image saved to: {output_path}")
|
|
201
|
+
|
|
202
|
+
return 0
|
|
203
|
+
except Exception as e:
|
|
204
|
+
print(f"Error: {e}")
|
|
205
|
+
return 1
|
|
206
|
+
|
|
207
|
+
@staticmethod
|
|
208
|
+
def handle_files(args, unknown_args):
|
|
209
|
+
"""Handle files subcommands."""
|
|
210
|
+
if not unknown_args:
|
|
211
|
+
print("Usage: praisonai files <upload|list|get|delete> [options]")
|
|
212
|
+
print("\nSubcommands:")
|
|
213
|
+
print(" upload Upload a file")
|
|
214
|
+
print(" list List uploaded files")
|
|
215
|
+
print(" get Get file info")
|
|
216
|
+
print(" delete Delete a file")
|
|
217
|
+
return 1
|
|
218
|
+
|
|
219
|
+
subcommand = unknown_args[0]
|
|
220
|
+
remaining_args = unknown_args[1:]
|
|
221
|
+
|
|
222
|
+
if subcommand == "upload":
|
|
223
|
+
return CapabilitiesHandler._handle_files_upload(args, remaining_args)
|
|
224
|
+
elif subcommand == "list":
|
|
225
|
+
return CapabilitiesHandler._handle_files_list(args, remaining_args)
|
|
226
|
+
elif subcommand == "get":
|
|
227
|
+
return CapabilitiesHandler._handle_files_get(args, remaining_args)
|
|
228
|
+
elif subcommand == "delete":
|
|
229
|
+
return CapabilitiesHandler._handle_files_delete(args, remaining_args)
|
|
230
|
+
else:
|
|
231
|
+
print(f"Unknown files subcommand: {subcommand}")
|
|
232
|
+
return 1
|
|
233
|
+
|
|
234
|
+
@staticmethod
|
|
235
|
+
def _handle_files_upload(args, remaining_args):
|
|
236
|
+
"""Handle: praisonai files upload <file> [options]"""
|
|
237
|
+
parser = argparse.ArgumentParser(prog="praisonai files upload")
|
|
238
|
+
parser.add_argument("file", help="File to upload")
|
|
239
|
+
parser.add_argument("--purpose", "-p", default="assistants",
|
|
240
|
+
choices=["assistants", "batch", "fine-tune"],
|
|
241
|
+
help="Purpose of the file")
|
|
242
|
+
|
|
243
|
+
try:
|
|
244
|
+
parsed = parser.parse_args(remaining_args)
|
|
245
|
+
except SystemExit:
|
|
246
|
+
return 1
|
|
247
|
+
|
|
248
|
+
from praisonai.capabilities.files import file_create
|
|
249
|
+
|
|
250
|
+
try:
|
|
251
|
+
result = file_create(
|
|
252
|
+
file=parsed.file,
|
|
253
|
+
purpose=parsed.purpose,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
print(f"File uploaded: {result.id}")
|
|
257
|
+
print(f" Filename: {result.filename}")
|
|
258
|
+
print(f" Purpose: {result.purpose}")
|
|
259
|
+
print(f" Bytes: {result.bytes}")
|
|
260
|
+
|
|
261
|
+
return 0
|
|
262
|
+
except Exception as e:
|
|
263
|
+
print(f"Error: {e}")
|
|
264
|
+
return 1
|
|
265
|
+
|
|
266
|
+
@staticmethod
|
|
267
|
+
def _handle_files_list(args, remaining_args):
|
|
268
|
+
"""Handle: praisonai files list [options]"""
|
|
269
|
+
parser = argparse.ArgumentParser(prog="praisonai files list")
|
|
270
|
+
parser.add_argument("--purpose", "-p", help="Filter by purpose")
|
|
271
|
+
|
|
272
|
+
try:
|
|
273
|
+
parsed = parser.parse_args(remaining_args)
|
|
274
|
+
except SystemExit:
|
|
275
|
+
return 1
|
|
276
|
+
|
|
277
|
+
from praisonai.capabilities.files import file_list
|
|
278
|
+
|
|
279
|
+
try:
|
|
280
|
+
results = file_list(purpose=parsed.purpose)
|
|
281
|
+
|
|
282
|
+
if not results:
|
|
283
|
+
print("No files found.")
|
|
284
|
+
else:
|
|
285
|
+
for f in results:
|
|
286
|
+
print(f"{f.id}: {f.filename} ({f.purpose})")
|
|
287
|
+
|
|
288
|
+
return 0
|
|
289
|
+
except Exception as e:
|
|
290
|
+
print(f"Error: {e}")
|
|
291
|
+
return 1
|
|
292
|
+
|
|
293
|
+
@staticmethod
|
|
294
|
+
def _handle_files_get(args, remaining_args):
|
|
295
|
+
"""Handle: praisonai files get <file_id>"""
|
|
296
|
+
parser = argparse.ArgumentParser(prog="praisonai files get")
|
|
297
|
+
parser.add_argument("file_id", help="File ID")
|
|
298
|
+
|
|
299
|
+
try:
|
|
300
|
+
parsed = parser.parse_args(remaining_args)
|
|
301
|
+
except SystemExit:
|
|
302
|
+
return 1
|
|
303
|
+
|
|
304
|
+
from praisonai.capabilities.files import file_retrieve
|
|
305
|
+
|
|
306
|
+
try:
|
|
307
|
+
result = file_retrieve(file_id=parsed.file_id)
|
|
308
|
+
|
|
309
|
+
print(f"File: {result.id}")
|
|
310
|
+
print(f" Filename: {result.filename}")
|
|
311
|
+
print(f" Purpose: {result.purpose}")
|
|
312
|
+
print(f" Bytes: {result.bytes}")
|
|
313
|
+
print(f" Status: {result.status}")
|
|
314
|
+
|
|
315
|
+
return 0
|
|
316
|
+
except Exception as e:
|
|
317
|
+
print(f"Error: {e}")
|
|
318
|
+
return 1
|
|
319
|
+
|
|
320
|
+
@staticmethod
|
|
321
|
+
def _handle_files_delete(args, remaining_args):
|
|
322
|
+
"""Handle: praisonai files delete <file_id>"""
|
|
323
|
+
parser = argparse.ArgumentParser(prog="praisonai files delete")
|
|
324
|
+
parser.add_argument("file_id", help="File ID")
|
|
325
|
+
|
|
326
|
+
try:
|
|
327
|
+
parsed = parser.parse_args(remaining_args)
|
|
328
|
+
except SystemExit:
|
|
329
|
+
return 1
|
|
330
|
+
|
|
331
|
+
from praisonai.capabilities.files import file_delete
|
|
332
|
+
|
|
333
|
+
try:
|
|
334
|
+
result = file_delete(file_id=parsed.file_id)
|
|
335
|
+
|
|
336
|
+
if result:
|
|
337
|
+
print(f"File deleted: {parsed.file_id}")
|
|
338
|
+
else:
|
|
339
|
+
print(f"Failed to delete file: {parsed.file_id}")
|
|
340
|
+
|
|
341
|
+
return 0
|
|
342
|
+
except Exception as e:
|
|
343
|
+
print(f"Error: {e}")
|
|
344
|
+
return 1
|
|
345
|
+
|
|
346
|
+
@staticmethod
|
|
347
|
+
def handle_embed(args, unknown_args):
|
|
348
|
+
"""Handle embed command."""
|
|
349
|
+
parser = argparse.ArgumentParser(prog="praisonai embed")
|
|
350
|
+
parser.add_argument("text", nargs="+", help="Text to embed")
|
|
351
|
+
parser.add_argument("--model", "-m", default="text-embedding-3-small", help="Model to use")
|
|
352
|
+
parser.add_argument("--dimensions", "-d", type=int, help="Output dimensions")
|
|
353
|
+
|
|
354
|
+
try:
|
|
355
|
+
parsed = parser.parse_args(unknown_args)
|
|
356
|
+
except SystemExit:
|
|
357
|
+
return 1
|
|
358
|
+
|
|
359
|
+
from praisonai.capabilities.embeddings import embed
|
|
360
|
+
|
|
361
|
+
try:
|
|
362
|
+
text_input = " ".join(parsed.text)
|
|
363
|
+
result = embed(
|
|
364
|
+
input=text_input,
|
|
365
|
+
model=parsed.model,
|
|
366
|
+
dimensions=parsed.dimensions,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
print(f"Embeddings generated: {len(result.embeddings)} vectors")
|
|
370
|
+
print(f"Dimensions: {len(result.embeddings[0]) if result.embeddings else 0}")
|
|
371
|
+
if result.usage:
|
|
372
|
+
print(f"Tokens: {result.usage.get('total_tokens', 0)}")
|
|
373
|
+
|
|
374
|
+
return 0
|
|
375
|
+
except Exception as e:
|
|
376
|
+
print(f"Error: {e}")
|
|
377
|
+
return 1
|
|
378
|
+
|
|
379
|
+
@staticmethod
|
|
380
|
+
def handle_rerank(args, unknown_args):
|
|
381
|
+
"""Handle rerank command."""
|
|
382
|
+
parser = argparse.ArgumentParser(prog="praisonai rerank")
|
|
383
|
+
parser.add_argument("query", help="Query to rank against")
|
|
384
|
+
parser.add_argument("--documents", "-d", nargs="+", required=True, help="Documents to rank")
|
|
385
|
+
parser.add_argument("--model", "-m", default="cohere/rerank-english-v3.0", help="Model to use")
|
|
386
|
+
parser.add_argument("--top-n", "-n", type=int, help="Number of top results")
|
|
387
|
+
|
|
388
|
+
try:
|
|
389
|
+
parsed = parser.parse_args(unknown_args)
|
|
390
|
+
except SystemExit:
|
|
391
|
+
return 1
|
|
392
|
+
|
|
393
|
+
from praisonai.capabilities.rerank import rerank
|
|
394
|
+
|
|
395
|
+
try:
|
|
396
|
+
result = rerank(
|
|
397
|
+
query=parsed.query,
|
|
398
|
+
documents=parsed.documents,
|
|
399
|
+
model=parsed.model,
|
|
400
|
+
top_n=parsed.top_n,
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
print(f"Ranked {len(result.results)} documents:")
|
|
404
|
+
for r in result.results:
|
|
405
|
+
print(f" [{r['index']}] Score: {r['relevance_score']:.4f}")
|
|
406
|
+
|
|
407
|
+
return 0
|
|
408
|
+
except Exception as e:
|
|
409
|
+
print(f"Error: {e}")
|
|
410
|
+
return 1
|
|
411
|
+
|
|
412
|
+
@staticmethod
|
|
413
|
+
def handle_moderate(args, unknown_args):
|
|
414
|
+
"""Handle moderate command."""
|
|
415
|
+
parser = argparse.ArgumentParser(prog="praisonai moderate")
|
|
416
|
+
parser.add_argument("text", nargs="+", help="Text to moderate")
|
|
417
|
+
parser.add_argument("--model", "-m", default="omni-moderation-latest", help="Model to use")
|
|
418
|
+
|
|
419
|
+
try:
|
|
420
|
+
parsed = parser.parse_args(unknown_args)
|
|
421
|
+
except SystemExit:
|
|
422
|
+
return 1
|
|
423
|
+
|
|
424
|
+
from praisonai.capabilities.moderations import moderate
|
|
425
|
+
|
|
426
|
+
try:
|
|
427
|
+
text_input = " ".join(parsed.text)
|
|
428
|
+
results = moderate(
|
|
429
|
+
input=text_input,
|
|
430
|
+
model=parsed.model,
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
for i, result in enumerate(results):
|
|
434
|
+
print(f"Result {i + 1}:")
|
|
435
|
+
print(f" Flagged: {result.flagged}")
|
|
436
|
+
if result.flagged:
|
|
437
|
+
flagged_categories = [k for k, v in result.categories.items() if v]
|
|
438
|
+
print(f" Categories: {', '.join(flagged_categories)}")
|
|
439
|
+
|
|
440
|
+
return 0
|
|
441
|
+
except Exception as e:
|
|
442
|
+
print(f"Error: {e}")
|
|
443
|
+
return 1
|
|
444
|
+
|
|
445
|
+
@staticmethod
|
|
446
|
+
def handle_ocr(args, unknown_args):
|
|
447
|
+
"""Handle ocr command."""
|
|
448
|
+
parser = argparse.ArgumentParser(prog="praisonai ocr")
|
|
449
|
+
parser.add_argument("document", help="Document or image to process")
|
|
450
|
+
parser.add_argument("--model", "-m", default="mistral/mistral-ocr-latest", help="Model to use")
|
|
451
|
+
parser.add_argument("--output", "-o", help="Output file path")
|
|
452
|
+
|
|
453
|
+
try:
|
|
454
|
+
parsed = parser.parse_args(unknown_args)
|
|
455
|
+
except SystemExit:
|
|
456
|
+
return 1
|
|
457
|
+
|
|
458
|
+
from praisonai.capabilities.ocr import ocr
|
|
459
|
+
|
|
460
|
+
try:
|
|
461
|
+
result = ocr(
|
|
462
|
+
document=parsed.document,
|
|
463
|
+
model=parsed.model,
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
if parsed.output:
|
|
467
|
+
with open(parsed.output, 'w') as f:
|
|
468
|
+
f.write(result.text)
|
|
469
|
+
print(f"OCR result saved to: {parsed.output}")
|
|
470
|
+
else:
|
|
471
|
+
print(result.text)
|
|
472
|
+
|
|
473
|
+
return 0
|
|
474
|
+
except Exception as e:
|
|
475
|
+
print(f"Error: {e}")
|
|
476
|
+
return 1
|
|
477
|
+
|
|
478
|
+
@staticmethod
|
|
479
|
+
def handle_batches(args, unknown_args):
|
|
480
|
+
"""Handle batches subcommands."""
|
|
481
|
+
if not unknown_args:
|
|
482
|
+
print("Usage: praisonai batches <create|list|get|cancel> [options]")
|
|
483
|
+
print("\nSubcommands:")
|
|
484
|
+
print(" create Create a batch job")
|
|
485
|
+
print(" list List batch jobs")
|
|
486
|
+
print(" get Get batch status")
|
|
487
|
+
print(" cancel Cancel a batch job")
|
|
488
|
+
return 1
|
|
489
|
+
|
|
490
|
+
subcommand = unknown_args[0]
|
|
491
|
+
remaining_args = unknown_args[1:]
|
|
492
|
+
|
|
493
|
+
if subcommand == "create":
|
|
494
|
+
return CapabilitiesHandler._handle_batches_create(args, remaining_args)
|
|
495
|
+
elif subcommand == "list":
|
|
496
|
+
return CapabilitiesHandler._handle_batches_list(args, remaining_args)
|
|
497
|
+
elif subcommand == "get":
|
|
498
|
+
return CapabilitiesHandler._handle_batches_get(args, remaining_args)
|
|
499
|
+
elif subcommand == "cancel":
|
|
500
|
+
return CapabilitiesHandler._handle_batches_cancel(args, remaining_args)
|
|
501
|
+
else:
|
|
502
|
+
print(f"Unknown batches subcommand: {subcommand}")
|
|
503
|
+
return 1
|
|
504
|
+
|
|
505
|
+
@staticmethod
|
|
506
|
+
def _handle_batches_create(args, remaining_args):
|
|
507
|
+
"""Handle: praisonai batches create <file_id>"""
|
|
508
|
+
parser = argparse.ArgumentParser(prog="praisonai batches create")
|
|
509
|
+
parser.add_argument("file_id", help="Input file ID")
|
|
510
|
+
parser.add_argument("--endpoint", "-e", default="/v1/chat/completions",
|
|
511
|
+
choices=["/v1/chat/completions", "/v1/embeddings"])
|
|
512
|
+
|
|
513
|
+
try:
|
|
514
|
+
parsed = parser.parse_args(remaining_args)
|
|
515
|
+
except SystemExit:
|
|
516
|
+
return 1
|
|
517
|
+
|
|
518
|
+
from praisonai.capabilities.batches import batch_create
|
|
519
|
+
|
|
520
|
+
try:
|
|
521
|
+
result = batch_create(
|
|
522
|
+
input_file_id=parsed.file_id,
|
|
523
|
+
endpoint=parsed.endpoint,
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
print(f"Batch created: {result.id}")
|
|
527
|
+
print(f" Status: {result.status}")
|
|
528
|
+
|
|
529
|
+
return 0
|
|
530
|
+
except Exception as e:
|
|
531
|
+
print(f"Error: {e}")
|
|
532
|
+
return 1
|
|
533
|
+
|
|
534
|
+
@staticmethod
|
|
535
|
+
def _handle_batches_list(args, remaining_args):
|
|
536
|
+
"""Handle: praisonai batches list"""
|
|
537
|
+
from praisonai.capabilities.batches import batch_list
|
|
538
|
+
|
|
539
|
+
try:
|
|
540
|
+
results = batch_list()
|
|
541
|
+
|
|
542
|
+
if not results:
|
|
543
|
+
print("No batches found.")
|
|
544
|
+
else:
|
|
545
|
+
for b in results:
|
|
546
|
+
print(f"{b.id}: {b.status} ({b.endpoint})")
|
|
547
|
+
|
|
548
|
+
return 0
|
|
549
|
+
except Exception as e:
|
|
550
|
+
print(f"Error: {e}")
|
|
551
|
+
return 1
|
|
552
|
+
|
|
553
|
+
@staticmethod
|
|
554
|
+
def _handle_batches_get(args, remaining_args):
|
|
555
|
+
"""Handle: praisonai batches get <batch_id>"""
|
|
556
|
+
parser = argparse.ArgumentParser(prog="praisonai batches get")
|
|
557
|
+
parser.add_argument("batch_id", help="Batch ID")
|
|
558
|
+
|
|
559
|
+
try:
|
|
560
|
+
parsed = parser.parse_args(remaining_args)
|
|
561
|
+
except SystemExit:
|
|
562
|
+
return 1
|
|
563
|
+
|
|
564
|
+
from praisonai.capabilities.batches import batch_retrieve
|
|
565
|
+
|
|
566
|
+
try:
|
|
567
|
+
result = batch_retrieve(batch_id=parsed.batch_id)
|
|
568
|
+
|
|
569
|
+
print(f"Batch: {result.id}")
|
|
570
|
+
print(f" Status: {result.status}")
|
|
571
|
+
print(f" Endpoint: {result.endpoint}")
|
|
572
|
+
if result.request_counts:
|
|
573
|
+
print(f" Completed: {result.request_counts.get('completed', 0)}/{result.request_counts.get('total', 0)}")
|
|
574
|
+
|
|
575
|
+
return 0
|
|
576
|
+
except Exception as e:
|
|
577
|
+
print(f"Error: {e}")
|
|
578
|
+
return 1
|
|
579
|
+
|
|
580
|
+
@staticmethod
|
|
581
|
+
def _handle_batches_cancel(args, remaining_args):
|
|
582
|
+
"""Handle: praisonai batches cancel <batch_id>"""
|
|
583
|
+
parser = argparse.ArgumentParser(prog="praisonai batches cancel")
|
|
584
|
+
parser.add_argument("batch_id", help="Batch ID")
|
|
585
|
+
|
|
586
|
+
try:
|
|
587
|
+
parsed = parser.parse_args(remaining_args)
|
|
588
|
+
except SystemExit:
|
|
589
|
+
return 1
|
|
590
|
+
|
|
591
|
+
from praisonai.capabilities.batches import batch_cancel
|
|
592
|
+
|
|
593
|
+
try:
|
|
594
|
+
result = batch_cancel(batch_id=parsed.batch_id)
|
|
595
|
+
|
|
596
|
+
print(f"Batch cancelled: {result.id}")
|
|
597
|
+
print(f" Status: {result.status}")
|
|
598
|
+
|
|
599
|
+
return 0
|
|
600
|
+
except Exception as e:
|
|
601
|
+
print(f"Error: {e}")
|
|
602
|
+
return 1
|
|
603
|
+
|
|
604
|
+
@staticmethod
|
|
605
|
+
def handle_vector_stores(args, unknown_args):
|
|
606
|
+
"""Handle vector-stores subcommands."""
|
|
607
|
+
if not unknown_args:
|
|
608
|
+
print("Usage: praisonai vector-stores <create|search> [options]")
|
|
609
|
+
print("\nSubcommands:")
|
|
610
|
+
print(" create Create a vector store")
|
|
611
|
+
print(" search Search a vector store")
|
|
612
|
+
return 1
|
|
613
|
+
|
|
614
|
+
subcommand = unknown_args[0]
|
|
615
|
+
remaining_args = unknown_args[1:]
|
|
616
|
+
|
|
617
|
+
if subcommand == "create":
|
|
618
|
+
return CapabilitiesHandler._handle_vector_stores_create(args, remaining_args)
|
|
619
|
+
elif subcommand == "search":
|
|
620
|
+
return CapabilitiesHandler._handle_vector_stores_search(args, remaining_args)
|
|
621
|
+
else:
|
|
622
|
+
print(f"Unknown vector-stores subcommand: {subcommand}")
|
|
623
|
+
return 1
|
|
624
|
+
|
|
625
|
+
@staticmethod
|
|
626
|
+
def _handle_vector_stores_create(args, remaining_args):
|
|
627
|
+
"""Handle: praisonai vector-stores create <name>"""
|
|
628
|
+
parser = argparse.ArgumentParser(prog="praisonai vector-stores create")
|
|
629
|
+
parser.add_argument("name", help="Vector store name")
|
|
630
|
+
parser.add_argument("--file-ids", "-f", nargs="+", help="File IDs to add")
|
|
631
|
+
|
|
632
|
+
try:
|
|
633
|
+
parsed = parser.parse_args(remaining_args)
|
|
634
|
+
except SystemExit:
|
|
635
|
+
return 1
|
|
636
|
+
|
|
637
|
+
from praisonai.capabilities.vector_stores import vector_store_create
|
|
638
|
+
|
|
639
|
+
try:
|
|
640
|
+
result = vector_store_create(
|
|
641
|
+
name=parsed.name,
|
|
642
|
+
file_ids=parsed.file_ids,
|
|
643
|
+
)
|
|
644
|
+
|
|
645
|
+
print(f"Vector store created: {result.id}")
|
|
646
|
+
print(f" Name: {result.name}")
|
|
647
|
+
print(f" Status: {result.status}")
|
|
648
|
+
|
|
649
|
+
return 0
|
|
650
|
+
except Exception as e:
|
|
651
|
+
print(f"Error: {e}")
|
|
652
|
+
return 1
|
|
653
|
+
|
|
654
|
+
@staticmethod
|
|
655
|
+
def _handle_vector_stores_search(args, remaining_args):
|
|
656
|
+
"""Handle: praisonai vector-stores search <store_id> <query>"""
|
|
657
|
+
parser = argparse.ArgumentParser(prog="praisonai vector-stores search")
|
|
658
|
+
parser.add_argument("store_id", help="Vector store ID")
|
|
659
|
+
parser.add_argument("query", help="Search query")
|
|
660
|
+
parser.add_argument("--max-results", "-n", type=int, default=10, help="Max results")
|
|
661
|
+
|
|
662
|
+
try:
|
|
663
|
+
parsed = parser.parse_args(remaining_args)
|
|
664
|
+
except SystemExit:
|
|
665
|
+
return 1
|
|
666
|
+
|
|
667
|
+
from praisonai.capabilities.vector_stores import vector_store_search
|
|
668
|
+
|
|
669
|
+
try:
|
|
670
|
+
result = vector_store_search(
|
|
671
|
+
vector_store_id=parsed.store_id,
|
|
672
|
+
query=parsed.query,
|
|
673
|
+
max_num_results=parsed.max_results,
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
print(f"Search results for: {result.query}")
|
|
677
|
+
for i, r in enumerate(result.results):
|
|
678
|
+
print(f" [{i + 1}] Score: {r.get('score', 0):.4f}")
|
|
679
|
+
if 'content' in r:
|
|
680
|
+
for c in r['content'][:1]: # Show first content
|
|
681
|
+
text = c.get('text', '')[:100]
|
|
682
|
+
print(f" {text}...")
|
|
683
|
+
|
|
684
|
+
return 0
|
|
685
|
+
except Exception as e:
|
|
686
|
+
print(f"Error: {e}")
|
|
687
|
+
return 1
|
|
688
|
+
|
|
689
|
+
@staticmethod
|
|
690
|
+
def handle_assistants(args, unknown_args):
|
|
691
|
+
"""Handle assistants subcommands."""
|
|
692
|
+
if not unknown_args:
|
|
693
|
+
print("Usage: praisonai assistants <create|list> [options]")
|
|
694
|
+
print("\nSubcommands:")
|
|
695
|
+
print(" create Create an assistant")
|
|
696
|
+
print(" list List assistants")
|
|
697
|
+
return 1
|
|
698
|
+
|
|
699
|
+
subcommand = unknown_args[0]
|
|
700
|
+
remaining_args = unknown_args[1:]
|
|
701
|
+
|
|
702
|
+
if subcommand == "create":
|
|
703
|
+
return CapabilitiesHandler._handle_assistants_create(args, remaining_args)
|
|
704
|
+
elif subcommand == "list":
|
|
705
|
+
return CapabilitiesHandler._handle_assistants_list(args, remaining_args)
|
|
706
|
+
else:
|
|
707
|
+
print(f"Unknown assistants subcommand: {subcommand}")
|
|
708
|
+
return 1
|
|
709
|
+
|
|
710
|
+
@staticmethod
|
|
711
|
+
def _handle_assistants_create(args, remaining_args):
|
|
712
|
+
"""Handle: praisonai assistants create [options]"""
|
|
713
|
+
parser = argparse.ArgumentParser(prog="praisonai assistants create")
|
|
714
|
+
parser.add_argument("--name", "-n", required=True, help="Assistant name")
|
|
715
|
+
parser.add_argument("--instructions", "-i", help="System instructions")
|
|
716
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model to use")
|
|
717
|
+
|
|
718
|
+
try:
|
|
719
|
+
parsed = parser.parse_args(remaining_args)
|
|
720
|
+
except SystemExit:
|
|
721
|
+
return 1
|
|
722
|
+
|
|
723
|
+
from praisonai.capabilities.assistants import assistant_create
|
|
724
|
+
|
|
725
|
+
try:
|
|
726
|
+
result = assistant_create(
|
|
727
|
+
name=parsed.name,
|
|
728
|
+
instructions=parsed.instructions,
|
|
729
|
+
model=parsed.model,
|
|
730
|
+
)
|
|
731
|
+
|
|
732
|
+
print(f"Assistant created: {result.id}")
|
|
733
|
+
print(f" Name: {result.name}")
|
|
734
|
+
print(f" Model: {result.model}")
|
|
735
|
+
|
|
736
|
+
return 0
|
|
737
|
+
except Exception as e:
|
|
738
|
+
print(f"Error: {e}")
|
|
739
|
+
return 1
|
|
740
|
+
|
|
741
|
+
@staticmethod
|
|
742
|
+
def _handle_assistants_list(args, remaining_args):
|
|
743
|
+
"""Handle: praisonai assistants list"""
|
|
744
|
+
from praisonai.capabilities.assistants import assistant_list
|
|
745
|
+
|
|
746
|
+
try:
|
|
747
|
+
results = assistant_list()
|
|
748
|
+
|
|
749
|
+
if not results:
|
|
750
|
+
print("No assistants found.")
|
|
751
|
+
else:
|
|
752
|
+
for a in results:
|
|
753
|
+
print(f"{a.id}: {a.name} ({a.model})")
|
|
754
|
+
|
|
755
|
+
return 0
|
|
756
|
+
except Exception as e:
|
|
757
|
+
print(f"Error: {e}")
|
|
758
|
+
return 1
|
|
759
|
+
|
|
760
|
+
@staticmethod
|
|
761
|
+
def handle_fine_tuning(args, unknown_args):
|
|
762
|
+
"""Handle fine-tuning subcommands."""
|
|
763
|
+
if not unknown_args:
|
|
764
|
+
print("Usage: praisonai fine-tuning <create|list> [options]")
|
|
765
|
+
print("\nSubcommands:")
|
|
766
|
+
print(" create Create a fine-tuning job")
|
|
767
|
+
print(" list List fine-tuning jobs")
|
|
768
|
+
return 1
|
|
769
|
+
|
|
770
|
+
subcommand = unknown_args[0]
|
|
771
|
+
remaining_args = unknown_args[1:]
|
|
772
|
+
|
|
773
|
+
if subcommand == "create":
|
|
774
|
+
return CapabilitiesHandler._handle_fine_tuning_create(args, remaining_args)
|
|
775
|
+
elif subcommand == "list":
|
|
776
|
+
return CapabilitiesHandler._handle_fine_tuning_list(args, remaining_args)
|
|
777
|
+
else:
|
|
778
|
+
print(f"Unknown fine-tuning subcommand: {subcommand}")
|
|
779
|
+
return 1
|
|
780
|
+
|
|
781
|
+
@staticmethod
|
|
782
|
+
def _handle_fine_tuning_create(args, remaining_args):
|
|
783
|
+
"""Handle: praisonai fine-tuning create <file_id>"""
|
|
784
|
+
parser = argparse.ArgumentParser(prog="praisonai fine-tuning create")
|
|
785
|
+
parser.add_argument("file_id", help="Training file ID")
|
|
786
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini-2024-07-18", help="Base model")
|
|
787
|
+
parser.add_argument("--suffix", "-s", help="Model name suffix")
|
|
788
|
+
|
|
789
|
+
try:
|
|
790
|
+
parsed = parser.parse_args(remaining_args)
|
|
791
|
+
except SystemExit:
|
|
792
|
+
return 1
|
|
793
|
+
|
|
794
|
+
from praisonai.capabilities.fine_tuning import fine_tuning_create
|
|
795
|
+
|
|
796
|
+
try:
|
|
797
|
+
result = fine_tuning_create(
|
|
798
|
+
training_file=parsed.file_id,
|
|
799
|
+
model=parsed.model,
|
|
800
|
+
suffix=parsed.suffix,
|
|
801
|
+
)
|
|
802
|
+
|
|
803
|
+
print(f"Fine-tuning job created: {result.id}")
|
|
804
|
+
print(f" Status: {result.status}")
|
|
805
|
+
print(f" Model: {result.model}")
|
|
806
|
+
|
|
807
|
+
return 0
|
|
808
|
+
except Exception as e:
|
|
809
|
+
print(f"Error: {e}")
|
|
810
|
+
return 1
|
|
811
|
+
|
|
812
|
+
@staticmethod
|
|
813
|
+
def _handle_fine_tuning_list(args, remaining_args):
|
|
814
|
+
"""Handle: praisonai fine-tuning list"""
|
|
815
|
+
from praisonai.capabilities.fine_tuning import fine_tuning_list
|
|
816
|
+
|
|
817
|
+
try:
|
|
818
|
+
results = fine_tuning_list()
|
|
819
|
+
|
|
820
|
+
if not results:
|
|
821
|
+
print("No fine-tuning jobs found.")
|
|
822
|
+
else:
|
|
823
|
+
for j in results:
|
|
824
|
+
print(f"{j.id}: {j.status} ({j.model})")
|
|
825
|
+
|
|
826
|
+
return 0
|
|
827
|
+
except Exception as e:
|
|
828
|
+
print(f"Error: {e}")
|
|
829
|
+
return 1
|
|
830
|
+
|
|
831
|
+
@staticmethod
|
|
832
|
+
def handle_completions(args, unknown_args):
|
|
833
|
+
"""Handle completions subcommands."""
|
|
834
|
+
parser = argparse.ArgumentParser(prog="praisonai completions")
|
|
835
|
+
parser.add_argument("prompt", nargs="?", help="Prompt text")
|
|
836
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model to use")
|
|
837
|
+
parser.add_argument("--max-tokens", type=int, help="Maximum tokens")
|
|
838
|
+
parser.add_argument("--temperature", "-t", type=float, default=1.0, help="Temperature")
|
|
839
|
+
parser.add_argument("--system", "-s", help="System prompt")
|
|
840
|
+
|
|
841
|
+
try:
|
|
842
|
+
parsed = parser.parse_args(unknown_args)
|
|
843
|
+
except SystemExit:
|
|
844
|
+
return 1
|
|
845
|
+
|
|
846
|
+
if not parsed.prompt:
|
|
847
|
+
print("Usage: praisonai completions <prompt> [options]")
|
|
848
|
+
return 1
|
|
849
|
+
|
|
850
|
+
from praisonai.capabilities.completions import chat_completion
|
|
851
|
+
|
|
852
|
+
try:
|
|
853
|
+
messages = []
|
|
854
|
+
if parsed.system:
|
|
855
|
+
messages.append({"role": "system", "content": parsed.system})
|
|
856
|
+
messages.append({"role": "user", "content": parsed.prompt})
|
|
857
|
+
|
|
858
|
+
result = chat_completion(
|
|
859
|
+
messages=messages,
|
|
860
|
+
model=parsed.model,
|
|
861
|
+
temperature=parsed.temperature,
|
|
862
|
+
max_tokens=parsed.max_tokens,
|
|
863
|
+
)
|
|
864
|
+
|
|
865
|
+
print(result.content)
|
|
866
|
+
return 0
|
|
867
|
+
except Exception as e:
|
|
868
|
+
print(f"Error: {e}")
|
|
869
|
+
return 1
|
|
870
|
+
|
|
871
|
+
@staticmethod
|
|
872
|
+
def handle_messages(args, unknown_args):
|
|
873
|
+
"""Handle messages subcommands."""
|
|
874
|
+
if not unknown_args:
|
|
875
|
+
print("Usage: praisonai messages <create|count-tokens> [options]")
|
|
876
|
+
return 1
|
|
877
|
+
|
|
878
|
+
subcommand = unknown_args[0]
|
|
879
|
+
remaining_args = unknown_args[1:]
|
|
880
|
+
|
|
881
|
+
if subcommand == "create":
|
|
882
|
+
return CapabilitiesHandler._handle_messages_create(args, remaining_args)
|
|
883
|
+
elif subcommand == "count-tokens":
|
|
884
|
+
return CapabilitiesHandler._handle_count_tokens(args, remaining_args)
|
|
885
|
+
else:
|
|
886
|
+
print(f"Unknown messages subcommand: {subcommand}")
|
|
887
|
+
return 1
|
|
888
|
+
|
|
889
|
+
@staticmethod
|
|
890
|
+
def _handle_messages_create(args, remaining_args):
|
|
891
|
+
"""Handle: praisonai messages create <prompt>"""
|
|
892
|
+
parser = argparse.ArgumentParser(prog="praisonai messages create")
|
|
893
|
+
parser.add_argument("prompt", help="Prompt text")
|
|
894
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model")
|
|
895
|
+
parser.add_argument("--max-tokens", type=int, default=1024, help="Max tokens")
|
|
896
|
+
parser.add_argument("--system", "-s", help="System prompt")
|
|
897
|
+
|
|
898
|
+
try:
|
|
899
|
+
parsed = parser.parse_args(remaining_args)
|
|
900
|
+
except SystemExit:
|
|
901
|
+
return 1
|
|
902
|
+
|
|
903
|
+
from praisonai.capabilities.messages import messages_create
|
|
904
|
+
|
|
905
|
+
try:
|
|
906
|
+
result = messages_create(
|
|
907
|
+
messages=[{"role": "user", "content": parsed.prompt}],
|
|
908
|
+
model=parsed.model,
|
|
909
|
+
max_tokens=parsed.max_tokens,
|
|
910
|
+
system=parsed.system,
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
if result.content:
|
|
914
|
+
for block in result.content:
|
|
915
|
+
if block.get("type") == "text":
|
|
916
|
+
print(block.get("text", ""))
|
|
917
|
+
|
|
918
|
+
return 0
|
|
919
|
+
except Exception as e:
|
|
920
|
+
print(f"Error: {e}")
|
|
921
|
+
return 1
|
|
922
|
+
|
|
923
|
+
@staticmethod
|
|
924
|
+
def _handle_count_tokens(args, remaining_args):
|
|
925
|
+
"""Handle: praisonai messages count-tokens <text>"""
|
|
926
|
+
parser = argparse.ArgumentParser(prog="praisonai messages count-tokens")
|
|
927
|
+
parser.add_argument("text", help="Text to count tokens for")
|
|
928
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model for tokenization")
|
|
929
|
+
|
|
930
|
+
try:
|
|
931
|
+
parsed = parser.parse_args(remaining_args)
|
|
932
|
+
except SystemExit:
|
|
933
|
+
return 1
|
|
934
|
+
|
|
935
|
+
from praisonai.capabilities.messages import count_tokens
|
|
936
|
+
|
|
937
|
+
try:
|
|
938
|
+
result = count_tokens(
|
|
939
|
+
messages=[{"role": "user", "content": parsed.text}],
|
|
940
|
+
model=parsed.model,
|
|
941
|
+
)
|
|
942
|
+
|
|
943
|
+
print(f"Token count: {result.input_tokens}")
|
|
944
|
+
return 0
|
|
945
|
+
except Exception as e:
|
|
946
|
+
print(f"Error: {e}")
|
|
947
|
+
return 1
|
|
948
|
+
|
|
949
|
+
@staticmethod
|
|
950
|
+
def handle_guardrails(args, unknown_args):
|
|
951
|
+
"""Handle guardrails subcommands."""
|
|
952
|
+
parser = argparse.ArgumentParser(prog="praisonai guardrails")
|
|
953
|
+
parser.add_argument("content", help="Content to check")
|
|
954
|
+
parser.add_argument("--rules", "-r", nargs="+", help="Rules to apply")
|
|
955
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model to use")
|
|
956
|
+
|
|
957
|
+
try:
|
|
958
|
+
parsed = parser.parse_args(unknown_args)
|
|
959
|
+
except SystemExit:
|
|
960
|
+
return 1
|
|
961
|
+
|
|
962
|
+
from praisonai.capabilities.guardrails import apply_guardrail
|
|
963
|
+
|
|
964
|
+
try:
|
|
965
|
+
result = apply_guardrail(
|
|
966
|
+
content=parsed.content,
|
|
967
|
+
rules=parsed.rules,
|
|
968
|
+
model=parsed.model,
|
|
969
|
+
)
|
|
970
|
+
|
|
971
|
+
if result.passed:
|
|
972
|
+
print("Content passed guardrail check")
|
|
973
|
+
else:
|
|
974
|
+
print("Content failed guardrail check")
|
|
975
|
+
if result.violations:
|
|
976
|
+
for v in result.violations:
|
|
977
|
+
print(f" - {v}")
|
|
978
|
+
|
|
979
|
+
return 0 if result.passed else 1
|
|
980
|
+
except Exception as e:
|
|
981
|
+
print(f"Error: {e}")
|
|
982
|
+
return 1
|
|
983
|
+
|
|
984
|
+
@staticmethod
|
|
985
|
+
def handle_rag(args, unknown_args):
|
|
986
|
+
"""Handle RAG subcommands."""
|
|
987
|
+
parser = argparse.ArgumentParser(prog="praisonai rag")
|
|
988
|
+
parser.add_argument("query", help="Query string")
|
|
989
|
+
parser.add_argument("--documents", "-d", nargs="+", help="Documents to search")
|
|
990
|
+
parser.add_argument("--vector-store", "-v", help="Vector store ID")
|
|
991
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model to use")
|
|
992
|
+
|
|
993
|
+
try:
|
|
994
|
+
parsed = parser.parse_args(unknown_args)
|
|
995
|
+
except SystemExit:
|
|
996
|
+
return 1
|
|
997
|
+
|
|
998
|
+
from praisonai.capabilities.rag import rag_query
|
|
999
|
+
|
|
1000
|
+
try:
|
|
1001
|
+
result = rag_query(
|
|
1002
|
+
query=parsed.query,
|
|
1003
|
+
documents=parsed.documents,
|
|
1004
|
+
vector_store_id=parsed.vector_store,
|
|
1005
|
+
model=parsed.model,
|
|
1006
|
+
)
|
|
1007
|
+
|
|
1008
|
+
print(result.answer)
|
|
1009
|
+
|
|
1010
|
+
if result.sources:
|
|
1011
|
+
print("\nSources:")
|
|
1012
|
+
for s in result.sources[:3]:
|
|
1013
|
+
print(f" - {s.get('text', '')[:100]}...")
|
|
1014
|
+
|
|
1015
|
+
return 0
|
|
1016
|
+
except Exception as e:
|
|
1017
|
+
print(f"Error: {e}")
|
|
1018
|
+
return 1
|
|
1019
|
+
|
|
1020
|
+
@staticmethod
|
|
1021
|
+
def handle_realtime(args, unknown_args):
|
|
1022
|
+
"""Handle realtime subcommands."""
|
|
1023
|
+
parser = argparse.ArgumentParser(prog="praisonai realtime")
|
|
1024
|
+
parser.add_argument("action", choices=["connect", "info"], help="Action")
|
|
1025
|
+
parser.add_argument("--model", "-m", default="gpt-4o-realtime-preview", help="Model")
|
|
1026
|
+
|
|
1027
|
+
try:
|
|
1028
|
+
parsed = parser.parse_args(unknown_args)
|
|
1029
|
+
except SystemExit:
|
|
1030
|
+
return 1
|
|
1031
|
+
|
|
1032
|
+
from praisonai.capabilities.realtime import realtime_connect
|
|
1033
|
+
|
|
1034
|
+
try:
|
|
1035
|
+
if parsed.action == "connect":
|
|
1036
|
+
session = realtime_connect(model=parsed.model)
|
|
1037
|
+
print(f"Session ID: {session.id}")
|
|
1038
|
+
print(f"URL: {session.url}")
|
|
1039
|
+
print(f"Status: {session.status}")
|
|
1040
|
+
else:
|
|
1041
|
+
print("Realtime API info:")
|
|
1042
|
+
print(" - Supports audio/text modalities")
|
|
1043
|
+
print(" - Use WebSocket connection for streaming")
|
|
1044
|
+
|
|
1045
|
+
return 0
|
|
1046
|
+
except Exception as e:
|
|
1047
|
+
print(f"Error: {e}")
|
|
1048
|
+
return 1
|
|
1049
|
+
|
|
1050
|
+
@staticmethod
|
|
1051
|
+
def handle_videos(args, unknown_args):
|
|
1052
|
+
"""Handle video generation."""
|
|
1053
|
+
parser = argparse.ArgumentParser(prog="praisonai videos")
|
|
1054
|
+
parser.add_argument("prompt", help="Video description")
|
|
1055
|
+
parser.add_argument("--model", "-m", default="sora", help="Model to use")
|
|
1056
|
+
parser.add_argument("--output", "-o", help="Output file path")
|
|
1057
|
+
|
|
1058
|
+
try:
|
|
1059
|
+
parsed = parser.parse_args(unknown_args)
|
|
1060
|
+
except SystemExit:
|
|
1061
|
+
return 1
|
|
1062
|
+
|
|
1063
|
+
from praisonai.capabilities.videos import video_generate
|
|
1064
|
+
|
|
1065
|
+
try:
|
|
1066
|
+
result = video_generate(
|
|
1067
|
+
prompt=parsed.prompt,
|
|
1068
|
+
model=parsed.model,
|
|
1069
|
+
)
|
|
1070
|
+
|
|
1071
|
+
print(f"Video ID: {result.id}")
|
|
1072
|
+
if result.url:
|
|
1073
|
+
print(f"URL: {result.url}")
|
|
1074
|
+
print(f"Status: {result.status}")
|
|
1075
|
+
|
|
1076
|
+
return 0
|
|
1077
|
+
except Exception as e:
|
|
1078
|
+
print(f"Error: {e}")
|
|
1079
|
+
return 1
|
|
1080
|
+
|
|
1081
|
+
@staticmethod
|
|
1082
|
+
def handle_a2a(args, unknown_args):
|
|
1083
|
+
"""Handle agent-to-agent communication."""
|
|
1084
|
+
parser = argparse.ArgumentParser(prog="praisonai a2a")
|
|
1085
|
+
parser.add_argument("message", help="Message to send")
|
|
1086
|
+
parser.add_argument("--target", "-t", required=True, help="Target agent name")
|
|
1087
|
+
|
|
1088
|
+
try:
|
|
1089
|
+
parsed = parser.parse_args(unknown_args)
|
|
1090
|
+
except SystemExit:
|
|
1091
|
+
return 1
|
|
1092
|
+
|
|
1093
|
+
from praisonai.capabilities.a2a import a2a_send
|
|
1094
|
+
|
|
1095
|
+
try:
|
|
1096
|
+
result = a2a_send(
|
|
1097
|
+
message=parsed.message,
|
|
1098
|
+
target_agent=parsed.target,
|
|
1099
|
+
)
|
|
1100
|
+
|
|
1101
|
+
print(f"Message ID: {result.id}")
|
|
1102
|
+
print(f"Status: {result.status}")
|
|
1103
|
+
if result.response:
|
|
1104
|
+
print(f"Response: {result.response}")
|
|
1105
|
+
|
|
1106
|
+
return 0
|
|
1107
|
+
except Exception as e:
|
|
1108
|
+
print(f"Error: {e}")
|
|
1109
|
+
return 1
|
|
1110
|
+
|
|
1111
|
+
@staticmethod
|
|
1112
|
+
def handle_containers(args, unknown_args):
|
|
1113
|
+
"""Handle container operations."""
|
|
1114
|
+
if not unknown_args:
|
|
1115
|
+
print("Usage: praisonai containers <create|files> [options]")
|
|
1116
|
+
return 1
|
|
1117
|
+
|
|
1118
|
+
subcommand = unknown_args[0]
|
|
1119
|
+
remaining_args = unknown_args[1:]
|
|
1120
|
+
|
|
1121
|
+
if subcommand == "create":
|
|
1122
|
+
return CapabilitiesHandler._handle_container_create(args, remaining_args)
|
|
1123
|
+
elif subcommand == "files":
|
|
1124
|
+
return CapabilitiesHandler._handle_container_files(args, remaining_args)
|
|
1125
|
+
else:
|
|
1126
|
+
print(f"Unknown containers subcommand: {subcommand}")
|
|
1127
|
+
return 1
|
|
1128
|
+
|
|
1129
|
+
@staticmethod
|
|
1130
|
+
def _handle_container_create(args, remaining_args):
|
|
1131
|
+
"""Handle: praisonai containers create"""
|
|
1132
|
+
parser = argparse.ArgumentParser(prog="praisonai containers create")
|
|
1133
|
+
parser.add_argument("--image", "-i", default="python:3.11", help="Container image")
|
|
1134
|
+
parser.add_argument("--name", "-n", help="Container name")
|
|
1135
|
+
|
|
1136
|
+
try:
|
|
1137
|
+
parsed = parser.parse_args(remaining_args)
|
|
1138
|
+
except SystemExit:
|
|
1139
|
+
return 1
|
|
1140
|
+
|
|
1141
|
+
from praisonai.capabilities.containers import container_create
|
|
1142
|
+
|
|
1143
|
+
try:
|
|
1144
|
+
result = container_create(
|
|
1145
|
+
image=parsed.image,
|
|
1146
|
+
name=parsed.name,
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
print(f"Container ID: {result.id}")
|
|
1150
|
+
print(f"Status: {result.status}")
|
|
1151
|
+
|
|
1152
|
+
return 0
|
|
1153
|
+
except Exception as e:
|
|
1154
|
+
print(f"Error: {e}")
|
|
1155
|
+
return 1
|
|
1156
|
+
|
|
1157
|
+
@staticmethod
|
|
1158
|
+
def _handle_container_files(args, remaining_args):
|
|
1159
|
+
"""Handle: praisonai containers files <action>"""
|
|
1160
|
+
if not remaining_args:
|
|
1161
|
+
print("Usage: praisonai containers files <read|write|list> [options]")
|
|
1162
|
+
return 1
|
|
1163
|
+
|
|
1164
|
+
action = remaining_args[0]
|
|
1165
|
+
action_args = remaining_args[1:]
|
|
1166
|
+
|
|
1167
|
+
if action == "read":
|
|
1168
|
+
parser = argparse.ArgumentParser(prog="praisonai containers files read")
|
|
1169
|
+
parser.add_argument("container_id", help="Container ID")
|
|
1170
|
+
parser.add_argument("path", help="File path")
|
|
1171
|
+
|
|
1172
|
+
try:
|
|
1173
|
+
parsed = parser.parse_args(action_args)
|
|
1174
|
+
except SystemExit:
|
|
1175
|
+
return 1
|
|
1176
|
+
|
|
1177
|
+
from praisonai.capabilities.container_files import container_file_read
|
|
1178
|
+
|
|
1179
|
+
try:
|
|
1180
|
+
result = container_file_read(
|
|
1181
|
+
container_id=parsed.container_id,
|
|
1182
|
+
path=parsed.path,
|
|
1183
|
+
)
|
|
1184
|
+
|
|
1185
|
+
if result.content:
|
|
1186
|
+
print(result.content)
|
|
1187
|
+
else:
|
|
1188
|
+
print("(empty or not available)")
|
|
1189
|
+
|
|
1190
|
+
return 0
|
|
1191
|
+
except Exception as e:
|
|
1192
|
+
print(f"Error: {e}")
|
|
1193
|
+
return 1
|
|
1194
|
+
|
|
1195
|
+
elif action == "list":
|
|
1196
|
+
parser = argparse.ArgumentParser(prog="praisonai containers files list")
|
|
1197
|
+
parser.add_argument("container_id", help="Container ID")
|
|
1198
|
+
parser.add_argument("--path", "-p", default="/", help="Directory path")
|
|
1199
|
+
|
|
1200
|
+
try:
|
|
1201
|
+
parsed = parser.parse_args(action_args)
|
|
1202
|
+
except SystemExit:
|
|
1203
|
+
return 1
|
|
1204
|
+
|
|
1205
|
+
from praisonai.capabilities.container_files import container_file_list
|
|
1206
|
+
|
|
1207
|
+
try:
|
|
1208
|
+
results = container_file_list(
|
|
1209
|
+
container_id=parsed.container_id,
|
|
1210
|
+
path=parsed.path,
|
|
1211
|
+
)
|
|
1212
|
+
|
|
1213
|
+
if not results:
|
|
1214
|
+
print("No files found.")
|
|
1215
|
+
else:
|
|
1216
|
+
for f in results:
|
|
1217
|
+
print(f.path)
|
|
1218
|
+
|
|
1219
|
+
return 0
|
|
1220
|
+
except Exception as e:
|
|
1221
|
+
print(f"Error: {e}")
|
|
1222
|
+
return 1
|
|
1223
|
+
|
|
1224
|
+
else:
|
|
1225
|
+
print(f"Unknown action: {action}")
|
|
1226
|
+
return 1
|
|
1227
|
+
|
|
1228
|
+
@staticmethod
|
|
1229
|
+
def handle_passthrough(args, unknown_args):
|
|
1230
|
+
"""Handle passthrough API calls."""
|
|
1231
|
+
parser = argparse.ArgumentParser(prog="praisonai passthrough")
|
|
1232
|
+
parser.add_argument("provider", help="Provider name")
|
|
1233
|
+
parser.add_argument("endpoint", help="API endpoint")
|
|
1234
|
+
parser.add_argument("--method", "-X", default="POST", help="HTTP method")
|
|
1235
|
+
parser.add_argument("--data", "-d", help="JSON data")
|
|
1236
|
+
|
|
1237
|
+
try:
|
|
1238
|
+
parsed = parser.parse_args(unknown_args)
|
|
1239
|
+
except SystemExit:
|
|
1240
|
+
return 1
|
|
1241
|
+
|
|
1242
|
+
from praisonai.capabilities.passthrough import passthrough
|
|
1243
|
+
import json
|
|
1244
|
+
|
|
1245
|
+
try:
|
|
1246
|
+
data = json.loads(parsed.data) if parsed.data else None
|
|
1247
|
+
|
|
1248
|
+
result = passthrough(
|
|
1249
|
+
provider=parsed.provider,
|
|
1250
|
+
endpoint=parsed.endpoint,
|
|
1251
|
+
method=parsed.method,
|
|
1252
|
+
data=data,
|
|
1253
|
+
)
|
|
1254
|
+
|
|
1255
|
+
print(f"Status: {result.status_code}")
|
|
1256
|
+
if result.data:
|
|
1257
|
+
print(json.dumps(result.data, indent=2))
|
|
1258
|
+
|
|
1259
|
+
return 0
|
|
1260
|
+
except Exception as e:
|
|
1261
|
+
print(f"Error: {e}")
|
|
1262
|
+
return 1
|
|
1263
|
+
|
|
1264
|
+
@staticmethod
|
|
1265
|
+
def handle_responses(args, unknown_args):
|
|
1266
|
+
"""Handle responses API."""
|
|
1267
|
+
parser = argparse.ArgumentParser(prog="praisonai responses")
|
|
1268
|
+
parser.add_argument("input", help="Input text")
|
|
1269
|
+
parser.add_argument("--model", "-m", default="gpt-4o-mini", help="Model")
|
|
1270
|
+
parser.add_argument("--instructions", "-i", help="Instructions")
|
|
1271
|
+
|
|
1272
|
+
try:
|
|
1273
|
+
parsed = parser.parse_args(unknown_args)
|
|
1274
|
+
except SystemExit:
|
|
1275
|
+
return 1
|
|
1276
|
+
|
|
1277
|
+
from praisonai.capabilities.responses import responses_create
|
|
1278
|
+
|
|
1279
|
+
try:
|
|
1280
|
+
result = responses_create(
|
|
1281
|
+
input=parsed.input,
|
|
1282
|
+
model=parsed.model,
|
|
1283
|
+
instructions=parsed.instructions,
|
|
1284
|
+
)
|
|
1285
|
+
|
|
1286
|
+
print(result.output or "(no output)")
|
|
1287
|
+
|
|
1288
|
+
return 0
|
|
1289
|
+
except Exception as e:
|
|
1290
|
+
print(f"Error: {e}")
|
|
1291
|
+
return 1
|
|
1292
|
+
|
|
1293
|
+
@staticmethod
|
|
1294
|
+
def handle_search(args, unknown_args):
|
|
1295
|
+
"""Handle search operations."""
|
|
1296
|
+
parser = argparse.ArgumentParser(prog="praisonai search")
|
|
1297
|
+
parser.add_argument("query", help="Search query")
|
|
1298
|
+
parser.add_argument("--max-results", "-n", type=int, default=5, help="Max results")
|
|
1299
|
+
|
|
1300
|
+
try:
|
|
1301
|
+
parsed = parser.parse_args(unknown_args)
|
|
1302
|
+
except SystemExit:
|
|
1303
|
+
return 1
|
|
1304
|
+
|
|
1305
|
+
from praisonai.capabilities.search import search
|
|
1306
|
+
|
|
1307
|
+
try:
|
|
1308
|
+
result = search(
|
|
1309
|
+
query=parsed.query,
|
|
1310
|
+
max_results=parsed.max_results,
|
|
1311
|
+
)
|
|
1312
|
+
|
|
1313
|
+
if not result.results:
|
|
1314
|
+
print("No results found.")
|
|
1315
|
+
else:
|
|
1316
|
+
for r in result.results:
|
|
1317
|
+
title = r.get("title", "Untitled")
|
|
1318
|
+
url = r.get("url", "")
|
|
1319
|
+
print(f"- {title}")
|
|
1320
|
+
if url:
|
|
1321
|
+
print(f" {url}")
|
|
1322
|
+
|
|
1323
|
+
return 0
|
|
1324
|
+
except Exception as e:
|
|
1325
|
+
print(f"Error: {e}")
|
|
1326
|
+
return 1
|