papi-ai/symfony 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

papi-ai/symfony

最新稳定版本:v0.9.1

Composer 安装命令:

composer require papi-ai/symfony

包简介

Symfony bridge for PapiAI - Integrate AI agents into your Symfony application

README 文档

README

CI Latest Version Total Downloads PHP Version License

Symfony bridge for PapiAI -- integrate AI agents into your Symfony application with full dependency injection, configuration, and service wiring.

Installation

composer require papi-ai/symfony

Bundle Registration

If you are not using Symfony Flex, register the bundle manually in config/bundles.php:

return [
    // ...
    PapiAI\Symfony\PapiBundle::class => ['all' => true],
];

Configuration

Create config/packages/papi.yaml:

papi:
    default_provider: openai

    providers:
        openai:
            driver: PapiAI\OpenAI\OpenAIProvider
            api_key: '%env(OPENAI_API_KEY)%'
            model: gpt-4o

        anthropic:
            driver: PapiAI\Anthropic\AnthropicProvider
            api_key: '%env(ANTHROPIC_API_KEY)%'
            model: claude-sonnet-4-20250514

    middleware:
        - app.middleware.logging
        - app.middleware.rate_limit

    conversation:
        store: file
        path: '%kernel.project_dir%/var/papi/conversations'

Usage

Injecting a Provider

use PapiAI\Core\Contracts\ProviderInterface;

class ChatController
{
    public function __construct(
        private ProviderInterface $provider,
    ) {}

    public function chat(string $message): string
    {
        $response = $this->provider->chat([
            ['role' => 'user', 'content' => $message],
        ]);

        return $response->getText();
    }
}

Using Conversation Storage

use PapiAI\Core\Contracts\ConversationStoreInterface;
use PapiAI\Core\Conversation;

class ConversationService
{
    public function __construct(
        private ConversationStoreInterface $store,
    ) {}

    public function saveConversation(string $id, Conversation $conversation): void
    {
        $this->store->save($id, $conversation);
    }

    public function loadConversation(string $id): ?Conversation
    {
        return $this->store->load($id);
    }
}

Using Doctrine Conversation Store

Install Doctrine DBAL and configure the store:

composer require doctrine/dbal
papi:
    conversation:
        store: doctrine

Create the conversations table in your database:

CREATE TABLE papi_conversations (
    id VARCHAR(255) PRIMARY KEY,
    data JSON NOT NULL,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL
);

Using Messenger Queue

Install Symfony Messenger:

composer require symfony/messenger
use PapiAI\Core\Contracts\QueueInterface;
use PapiAI\Core\AgentJob;

class AgentService
{
    public function __construct(
        private QueueInterface $queue,
    ) {}

    public function dispatchJob(string $agentClass, string $prompt): string
    {
        $job = new AgentJob(
            agentClass: $agentClass,
            prompt: $prompt,
        );

        return $this->queue->dispatch($job);
    }
}

License

MIT License. See LICENSE for details.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固