init ai sdk
This commit is contained in:
143
config/ai.php
Normal file
143
config/ai.php
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default AI Provider Names
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which of the AI providers below should be the
|
||||||
|
| default for AI operations when no explicit provider is provided
|
||||||
|
| for the operation. This should be any provider defined below.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => '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'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Laravel\Ai\Migrations\AiMigration;
|
||||||
|
|
||||||
|
return new class extends AiMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('agent_conversations', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
||||||
20
stubs/agent-middleware.stub
Normal file
20
stubs/agent-middleware.stub
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{ namespace }};
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Laravel\Ai\Prompts\AgentPrompt;
|
||||||
|
use Laravel\Ai\Responses\AgentResponse;
|
||||||
|
|
||||||
|
class {{ class }}
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the incoming prompt.
|
||||||
|
*/
|
||||||
|
public function handle(AgentPrompt $prompt, Closure $next)
|
||||||
|
{
|
||||||
|
return $next($prompt)->then(function (AgentResponse $response) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
44
stubs/agent.stub
Normal file
44
stubs/agent.stub
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{ namespace }};
|
||||||
|
|
||||||
|
use Laravel\Ai\Contracts\Agent;
|
||||||
|
use Laravel\Ai\Contracts\Conversational;
|
||||||
|
use Laravel\Ai\Contracts\HasTools;
|
||||||
|
use Laravel\Ai\Contracts\Tool;
|
||||||
|
use Laravel\Ai\Messages\Message;
|
||||||
|
use Laravel\Ai\Promptable;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
|
class {{ class }} implements Agent, Conversational, HasTools
|
||||||
|
{
|
||||||
|
use Promptable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the instructions that the agent should follow.
|
||||||
|
*/
|
||||||
|
public function instructions(): Stringable|string
|
||||||
|
{
|
||||||
|
return 'You are a helpful assistant.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of messages comprising the conversation so far.
|
||||||
|
*
|
||||||
|
* @return Message[]
|
||||||
|
*/
|
||||||
|
public function messages(): iterable
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tools available to the agent.
|
||||||
|
*
|
||||||
|
* @return Tool[]
|
||||||
|
*/
|
||||||
|
public function tools(): iterable
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
56
stubs/structured-agent.stub
Normal file
56
stubs/structured-agent.stub
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{ namespace }};
|
||||||
|
|
||||||
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||||
|
use Laravel\Ai\Contracts\Agent;
|
||||||
|
use Laravel\Ai\Contracts\Conversational;
|
||||||
|
use Laravel\Ai\Contracts\HasStructuredOutput;
|
||||||
|
use Laravel\Ai\Contracts\HasTools;
|
||||||
|
use Laravel\Ai\Contracts\Tool;
|
||||||
|
use Laravel\Ai\Messages\Message;
|
||||||
|
use Laravel\Ai\Promptable;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
|
class {{ class }} implements Agent, Conversational, HasStructuredOutput, HasTools
|
||||||
|
{
|
||||||
|
use Promptable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the instructions that the agent should follow.
|
||||||
|
*/
|
||||||
|
public function instructions(): Stringable|string
|
||||||
|
{
|
||||||
|
return 'You are a helpful assistant.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of messages comprising the conversation so far.
|
||||||
|
*
|
||||||
|
* @return Message[]
|
||||||
|
*/
|
||||||
|
public function messages(): iterable
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tools available to the agent.
|
||||||
|
*
|
||||||
|
* @return Tool[]
|
||||||
|
*/
|
||||||
|
public function tools(): iterable
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the agent's structured output schema definition.
|
||||||
|
*/
|
||||||
|
public function schema(JsonSchema $schema): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'value' => $schema->string()->required(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
37
stubs/tool.stub
Normal file
37
stubs/tool.stub
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{ namespace }};
|
||||||
|
|
||||||
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||||
|
use Laravel\Ai\Contracts\Tool;
|
||||||
|
use Laravel\Ai\Tools\Request;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
|
class {{ class }} implements Tool
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the description of the tool's purpose.
|
||||||
|
*/
|
||||||
|
public function description(): Stringable|string
|
||||||
|
{
|
||||||
|
return 'A description of the tool.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the tool.
|
||||||
|
*/
|
||||||
|
public function handle(Request $request): Stringable|string
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tool's schema definition.
|
||||||
|
*/
|
||||||
|
public function schema(JsonSchema $schema): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'value' => $schema->string()->required(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user