Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andreich1980's avatar

andreich1980 wrote a comment+100 XP

4d ago

The Batteries-Included AI Toolkit : Ep 12, Testing AI Features Without Hitting the API

I just tested it in the Tinker

\App\Ai\DirectAnswerAgent::fake([
    ['response...']
]);

$response = \App\Ai\DirectAnswerAgent::make()->prompt('hi there');
$responseB = \App\Ai\DirectAnswerAgent::make()->prompt('hi there 2');

dump([
    (string) $response,
    (string) $responseB,
]);

And the result is:

[
    "[\"response...\"]",
    "Fake response for prompt: hi there 2",
  ]

It does not hit the API, it returns a generic fake response (because I haven't provided my custom fake response). But it does not hit the API, because fake() was called.

But once I remove the fake() completely - it does hit real API.

andreich1980's avatar

andreich1980 wrote a comment+100 XP

4d ago

The Batteries-Included AI Toolkit : Ep 12, Testing AI Features Without Hitting the API

Based on the Laravel AI SDK docs preventStrayPrompts does not protect from requests "bypassing the fake" (do you mean "they hit the real API"?), but it could tell you if there were some extra calls for the agent that you haven't faked, e.g. you test your API endpoint and expect the AI agent is called only once, and you provide exactly one fake response, and without preventStrayPrompts you won't know if the AI agent was called more than once during the API request. With this method - you'd know that there was other requests, but you haven't provided the fake response for them.

Or did I understood it wrong and it does protect against real API hits?

andreich1980's avatar

andreich1980 wrote a comment+100 XP

4d ago

The Batteries-Included AI Toolkit : Ep 12, Testing AI Features Without Hitting the API

Hi Jeremy.

Thanks for the course.

I'm wondering what is the purpose of a test that

  1. calls TicketTriager::make()->prompt()
  2. right after that calls assertPrompted() (to make sure the prompt() method was called 1 line above?)

What is the value of such a test? What are you actually testing here? That you didn't forget to prompt the agent one line above the assertion? Am I missing something here?

The same with Embeddings test. It looks like you're testing Laravel AI SDK package, not your actual code.

andreich1980's avatar

andreich1980 liked a comment+100 XP

2mos ago

The Laravel Workshop: Ep 24, Building the Post Model

If post and repliks are both posts i would not delete on cascade if a user is deleted. I want to keep replies from deleted users too as it could make the replies section to look Strange if multiple replies are missing in the chronological order. So i would separate the models.

andreich1980's avatar

andreich1980 liked a comment+100 XP

5mos ago

Build a Livewire App With Me!: Ep 19, Real-time Chat with Laravel Reverb

@andreich1980

I could only get comma dot working like this, PhpStorm Junie actually suggested just dot, but that failed

#[On('echo-private:App.Models.User.{user.id},.message.created')]