From 5f210c6c73379383b9220337546a9b35b9461458 Mon Sep 17 00:00:00 2001 From: Meghdad Date: Sun, 10 May 2026 11:08:07 +0330 Subject: [PATCH] init ai sdk --- config/ai.php | 143 ++++++++++++++++++ ...73636_create_agent_conversations_table.php | 50 ++++++ stubs/agent-middleware.stub | 20 +++ stubs/agent.stub | 44 ++++++ stubs/structured-agent.stub | 56 +++++++ stubs/tool.stub | 37 +++++ 6 files changed, 350 insertions(+) create mode 100644 config/ai.php create mode 100644 database/migrations/2026_05_10_073636_create_agent_conversations_table.php create mode 100644 stubs/agent-middleware.stub create mode 100644 stubs/agent.stub create mode 100644 stubs/structured-agent.stub create mode 100644 stubs/tool.stub diff --git a/config/ai.php b/config/ai.php new file mode 100644 index 0000000..f722b28 --- /dev/null +++ b/config/ai.php @@ -0,0 +1,143 @@ + 'openai', + 'default_for_images' => 'gemini', + 'default_for_audio' => 'openai', + 'default_for_transcription' => 'openai', + 'default_for_embeddings' => 'openai', + 'default_for_reranking' => 'cohere', + + /* + |-------------------------------------------------------------------------- + | Caching + |-------------------------------------------------------------------------- + | + | Below you may configure caching strategies for AI related operations + | such as embedding generation. You are free to adjust these values + | based on your application's available caching stores and needs. + | + */ + + 'caching' => [ + 'embeddings' => [ + 'cache' => false, + 'store' => env('CACHE_STORE', 'database'), + ], + ], + + /* + |-------------------------------------------------------------------------- + | AI Providers + |-------------------------------------------------------------------------- + | + | Below are each of your AI providers defined for this application. Each + | represents an AI provider and API key combination which can be used + | to perform tasks like text, image, and audio creation via agents. + | + */ + + 'providers' => [ + 'anthropic' => [ + 'driver' => 'anthropic', + 'key' => env('ANTHROPIC_API_KEY'), + 'url' => env('ANTHROPIC_URL', 'https://api.anthropic.com/v1'), + ], + + 'azure' => [ + 'driver' => 'azure', + 'key' => env('AZURE_OPENAI_API_KEY'), + 'url' => env('AZURE_OPENAI_URL'), + 'api_version' => env('AZURE_OPENAI_API_VERSION', '2025-04-01-preview'), + 'deployment' => env('AZURE_OPENAI_DEPLOYMENT', 'gpt-4o'), + 'embedding_deployment' => env('AZURE_OPENAI_EMBEDDING_DEPLOYMENT', 'text-embedding-3-small'), + 'image_deployment' => env('AZURE_OPENAI_IMAGE_DEPLOYMENT', 'gpt-image-1'), + ], + + 'bedrock' => [ + 'driver' => 'bedrock', + 'region' => env('AWS_BEDROCK_REGION', 'us-east-1'), + 'key' => env('AWS_BEARER_TOKEN_BEDROCK'), + 'access_key_id' => env('AWS_ACCESS_KEY_ID'), + 'secret_access_key' => env('AWS_SECRET_ACCESS_KEY'), + 'session_token' => env('AWS_SESSION_TOKEN'), + 'use_default_credential_provider' => env('AWS_USE_DEFAULT_CREDENTIALS', true), + ], + + 'cohere' => [ + 'driver' => 'cohere', + 'key' => env('COHERE_API_KEY'), + ], + + 'deepseek' => [ + 'driver' => 'deepseek', + 'key' => env('DEEPSEEK_API_KEY'), + ], + + 'eleven' => [ + 'driver' => 'eleven', + 'key' => env('ELEVENLABS_API_KEY'), + ], + + 'gemini' => [ + 'driver' => 'gemini', + 'key' => env('GEMINI_API_KEY'), + 'url' => env('GEMINI_URL', 'https://generativelanguage.googleapis.com/v1beta/'), + ], + + 'groq' => [ + 'driver' => 'groq', + 'key' => env('GROQ_API_KEY'), + ], + + 'jina' => [ + 'driver' => 'jina', + 'key' => env('JINA_API_KEY'), + ], + + 'mistral' => [ + 'driver' => 'mistral', + 'key' => env('MISTRAL_API_KEY'), + ], + + 'ollama' => [ + 'driver' => 'ollama', + 'key' => env('OLLAMA_API_KEY', ''), + 'url' => env('OLLAMA_URL', 'http://localhost:11434'), + ], + + 'openai' => [ + 'driver' => 'openai', + 'key' => env('OPENAI_API_KEY'), + 'url' => env('OPENAI_URL', 'https://api.openai.com/v1'), + ], + + 'openrouter' => [ + 'driver' => 'openrouter', + 'key' => env('OPENROUTER_API_KEY'), + ], + + 'voyageai' => [ + 'driver' => 'voyageai', + 'key' => env('VOYAGEAI_API_KEY'), + ], + + 'xai' => [ + 'driver' => 'xai', + 'key' => env('XAI_API_KEY'), + ], + ], + +]; diff --git a/database/migrations/2026_05_10_073636_create_agent_conversations_table.php b/database/migrations/2026_05_10_073636_create_agent_conversations_table.php new file mode 100644 index 0000000..e1f2d63 --- /dev/null +++ b/database/migrations/2026_05_10_073636_create_agent_conversations_table.php @@ -0,0 +1,50 @@ +string('id', 36)->primary(); + $table->foreignId('user_id')->nullable(); + $table->string('title'); + $table->timestamps(); + + $table->index(['user_id', 'updated_at']); + }); + + Schema::create('agent_conversation_messages', function (Blueprint $table) { + $table->string('id', 36)->primary(); + $table->string('conversation_id', 36)->index(); + $table->foreignId('user_id')->nullable(); + $table->string('agent'); + $table->string('role', 25); + $table->text('content'); + $table->text('attachments'); + $table->text('tool_calls'); + $table->text('tool_results'); + $table->text('usage'); + $table->text('meta'); + $table->timestamps(); + + $table->index(['conversation_id', 'user_id', 'updated_at'], 'conversation_index'); + $table->index(['user_id']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('agent_conversations'); + Schema::dropIfExists('agent_conversation_messages'); + } +}; diff --git a/stubs/agent-middleware.stub b/stubs/agent-middleware.stub new file mode 100644 index 0000000..c1a50f4 --- /dev/null +++ b/stubs/agent-middleware.stub @@ -0,0 +1,20 @@ +then(function (AgentResponse $response) { + // ... + }); + } +} diff --git a/stubs/agent.stub b/stubs/agent.stub new file mode 100644 index 0000000..06471d5 --- /dev/null +++ b/stubs/agent.stub @@ -0,0 +1,44 @@ + $schema->string()->required(), + ]; + } +} diff --git a/stubs/tool.stub b/stubs/tool.stub new file mode 100644 index 0000000..e096021 --- /dev/null +++ b/stubs/tool.stub @@ -0,0 +1,37 @@ + $schema->string()->required(), + ]; + } +}