mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Introduce the AI provider layer: laravel/ai SDK integration, AiService and AiExtractionService, the AiProvider enum (OpenAI, Gemini, Ollama) and supporting DTOs/agents. - Encrypt stored API keys; per-provider test-connection action - Ollama model dropdown with reachability-based connection test - Multi-provider settings UI with per-row test and auto-migration of the legacy single-provider shape into the multi-provider structure - Resolve active config through AiProviderConfigDto
38 lines
887 B
PHP
38 lines
887 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class OllamaService
|
|
{
|
|
public const int DEFAULT_TIMEOUT = 10;
|
|
|
|
public static function new(): self
|
|
{
|
|
return resolve(static::class);
|
|
}
|
|
|
|
/**
|
|
* Fetch the list of model names available on an Ollama server via /api/tags.
|
|
*
|
|
* @return array<int, string>
|
|
*
|
|
* @throws \Illuminate\Http\Client\ConnectionException
|
|
* @throws \Illuminate\Http\Client\RequestException
|
|
*/
|
|
public function listModels(string $baseUrl, int $timeout = self::DEFAULT_TIMEOUT): array
|
|
{
|
|
$response = Http::baseUrl(rtrim($baseUrl, '/'))
|
|
->timeout($timeout)
|
|
->throw()
|
|
->get('/api/tags');
|
|
|
|
return collect($response->json('models', []))
|
|
->pluck('name')
|
|
->filter()
|
|
->values()
|
|
->all();
|
|
}
|
|
}
|