All skills
asyrafhussin avatar

/laravel-ai-sdk

@7221662

Laravel AI SDK for building AI-powered features. Use when creating agents, generating images or audio, working with embeddings, vector search, or testing AI features. Triggers on tasks involving laravel/ai, AI agents, tool-calling, structured output, streaming, embeddings, reranking, or AI faking in tests.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/laravel-ai-sdk

This session only. Nothing lands on disk.

rulestest-data.md

≈905 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing Embeddings, Reranking, Files, and Vector Stores

Impact: HIGH (Fake data operations in tests)

Fake embeddings, reranking, file storage, and vector store operations to avoid real API calls and provider dependencies in tests.

Bad Example

// Real embedding generation in tests — slow, costs money, needs API key
test('stores document with embedding', function () {
    $embedding = Str::of($content)->toEmbeddings(); // Real API call
    Document::create(['content' => $content, 'embedding' => $embedding]);
});

Good Example

use Laravel\Ai\Embeddings;
use Laravel\Ai\Prompts\EmbeddingsPrompt;

// Fake embeddings — auto-generates vectors of proper dimensions
test('generates document embeddings', function () {
    Embeddings::fake();

    $response = Embeddings::for(['Laravel is great.'])->generate();

    Embeddings::assertGenerated(function (EmbeddingsPrompt $prompt) {
        return $prompt->contains('Laravel');
    });
});
// Fake with specific vectors
test('generates specific embeddings', function () {
    Embeddings::fake([
        [$firstEmbeddingVector],
        [$secondEmbeddingVector],
    ]);

    $response = Embeddings::for(['Input text.'])->generate();
});
// Prevent stray embedding calls
test('no unexpected embeddings', function () {
    Embeddings::fake()->preventStrayEmbeddings();
});
use Laravel\Ai\Reranking;
use Laravel\Ai\Prompts\RerankingPrompt;
use Laravel\Ai\Responses\Data\RankedDocument;

// Fake reranking
test('reranks search results', function () {
    Reranking::fake();

    $response = Reranking::of(['Doc A', 'Doc B'])->rerank('query');

    Reranking::assertReranked(function (RerankingPrompt $prompt) {
        return $prompt->contains('query');
    });
});

// Fake with specific ranked results
test('returns expected ranking', function () {
    Reranking::fake([
        [
            new RankedDocument(index: 0, document: 'First', score: 0.95),
            new RankedDocument(index: 1, document: 'Second', score: 0.80),
        ],
    ]);
});
use Laravel\Ai\Files;
use Laravel\Ai\Contracts\Files\StorableFile;
use Laravel\Ai\Files\Document;

// Fake file operations
test('stores document with provider', function () {
    Files::fake();

    Document::fromString('Hello, Laravel!', mimeType: 'text/plain')
        ->as('hello.txt')
        ->put();

    Files::assertStored(fn (StorableFile $file) =>
        (string) $file === 'Hello, Laravel!' &&
        $file->mimeType() === 'text/plain'
    );

    Files::assertNothingDeleted();
});
use Laravel\Ai\Stores;

// Fake vector store operations (also fakes file operations)
test('creates knowledge base store', function () {
    Stores::fake();

    $store = Stores::create('Knowledge Base');

    Stores::assertCreated('Knowledge Base');

    // Assert files added to store
    $store->add(Document::fromString('Content', 'text/plain')->as('doc.txt'));
    $store->assertAdded(fn (StorableFile $file) => $file->name() === 'doc.txt');
});

Why

  • Fast: No embedding API calls or provider connections
  • Deterministic: Controlled fake vectors and rankings
  • Comprehensive: Fake files, stores, and all data operations in one test
  • Assertable: Verify what was generated, stored, added, and removed

Reference: Laravel AI SDK — Testing

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive guide for the Laravel AI SDK but contains deceptive metadata claiming authorship by the 'Laravel Community' despite being associated with the user 'asyrafhussin'. It also presents an indirect prompt injection surface by documenting patterns for ingesting untrusted data (such as transcripts and external URLs) while granting agents capabilities like file system storage and network access.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7221662. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "Laravel Community",
  "version": "1.0.0",
  "laravelVersion": "13.x",
  "phpVersion": "8.3+"
}

README badge

README badge for asyrafhussin/agent-skills/laravel-ai-sdk