Merge branch 'ai_provider'

This commit is contained in:
Jan Böhmer 2026-05-03 00:38:17 +02:00
commit 801e23e63b
63 changed files with 5210 additions and 1717 deletions

8
.env
View file

@ -155,3 +155,11 @@ APP_ENV=prod
APP_SECRET=a03498528f5a5fc089273ec9ae5b2849
APP_SHARE_DIR=var/share
###< symfony/framework-bundle ###
###> symfony/ai-generic-platform ###
# GENERIC_BASE_URL=https://api.example.com/v1
###< symfony/ai-generic-platform ###
###> symfony/ai-open-router-platform ###
OPENROUTER_API_KEY=
###< symfony/ai-open-router-platform ###

View file

@ -62,6 +62,7 @@ for the first time.
* Automatic thumbnail generation for pictures
* Use cloud providers (like Octopart, Digikey, Farnell, LCSC or TME) to automatically get part information, datasheets, and
prices for parts
* Retrieve part information from arbitrary shop websites, using either conventional data extraction from structured metadata, or AI based data extraction
* API to access Part-DB from other applications/scripts
* [Integration with KiCad](https://docs.part-db.de/usage/eda_integration.html): Use Part-DB as the central datasource for your
KiCad and see available parts from Part-DB directly inside KiCad.

View file

@ -0,0 +1,152 @@
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Controller} from "@hotwired/stimulus";
import "tom-select/dist/css/tom-select.bootstrap5.css";
import '../../css/components/tom-select_extensions.css';
import TomSelect from "tom-select";
import TomSelect_click_to_edit from '../../tomselect/click_to_edit/click_to_edit'
import TomSelect_autoselect_typed from '../../tomselect/autoselect_typed/autoselect_typed'
TomSelect.define('click_to_edit', TomSelect_click_to_edit)
TomSelect.define('autoselect_typed', TomSelect_autoselect_typed)
export default class extends Controller {
_tomSelect;
_platformSelector;
connect() {
let dropdownParent = "body";
if (this.element.closest('.modal')) {
dropdownParent = null
}
//Try to find the platform selector
const platformSelector = document.querySelector("select[data-platform-selector-label='" + this.element.dataset.platformSelector + "']");
//Clear tomselect options, if the platform selector changes
if (platformSelector) {
this.platformSelector = platformSelector;
platformSelector.addEventListener('change', () => {
//Force reload of options by clearing the cache and options of TomSelect and triggering a search with an empty string
this._tomSelect.clearOptions();
this._tomSelect.clearCache();
this._tomSelect.load('');
});
}
let settings = {
persistent: false,
create: true,
maxItems: 1,
preload: 'focus',
createOnBlur: true,
selectOnTab: true,
clearAfterSelect: true,
shouldLoad: ((query) => true),
maxOptions: null,
//This a an ugly solution to disable the delimiter parsing of the TomSelect plugin
delimiter: 'VERY_L0NG_D€LIMITER_WHICH_WILL_NEVER_BE_ENCOUNTERED_IN_A_STRING',
dropdownParent: dropdownParent,
render: {
item: (data, escape) => {
return '<span>' + escape(data.label) + '</span>';
},
option: (data, escape) => {
if (data.image) {
return "<div class='row m-0'><div class='col-2 pl-0 pr-1'><img class='typeahead-image' src='" + data.image + "'/></div><div class='col-10'>" + data.label + "</div></div>"
}
return '<div>' + escape(data.label) + '</div>';
}
},
plugins: {
'autoselect_typed': {},
'click_to_edit': {},
'clear_button': {},
"restore_on_backspace": {}
}
};
if(this.element.dataset.urlTemplate) {
const base_url = this.element.dataset.urlTemplate;
settings.searchField = "label";
settings.sortField = "label";
settings.valueField = "label";
settings.load = (query, callback) => {
if (!this.platformSelector) {
console.error("Platform selector not found for AI model autocomplete");
callback();
return;
}
//Platform is the selected option
const platform = this.platformSelector.value;
if (!platform) {
callback();
return;
}
const self = this;
//Only fetch each platform once
if(self.platformLoaded === platform) {
callback();
}
const url = base_url.replace('__PLATFORM__', encodeURIComponent(platform));
fetch(url)
.then(response => response.json())
.then(json => {
self.platformLoaded = platform;
var data = [];
for (const name in json) {
data.push({
"label": name,
"capabilities": json[name].capabilities,
});
}
callback(data);
}).catch(()=>{
callback();
});
};
}
this._tomSelect = new TomSelect(this.element, settings);
}
disconnect() {
super.disconnect();
//Destroy the TomSelect instance
this._tomSelect.destroy();
}
}

View file

@ -33,6 +33,7 @@
"jbtronics/dompdf-font-loader-bundle": "^1.0.0",
"jbtronics/settings-bundle": "^3.0.0",
"jfcherng/php-diff": "^6.14",
"jkphl/micrometa": "^v3.4.0",
"knpuniversity/oauth2-client-bundle": "^2.15",
"league/commonmark": "^2.7",
"league/csv": "^9.8.0",
@ -56,6 +57,9 @@
"scheb/2fa-trusted-device": "^v7.11.0",
"shivas/versioning-bundle": "^4.0",
"spatie/db-dumper": "^3.3.1",
"symfony/ai-bundle": "^0.8.0",
"symfony/ai-lm-studio-platform": "^0.8.0",
"symfony/ai-open-router-platform": "^0.8.0",
"symfony/apache-pack": "^1.0",
"symfony/asset": "7.4.*",
"symfony/console": "7.4.*",

1683
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -33,4 +33,5 @@ return [
Jbtronics\SettingsBundle\JbtronicsSettingsBundle::class => ['all' => true],
Jbtronics\TranslationEditorBundle\JbtronicsTranslationEditorBundle::class => ['dev' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\AI\AiBundle\AiBundle::class => ['all' => true],
];

27
config/packages/ai.yaml Normal file
View file

@ -0,0 +1,27 @@
ai:
platform:
# Inference Platform configuration
# see https://github.com/symfony/ai/tree/main/src/platform#platform-bridges
# openai:
# api_key: '%env(OPENAI_API_KEY)%'
agent:
# Agent configuration
# see https://symfony.com/doc/current/ai/bundles/ai-bundle.html
# default:
# platform: 'ai.platform.openai'
# model: 'gpt-5-mini'
# prompt: |
# You are a pirate and you write funny.
# tools:
# - 'Symfony\AI\Agent\Bridge\Clock\Clock'
store:
# Store configuration
# chromadb:
# default:
# client: 'client.service.id'
# collection: 'my_collection'

View file

@ -0,0 +1,5 @@
ai:
platform:
generic:
default:
base_url: '%env(GENERIC_BASE_URL)%'

View file

@ -0,0 +1,4 @@
ai:
platform:
lmstudio:
host_url: '%env(string:settings:ai_lmstudio:hostURL)%'

View file

@ -0,0 +1,4 @@
ai:
platform:
openrouter:
api_key: '%env(string:settings:ai_openrouter:apiKey)%'

File diff suppressed because it is too large Load diff

View file

@ -47,6 +47,7 @@ It is installed on a web server and so can be accessed with any browser without
* Easy migration from an existing PartKeepr instance (see [here]({%link partkeepr_migration.md %}))
* Use cloud providers (like Octopart, Digikey, Farnell, Mouser, or TME) to automatically get part information, datasheets, and
prices for parts (see [here]({% link usage/information_provider_system.md %}))
* Retrieve part information from arbitrary shop websites, using either conventional data extraction from structured metadata, or AI based data extraction
* API to access Part-DB from other applications/scripts
* [Integration with KiCad]({%link usage/eda_integration.md %}): Use Part-DB as the central datasource for your
KiCad and see available parts from Part-DB directly inside KiCad.

27
docs/usage/ai.md Normal file
View file

@ -0,0 +1,27 @@
---
layout: default
title: AI features
nav_order: 6
parent: Usage
---
# AI features
Part-DB can utilize large language Models (LLMs) to provide AI-powered features that can assist you in managing your parts and projects.
For now this is mostly the ability to extract part information from websites without any structured data.
## AI platforms
Part-DB is platform agnostic and can work with different AI platforms, both locally and in the cloud. They can be configured in the "AI" tab in the system settings.
Currently, the following platforms are supported:
### OpenRouter
[OpenRouter](https://openrouter.ai/) is a platform that provides access to various LLMs, including models from OpenAI, Anthropic, and more.
You can use OpenRouter to connect to different LLMs and use them for Part-DB's AI features.
You need to supply an API key for OpenRouter to use it as an AI platform in Part-DB.
### LMStudio
[LMStudio](https://lmstudio.ai/) is a local LLM hosting solution that allows you to run LLMs on your own hardware. You can use LMStudio to host your own LLM and connect it to Part-DB for AI features.
Currently only LMStudio without any authentication is supported. Supply your LMStudio instance URL (including the port) to use it as an AI platform in Part-DB.

View file

@ -111,6 +111,19 @@ may have privacy and security implications.
Following env configuration options are available:
* `PROVIDER_GENERIC_WEB_ENABLED`: Set this to `1` to enable the Generic Web URL Provider (optional, default: `0`)
### AI Web Extractor
The AI web extractor provider can extract part information from any webpage using AI-based techniques. It is designed to handle unstructured data and can extract relevant information even from websites that do not use structured data formats like Schema.org.
This provider can be particularly useful for extracting information from websites that have complex layouts or do not follow standard e-commerce practices.
It also potentially extracts more detailed information than the Generic Web URL Provider, as it is not limited to the fields defined in the Schema.org format.
To use the AI Web Extractor, you need to setup an AI platform, in the AI settings tab, and chose a model, which support structured output.
For many use cases a small and cheap model like `google/gemini-2.5-flash-lite` will be sufficient, coming down to costs like 0.003$ per request.
For more complex websites, or if you wanna use the LLM for translation purposes too, you should consider a more powerful model.
You can add some additional instructions for the model, which gets added to the system prompt, to tweak the output of the model.
The provider will download the HTML of the given URL, convert it to markdown and send it to the LLM toghether with structured data extracted from the webpage via conventional methods.
### Octopart
The Octopart provider uses the [Octopart / Nexar API](https://nexar.com/api) to search for parts and get information.

View file

@ -26,11 +26,14 @@ namespace App\Controller;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Exceptions\OAuthReconnectRequiredException;
use App\Form\InfoProviderSystem\FromURLFormType;
use App\Form\InfoProviderSystem\PartSearchType;
use App\Services\InfoProviderSystem\ExistingPartFinder;
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
use App\Services\InfoProviderSystem\PartInfoRetriever;
use App\Services\InfoProviderSystem\ProviderRegistry;
use App\Services\InfoProviderSystem\Providers\GenericWebProvider;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use App\Settings\AppSettings;
use App\Settings\InfoProviderSystem\InfoProviderGeneralSettings;
use Doctrine\ORM\EntityManagerInterface;
@ -172,10 +175,15 @@ class InfoProviderController extends AbstractController
$keyword = $form->get('keyword')->getData();
$providers = $form->get('providers')->getData();
$no_cache_search = $form->get('no_cache_search')->getData();
$no_cache_details = $form->get('no_cache_details')->getData();
$dtos = [];
try {
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers);
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers, options: [
InfoProviderInterface::OPTION_NO_CACHE => $no_cache_search
]);
} catch (ClientException $e) {
$this->addFlash('error', t('info_providers.search.error.client_exception'));
$this->addFlash('error',$e->getMessage());
@ -207,40 +215,41 @@ class InfoProviderController extends AbstractController
return $this->render('info_providers/search/part_search.html.twig', [
'form' => $form,
'results' => $results,
'update_target' => $update_target
'update_target' => $update_target,
'no_cache_details' => $no_cache_details ?? false,
]);
}
#[Route('/from_url', name: 'info_providers_from_url')]
public function fromURL(Request $request, GenericWebProvider $provider): Response
public function fromURL(Request $request, GenericWebProvider $provider, CreateFromUrlHelper $fromUrlHelper): Response
{
$this->denyAccessUnlessGranted('@info_providers.create_parts');
if (!$provider->isActive()) {
if (!$fromUrlHelper->canCreateFromUrl()) {
$this->addFlash('error', "Generic Web Provider is not active. Please enable it in the provider settings.");
return $this->redirectToRoute('info_providers_list');
}
$formBuilder = $this->createFormBuilder();
$formBuilder->add('url', UrlType::class, [
'label' => 'info_providers.from_url.url.label',
'required' => true,
]);
$formBuilder->add('submit', SubmitType::class, [
'label' => 'info_providers.search.submit',
]);
$form = $formBuilder->getForm();
$form = $this->createForm(FromURLFormType::class);
$form->handleRequest($request);
$partDetail = null;
if ($form->isSubmitted() && $form->isValid()) {
//Try to retrieve the part detail from the given URL
$url = $form->get('url')->getData();
$method = $form->get('method')->getData();
$no_cache = $form->get('no_cache')->getData();
$skip_delegation = $form->get('skip_delegation')->getData();
try {
//It's okay if we use the cached results here, as its just for convenience
$searchResult = $this->infoRetriever->searchByKeyword(
keyword: $url,
providers: [$provider]
providers: [$method],
options: [
InfoProviderInterface::OPTION_SKIP_DELEGATION => $skip_delegation,
]
);
if (count($searchResult) === 0) {
@ -251,6 +260,8 @@ class InfoProviderController extends AbstractController
return $this->redirectToRoute('info_providers_create_part', [
'providerKey' => $searchResult->provider_key,
'providerId' => $searchResult->provider_id,
'no_cache' => $no_cache ? 1 : null,
'skip_delegation' => $skip_delegation ? 1 : null,
]);
}
} catch (ExceptionInterface $e) {

View file

@ -40,6 +40,7 @@ use App\Services\Attachments\AttachmentSubmitHandler;
use App\Services\Attachments\PartPreviewGenerator;
use App\Services\EntityMergers\Mergers\PartMerger;
use App\Services\InfoProviderSystem\PartInfoRetriever;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use App\Services\LogSystem\EventCommentHelper;
use App\Services\LogSystem\HistoryHelper;
use App\Services\LogSystem\TimeTravel;
@ -283,7 +284,14 @@ final class PartController extends AbstractController
{
$this->denyAccessUnlessGranted('@info_providers.create_parts');
$dto = $infoRetriever->getDetails($providerKey, $providerId);
//Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information
$no_cache = $request->query->getBoolean('no_cache', false);
$skip_delegation = $request->query->getBoolean('skip_delegation', false);
$dto = $infoRetriever->getDetails($providerKey, $providerId, [
InfoProviderInterface::OPTION_NO_CACHE => $no_cache,
InfoProviderInterface::OPTION_SKIP_DELEGATION => $skip_delegation,
]);
$new_part = $infoRetriever->dtoToPart($dto);
if ($new_part->getCategory() === null || $new_part->getCategory()->getID() === null) {
@ -342,10 +350,13 @@ final class PartController extends AbstractController
$this->denyAccessUnlessGranted('edit', $part);
$this->denyAccessUnlessGranted('@info_providers.create_parts');
//Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information
$no_cache = $request->query->getBoolean('no_cache', false);
//Save the old name of the target part for the template
$old_name = $part->getName();
$dto = $infoRetriever->getDetails($providerKey, $providerId);
$dto = $infoRetriever->getDetails($providerKey, $providerId, [InfoProviderInterface::OPTION_NO_CACHE => $no_cache]);
$provider_part = $infoRetriever->dtoToPart($dto);
$part = $partMerger->merge($part, $provider_part);

View file

@ -22,38 +22,43 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Parameters\AbstractParameter;
use App\Settings\MiscSettings\IpnSuggestSettings;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parameters\AttachmentTypeParameter;
use App\Entity\Parameters\CategoryParameter;
use App\Entity\Parameters\ProjectParameter;
use App\Entity\Parameters\FootprintParameter;
use App\Entity\Parameters\GroupParameter;
use App\Entity\Parameters\ManufacturerParameter;
use App\Entity\Parameters\MeasurementUnitParameter;
use App\Entity\Parameters\PartParameter;
use App\Entity\Parameters\ProjectParameter;
use App\Entity\Parameters\StorageLocationParameter;
use App\Entity\Parameters\SupplierParameter;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Currency;
use App\Repository\ParameterRepository;
use App\Services\AI\AIPlatformRegistry;
use App\Services\AI\AIPlatforms;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use App\Services\Attachments\PartPreviewGenerator;
use App\Services\Tools\TagFinder;
use App\Settings\MiscSettings\IpnSuggestSettings;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\AI\Platform\Capability;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
/**
* In this controller the endpoints for the typeaheads are collected.
@ -121,9 +126,12 @@ class TypeaheadController extends AbstractController
}
#[Route(path: '/parts/search/{query}', name: 'typeahead_parts')]
public function parts(EntityManagerInterface $entityManager, PartPreviewGenerator $previewGenerator,
AttachmentURLGenerator $attachmentURLGenerator, string $query = ""): JsonResponse
{
public function parts(
EntityManagerInterface $entityManager,
PartPreviewGenerator $previewGenerator,
AttachmentURLGenerator $attachmentURLGenerator,
string $query = ""
): JsonResponse {
$this->denyAccessUnlessGranted('@parts.read');
$repo = $entityManager->getRepository(Part::class);
@ -134,7 +142,7 @@ class TypeaheadController extends AbstractController
foreach ($parts as $part) {
//Determine the picture to show:
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
if($preview_attachment instanceof Attachment) {
if ($preview_attachment instanceof Attachment) {
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
} else {
$preview_url = '';
@ -148,7 +156,7 @@ class TypeaheadController extends AbstractController
'footprint' => $part->getFootprint() instanceof Footprint ? $part->getFootprint()->getName() : '',
'description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
'image' => $preview_url,
];
];
}
return new JsonResponse($data);
@ -219,8 +227,36 @@ class TypeaheadController extends AbstractController
$partRepository = $entityManager->getRepository(Part::class);
$ipnSuggestions = $partRepository->autoCompleteIpn($clonedPart, $description, $this->ipnSuggestSettings->suggestPartDigits);
$ipnSuggestions = $partRepository->autoCompleteIpn($clonedPart, $description,
$this->ipnSuggestSettings->suggestPartDigits);
return new JsonResponse($ipnSuggestions);
}
#[Route(path: '/ai/{platform}/models', name: 'typeahead_ai_models', requirements: ['platform' => '.+'])]
public function aiModels(
AIPlatforms $platform,
Request $request,
AIPlatformRegistry $platformRegistry,
CacheInterface $cache,
): JsonResponse {
$this->denyAccessUnlessGranted('@config.change_system_settings');
$capability_filter = $request->query->getEnum('capability', Capability::class);
$models = $cache->get('ai_models_'.$platform->value.'_'.($capability_filter->value ?? 'all'),
function (ItemInterface $item) use ($platformRegistry, $platform, $capability_filter) {
$item->expiresAfter(3600); //Cache for 1 hour
if ($capability_filter === null) {
return $platformRegistry->getPlatform($platform)->getModelCatalog()->getModels();
}
//Otherwise filter the models by the capability
return array_filter($platformRegistry->getPlatform($platform)->getModelCatalog()->getModels(),
static fn(array $model) => in_array($capability_filter, $model['capabilities'], true)
);
});
return new JsonResponse($models);
}
}

View file

@ -0,0 +1,87 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\InfoProviderSystem;
use App\Services\InfoProviderSystem\ProviderRegistry;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
class FromURLFormType extends AbstractType
{
public function __construct(private readonly ProviderRegistry $providerRegistry)
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('url', UrlType::class, [
'label' => 'info_providers.from_url.url.label',
'required' => true,
]);
$builder->add('method', ChoiceType::class, [
'expanded' => true,
'data' => 'generic_web', //Default value
'label' => 'info_providers.from_url.method',
'choices' => [
'info_providers.from_url.method.generic_web' => 'generic_web',
'info_providers.from_url.method.ai_web' => 'ai_web',
],
'choice_attr' => function ($choice, $key, $value) {
//Disable all providers that are not active
$provider = $this->providerRegistry->getProviderByKey($value);
if (!$provider->isActive()) {
return ['disabled' => 'disabled'];
}
return [];
},
//Render the choices as inline radio buttons
'label_attr' => [
'class' => 'radio-inline',
],
]);
$builder->add('no_cache', CheckboxType::class, [
'label' => 'info_providers.from_url.no_cache',
'required' => false,
]);
$builder->add('skip_delegation', CheckboxType::class, [
'label' => 'info_providers.from_url.skip_delegation',
'required' => false,
]);
$builder->add('submit', SubmitType::class, [
'label' => 'info_providers.search.submit',
]);
}
}

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Form\InfoProviderSystem;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SearchType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
@ -40,8 +41,17 @@ class PartSearchType extends AbstractType
'help' => 'info_providers.search.providers.help',
]);
$builder->add('no_cache_search', CheckboxType::class, [
'label' => 'info_providers.no_cache_search',
'required' => false,
]);
$builder->add('no_cache_details', CheckboxType::class, [
'label' => 'info_providers.no_cache_details',
'required' => false,
]);
$builder->add('submit', SubmitType::class, [
'label' => 'info_providers.search.submit'
]);
}
}
}

View file

@ -0,0 +1,72 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\Settings;
use Symfony\AI\Platform\Capability;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* An text input with autocomplete for AI models from the given platform.
* The platform is determined by the value of another form field, which is specified by the "platform_selector" option. This allows to filter the available models based on the selected platform.
*/
final class AiModelsType extends AbstractType
{
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
}
public function getParent(): string
{
return TextType::class;
}
public function configureOptions(OptionsResolver $resolver): void
{
//The target label of the platform select, which is used to filter the models for the selected platform.
$resolver->setRequired('platform_selector');
$resolver->setAllowedTypes('platform_selector', 'string');
//Only show models, that have the given capability. This is used to only show models that support structured output for the AI extractor settings.
$resolver->setDefault('filter_capability', null);
$resolver->setAllowedTypes('filter_capability', ['null', Capability::class]);
}
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$urlOptions = ['platform' => '__PLATFORM__'];
if ($options['filter_capability'] !== null) {
$urlOptions['capability'] = $options['filter_capability']->value;
}
$view->vars['attr']['data-url-template'] = $this->urlGenerator->generate('typeahead_ai_models', $urlOptions);
$view->vars['attr']['data-controller'] = 'elements--ai-model-autocomplete';
$view->vars['attr']['data-platform-selector'] = $options['platform_selector'];
}
}

View file

@ -0,0 +1,65 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Form\Settings;
use App\Services\AI\AIPlatformRegistry;
use App\Services\AI\AIPlatforms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Allow to choose an AI platform from the enabled platforms in the system. This is used in the settings to choose the default platform for AI features.
*/
final class AiPlatformChoiceType extends AbstractType
{
public function __construct(private readonly AIPlatformRegistry $platformRegistry)
{
}
public function getParent(): string
{
return EnumType::class;
}
public function configureOptions(OptionsResolver $resolver): void
{
$choices = array_map(static fn(string $val) => AIPlatforms::from($val), array_keys($this->platformRegistry->getEnabledPlatforms()));
$resolver->setDefaults([
'class' => AIPlatforms::class,
'choices' => $choices,
'required' => false,
'platform_selector_label' => null
]);
}
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$view->vars['attr']['data-platform-selector-label'] = $options['platform_selector_label'] ?? $view->vars['id'].'_label';
}
}

View file

@ -0,0 +1,94 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\AI;
use Jbtronics\SettingsBundle\Manager\SettingsManagerInterface;
use Symfony\AI\Platform\PlatformInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
final readonly class AIPlatformRegistry
{
/**
* All registered platforms, indexed by their service tag name (e.g. "openrouter", "lmstudio")
* @var array<string, PlatformInterface> $allPlatforms
*/
private array $allPlatforms;
/**
* All registered platforms, indexed by their AIPlatforms enum value (e.g. AIPlatforms::OPENROUTER->value)
* @var array<string, PlatformInterface> $enabledPlatforms
*/
private array $enabledPlatforms;
public function __construct(
SettingsManagerInterface $settingsManager,
#[AutowireIterator(tag: 'ai.platform', indexAttribute: 'name')]
iterable $platforms,
) {
$this->allPlatforms = iterator_to_array($platforms);
//Check which platforms are active based on the settings and store them in $activePlatforms
$tmp = [];
foreach (AIPlatforms::cases() as $platform) {
if (isset($this->allPlatforms[$platform->toServiceTagName()])) {
//Check if the platform is active by calling its isActive() on the settings class
$settings = $settingsManager->get($platform->toSettingsClass());
if (!$settings->isAIPlatformEnabled()) {
continue;
}
$tmp[$platform->value] = $this->allPlatforms[$platform->toServiceTagName()];
}
}
$this->enabledPlatforms = $tmp;
}
public function getPlatform(AIPlatforms $platform): PlatformInterface
{
if (!isset($this->enabledPlatforms[$platform->value])) {
throw new \InvalidArgumentException(sprintf('AI platform "%s" is not active or does not exist.', $platform->name));
}
return $this->enabledPlatforms[$platform->value];
}
/**
* Check if the given platform is active (i.e. it is registered and its settings are properly configured)
* @param AIPlatforms $platform
* @return bool
*/
public function isEnabled(AIPlatforms $platform): bool
{
return isset($this->enabledPlatforms[$platform->value]);
}
/**
* Returns an array of all active platforms, indexed by their AIPlatforms enum value (e.g. AIPlatforms::OPENROUTER->value)
* @return PlatformInterface[]
*/
public function getEnabledPlatforms(): array
{
return $this->enabledPlatforms;
}
}

View file

@ -0,0 +1,33 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\AI;
interface AIPlatformSettingsInterface
{
/**
* Returns true, if the AI platform is enabled in the settings and can be used, false otherwise.
* @return bool
*/
public function isAIPlatformEnabled(): bool;
}

View file

@ -0,0 +1,64 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\AI;
use App\Settings\AISettings\LMStudioSettings;
use App\Settings\AISettings\OpenRouterSettings;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
enum AIPlatforms: string implements TranslatableInterface
{
case OPENROUTER = 'openrouter';
case LMSTUDIO = 'lmstudio';
/**
* Returns the name attribute of the service tag for this platform, which is used to register the platform in the AIPlatformRegistry
* @return string
*/
public function toServiceTagName(): string
{
return $this->value;
}
/**
* Returns the class name of the settings class for this platform, which implements AIPlatformSettingsInterface
* @return string
* @phpstan-return class-string<AIPlatformSettingsInterface>
*/
public function toSettingsClass(): string
{
return match ($this) {
self::LMSTUDIO => LMStudioSettings::class,
self::OPENROUTER => OpenRouterSettings::class,
};
}
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
$key = 'settings.ai.' . $this->value;
return $translator->trans($key, locale: $locale);
}
}

View file

@ -0,0 +1,61 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\AI;
use Symfony\AI\Platform\Bridge\Generic\CompletionsModel;
use Symfony\AI\Platform\Exception\ModelNotFoundException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
/**
* This is a wrapper, to allow accepting all models, even if they are not contained in the decorated ModelCatalogInterface.
* This is a workaround for outdated/incomplete model catalogs provided by AI platforms, which do not contain all available models, or do not update their catalogs frequently enough.
*/
#[AsDecorator('ai.platform.model_catalog.lmstudio')]
#[AsDecorator('ai.platform.model_catalog.openrouter')]
final readonly class AcceptAllModelsCatalog implements ModelCatalogInterface
{
public function __construct(private ModelCatalogInterface $decorated)
{
}
public function getModel(string $modelName): Model
{
//Use the actual values when its available.
try {
return $this->decorated->getModel($modelName);
} catch (ModelNotFoundException $e) {
//If the model is not found, return a generic model with the given name and no capabilities.
return new CompletionsModel($modelName, []);
}
}
public function getModels(): array
{
//Return the actual models catalog here for correct autocompletition
return $this->decorated->getModels();
}
}

View file

@ -0,0 +1,109 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\InfoProviderSystem;
use App\Entity\UserSystem\User;
use App\Exceptions\ProviderIDNotSupportedException;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use Symfony\Bundle\SecurityBundle\Security;
final readonly class CreateFromUrlHelper
{
public function __construct(private Security $security,
private ProviderRegistry $providerRegistry,
private PartInfoRetriever $infoRetriever,
)
{
}
/**
* Checks if at least one provider can create parts from an URL and the current user is allowed to use it.
* This is used to determine if the "From URL" feature should be shown to the user.
* @return bool
*/
public function canCreateFromUrl(): bool
{
if (!$this->security->isGranted('@info_providers.create_parts')) {
return false;
}
//Check if either the generic web provider or the ai web provider is active
$genericWebProvider = $this->providerRegistry->getProviderByKey('generic_web');
$aiWebProvider = $this->providerRegistry->getProviderByKey('ai_web');
return $genericWebProvider->isActive() || $aiWebProvider->isActive();
}
/**
* Delegates the URL to another provider if possible, otherwise return null
* @param string $url
* @return SearchResultDTO|null
*/
public function delegateToOtherProvider(string $url, InfoProviderInterface $callingInfoProvider): ?SearchResultDTO
{
//Extract domain from url:
$host = parse_url($url, PHP_URL_HOST);
if ($host === false || $host === null) {
return null;
}
$provider = $this->providerRegistry->getProviderHandlingDomain($host);
if ($provider !== null && $provider->isActive() && $provider->getProviderKey() !== $callingInfoProvider->getProviderKey()) {
try {
$id = $provider->getIDFromURL($url);
if ($id !== null) {
$results = $this->infoRetriever->searchByKeyword($id, [$provider]);
if (count($results) > 0) {
return $results[0];
}
}
return null;
} catch (ProviderIDNotSupportedException $e) {
//Ignore and continue
return null;
}
}
return null;
}
/**
* Delegates the URL to another provider if possible and returns the details, otherwise return null
* @param string $url
* @param InfoProviderInterface $callingInfoProvider
* @return PartDetailDTO|null
*/
public function delegateToOtherProviderDetails(string $url, InfoProviderInterface $callingInfoProvider): ?PartDetailDTO
{
$delegatedResult = $this->delegateToOtherProvider($url, $callingInfoProvider);
if ($delegatedResult !== null) {
return $this->infoRetriever->getDetailsForSearchResult($delegatedResult);
}
return null;
}
}

View file

@ -0,0 +1,252 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\InfoProviderSystem;
use App\Entity\Parts\ManufacturingStatus;
use App\Services\InfoProviderSystem\DTOs\FileDTO;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
/**
* This class allows to convert the JSON data returned by an LLM into the DTOs used by the info provider system later.
*/
final class DTOJsonSchemaConverter
{
/**
* Returns the JSON schema, that defines the expected structure of the JSON data returned by the LLM.
* @return array
*/
public function getJSONSchema(): array
{
return [
'name' => 'clock',
'strict' => true,
'schema' => [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string', 'description' => 'Product name'],
'description' => ['type' => 'string', 'description' => 'A short description of the product, maybe containing the most important things. Onnly One line.'],
'manufacturer' => ['type' => ['string', 'null'], 'description' => 'Manufacturer name'],
'mpn' => ['type' => ['string', 'null'], 'description' => 'Manufacturer Part Number'],
'category' => ['type' => ['string', 'null'], 'description' => 'Product category, e.g. "Passive components -> Resistors"'],
'manufacturing_status' => ['type' => ['string', 'null'], 'enum' => ['active', 'obsolete', 'nrfnd', 'discontinued', null], 'description' => 'Manufacturing status'],
'footprint' => ['type' => ['string', 'null'], 'description' => 'Package/footprint type, like "SOT-23", "DIP-8", "QFN-32" etc.'],
'mass' => ['type' => ['number', 'null'], 'description' => 'Mass of the product in grams'],
'gtin' => ['type' => ['string', 'null'], 'description' => 'Global Trade Item Number (GTIN) / EAN / UPC code for barcodes'],
'notes' => ['type' => ['string', 'null'], 'description' => 'Optional long description of the part with more details than description. Can be markdown formatted.'],
'parameters' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string'],
'symbol' => ['type' => ['string', 'null'], 'description' => 'An optional quantity symbol for the parameter in latex code, like R_1'],
'value_typical' => ['type' => ['number', 'null'], 'description' => 'The typical value of the parameter. For example, for a resistor this could be 100 for a 100 Ohm resistor. Also used if only one numeric value is given. If used an unit should be given'],
'value_min' => ['type' => ['number', 'null'], 'description' => 'If a range is given for the parameter, this is the minimum value. Null if no range is given.'],
'value_max' => ['type' => ['number', 'null'], 'description' => 'If a range is given for the parameter, this is the maximum value. Null if not a range.'],
'value_text' => ['type' => ['string', 'null'], 'description' => 'When a value is not numeric it can be put here as text. Only use if it does not fit in value_min, value_typical or value_max. E.g. "Yes", "Red", etc.'],
'group' => ['type' => ['string', 'null'], 'description' => 'An optional group name for the parameter, e.g. "Electrical parameters", "Mechanical parameters" etc.'],
'unit' => ['type' => ['string', 'null'], 'description' => 'The unit of the parameter values, e.g. kg, Ohm, V, etc.'],
],
'required' => ['name', 'value_typical', 'value_min', 'value_max', 'value_text']
],
],
'datasheets' => [
'description' => 'A list of datasheets, manuals, or other technical documents related to the product. Not images, but actual documents, preferably PDFs.',
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'url' => ['type' => 'string'],
'description' => ['type' => 'string'],
],
'required' => ['url'],
],
],
'images' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'url' => ['type' => 'string'],
'description' => ['type' => 'string'],
],
'required' => ['url'],
],
],
'vendor_infos' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'distributor_name' => ['type' => 'string', 'description' => 'Name of the distributor or vendor. Typically the shop name'],
'order_number' => ['type' => ['string', 'null'], 'description' => 'The order number or SKU used by the distributor. Optional, but can help to find the product on the distributor website.'],
'product_url' => ['type' => 'string'],
'prices_include_vat' => ['type' => ['boolean', 'null'], 'description' => 'Whether the prices include VAT or not. Null if unknown.'],
'prices' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'minimum_quantity' => ['type' => 'integer', 'description' => 'Minimum quantity for this price tier. 1 when no tiered pricing is available.'],
'price' => ['type' => 'number', 'description' => 'Price for the given minimum quantity.'],
'currency' => ['type' => 'string', 'description' => 'Currency ISO code, e.g. USD'],
],
'required' => ['minimum_quantity', 'price', 'currency'],
],
],
],
'required' => ['distributor_name', 'product_url'],
],
],
'manufacturer_product_url' => ['type' => ['string', 'null'], 'description' => 'Manufacturer product page URL'],
],
'required' => ['name', 'description'],
]
];
}
public function jsonToDTO(array $data, string $providerKey, string $providerId, ?string $productUrl = null, string $distributorNameFallback = '???'): PartDetailDTO
{
// Map manufacturing status
$manufacturingStatus = null;
if (!empty($data['manufacturing_status'])) {
$status = strtolower((string) $data['manufacturing_status']);
$manufacturingStatus = match ($status) {
'active' => ManufacturingStatus::ACTIVE,
'obsolete', 'discontinued' => ManufacturingStatus::DISCONTINUED,
'nrfnd', 'not recommended for new designs' => ManufacturingStatus::NRFND,
'eol' => ManufacturingStatus::EOL,
'announced' => ManufacturingStatus::ANNOUNCED,
default => null,
};
}
// Build parameters
$parameters = null;
if (!empty($data['parameters']) && is_array($data['parameters'])) {
$parameters = [];
foreach ($data['parameters'] as $p) {
if (!empty($p['name'])) {
$parameters[] = new ParameterDTO(
name: $p['name'],
value_text: $p['value_text'] ?? null,
value_typ: isset($p['value_typical']) && is_numeric($p['value_typical']) ? (float) $p['value_typical'] : null,
value_min: isset($p['value_min']) && is_numeric($p['value_min']) ? (float) $p['value_min'] : null,
value_max: isset($p['value_max']) && is_numeric($p['value_max']) ? (float) $p['value_max'] : null,
unit: $p['unit'] ?? null,
symbol: $p['symbol'] ?? null,
group: $p['group'] ?? null,
);
}
}
}
// Build datasheets
$datasheets = null;
if (!empty($data['datasheets']) && is_array($data['datasheets'])) {
$datasheets = [];
foreach ($data['datasheets'] as $d) {
if (!empty($d['url'])) {
$datasheets[] = new FileDTO(
url: $d['url'],
name: $d['description'] ?? 'Datasheet'
);
}
}
}
// Build images
$images = null;
if (!empty($data['images']) && is_array($data['images'])) {
$images = [];
foreach ($data['images'] as $i) {
if (!empty($i['url'])) {
$images[] = new FileDTO(
url: $i['url'],
name: $i['description'] ?? 'Image'
);
}
}
}
// Build vendor infos
$vendorInfos = null;
if (!empty($data['vendor_infos']) && is_array($data['vendor_infos'])) {
$vendorInfos = [];
foreach ($data['vendor_infos'] as $v) {
$prices = [];
if (!empty($v['prices']) && is_array($v['prices'])) {
foreach ($v['prices'] as $p) {
$prices[] = new PriceDTO(
minimum_discount_amount: (int) ($p['minimum_quantity'] ?? 1),
price: (string) ($p['price'] ?? 0),
currency_iso_code: $p['currency'] ?? null,
price_related_quantity: 1,
);
}
}
$vendorInfos[] = new PurchaseInfoDTO(
distributor_name: $v['distributor_name'] ?? $distributorNameFallback,
order_number: $v['order_number'] ?? 'Unknown',
prices: $prices,
product_url: $v['product_url'] ?? $productUrl,
prices_include_vat: $v['prices_include_vat'] ?? null,
);
}
}
// Get preview image URL
$previewImageUrl = null;
if (!empty($data['images']) && is_array($data['images']) && !empty($data['images'][0]['url'])) {
$previewImageUrl = $data['images'][0]['url'];
}
return new PartDetailDTO(
provider_key: $providerKey,
provider_id: $providerId,
name: $data['name'] ?? 'Unknown',
description: $data['description'] ?? '',
category: $data['category'] ?? null,
manufacturer: $data['manufacturer'] ?? null,
mpn: $data['mpn'] ?? null,
preview_image_url: $previewImageUrl,
manufacturing_status: $manufacturingStatus,
provider_url: $productUrl,
footprint: $data['footprint'] ?? null,
gtin: $data['gtin'] ?? null,
notes: $data['notes'] ?? null,
datasheets: $datasheets,
images: $images,
parameters: $parameters,
vendor_infos: $vendorInfos,
mass: isset($data['mass']) && is_numeric($data['mass']) ? (float) $data['mass'] : null,
manufacturer_product_url: $data['manufacturer_product_url'] ?? null,
);
}
}

View file

@ -53,6 +53,7 @@ final class PartInfoRetriever
* Search for a keyword in the given providers. The results can be cached
* @param string[]|InfoProviderInterface[] $providers A list of providers to search in, either as provider keys or as provider instances
* @param string $keyword The keyword to search for
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
* @return SearchResultDTO[] The search results
* @throws InfoProviderNotActiveException if any of the given providers is not active
* @throws ClientException if any of the providers throws an exception during the search
@ -60,7 +61,7 @@ final class PartInfoRetriever
* @throws TransportException if any of the providers throws an exception during the search
* @throws OAuthReconnectRequiredException if any of the providers throws an exception during the search that indicates that the OAuth token needs to be refreshed
*/
public function searchByKeyword(string $keyword, array $providers): array
public function searchByKeyword(string $keyword, array $providers, array $options = []): array
{
$results = [];
@ -79,7 +80,7 @@ final class PartInfoRetriever
}
/** @noinspection SlowArrayOperationsInLoopInspection */
$results = array_merge($results, $this->searchInProvider($provider, $keyword));
$results = array_merge($results, $this->searchInProvider($provider, $keyword, $options));
}
return $results;
@ -89,15 +90,31 @@ final class PartInfoRetriever
* Search for a keyword in the given provider. The result is cached for 7 days.
* @return SearchResultDTO[]
*/
protected function searchInProvider(InfoProviderInterface $provider, string $keyword): array
protected function searchInProvider(InfoProviderInterface $provider, string $keyword, array $options = []): array
{
//Generate key and escape reserved characters from the provider id
$escaped_keyword = hash('xxh3', $keyword);
return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$escaped_keyword}", function (ItemInterface $item) use ($provider, $keyword) {
$no_cache = $options[InfoProviderInterface::OPTION_NO_CACHE] ?? false;
//Exclude the no_cache option from the options hash, since it should not affect the cache key, as it only determines whether to bypass the cache or not, but does not change the actual search results
$options_without_cache = $options;
unset($options_without_cache[InfoProviderInterface::OPTION_NO_CACHE]);
//Generate a hash for the options, to ensure that different options result in different cache entries
$options_hash = hash('xxh3', json_encode($options_without_cache, JSON_THROW_ON_ERROR));
$cache_key = "search_{$provider->getProviderKey()}_{$escaped_keyword}_{$options_hash}";
//If no_cache is set, bypass the cache and get fresh results from the provider
if ($no_cache) {
$this->partInfoCache->delete($cache_key);
}
return $this->partInfoCache->get($cache_key, function (ItemInterface $item) use ($provider, $keyword, $options) {
//Set the expiration time
$item->expiresAfter(!$this->debugMode ? self::CACHE_RESULT_EXPIRATION : 10);
return $provider->searchByKeyword($keyword);
return $provider->searchByKeyword($keyword, $options);
});
}
@ -106,10 +123,11 @@ final class PartInfoRetriever
* The result is cached for 4 days.
* @param string $provider_key
* @param string $part_id
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
* @return PartDetailDTO
* @throws InfoProviderNotActiveException if the the given providers is not active
*/
public function getDetails(string $provider_key, string $part_id): PartDetailDTO
public function getDetails(string $provider_key, string $part_id, array $options = []): PartDetailDTO
{
$provider = $this->provider_registry->getProviderByKey($provider_key);
@ -118,13 +136,26 @@ final class PartInfoRetriever
throw InfoProviderNotActiveException::fromProvider($provider);
}
//Exclude the no_cache option from the options hash, since it should not affect the cache key, as it only determines whether to bypass the cache or not, but does not change the actual search results
$options_without_cache = $options;
unset($options_without_cache[InfoProviderInterface::OPTION_NO_CACHE]);
//Generate a hash for the options, to ensure that different options result in different cache entries
$options_hash = hash('xxh3', json_encode($options_without_cache, JSON_THROW_ON_ERROR));
//Generate key and escape reserved characters from the provider id
$escaped_part_id = hash('xxh3', $part_id);
return $this->partInfoCache->get("details_{$provider_key}_{$escaped_part_id}", function (ItemInterface $item) use ($provider, $part_id) {
$cache_key = "details_{$provider_key}_{$escaped_part_id}_{$options_hash}";
//Delete the cache entry if no_cache is set, to ensure that the next get call will fetch fresh data from the provider, instead of returning stale data from the cache.
if ($options[InfoProviderInterface::OPTION_NO_CACHE] ?? false) {
$this->partInfoCache->delete($cache_key);
}
return $this->partInfoCache->get($cache_key, function (ItemInterface $item) use ($provider, $part_id, $options) {
//Set the expiration time
$item->expiresAfter(!$this->debugMode ? self::CACHE_DETAIL_EXPIRATION : 10);
return $provider->getDetails($part_id);
return $provider->getDetails($part_id, $options);
});
}

View file

@ -0,0 +1,282 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
* Copyright (C) 2026 Rahul Singh (https://github.com/rahools)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\InfoProviderSystem\Providers;
use App\Exceptions\ProviderIDNotSupportedException;
use App\Helpers\RandomizeUseragentHttpClient;
use App\Services\AI\AIPlatformRegistry;
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
use App\Services\InfoProviderSystem\DTOJsonSchemaConverter;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Settings\InfoProviderSystem\AIExtractorSettings;
use Brick\Schema\SchemaReader;
use Jkphl\Micrometa;
use League\HTMLToMarkdown\HtmlConverter;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
use Symfony\Component\Intl\Languages;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use function Symfony\Component\String\u;
final class AIWebProvider implements InfoProviderInterface
{
use FixAndValidateUrlTrait;
private const DISTRIBUTOR_NAME = 'Website';
private readonly HttpClientInterface $httpClient;
public function __construct(
HttpClientInterface $httpClient,
private readonly AIExtractorSettings $settings,
private readonly AIPlatformRegistry $AIPlatformRegistry,
private readonly DTOJsonSchemaConverter $jsonSchemaConverter,
private readonly CacheItemPoolInterface $partInfoCache,
private readonly CreateFromUrlHelper $createFromUrlHelper,
) {
//Use NoPrivateNetworkHttpClient to prevent SSRF vulnerabilities, and RandomizeUseragentHttpClient to make it harder for servers to block us
$this->httpClient = (new RandomizeUseragentHttpClient(new NoPrivateNetworkHttpClient($httpClient)))->withOptions(
[
'timeout' => 15,
]
);
}
public function getProviderInfo(): array
{
return [
'name' => 'AI Web Extractor',
'description' => 'Extract part info from any URL using LLM',
//'url' => 'https://openrouter.ai',
'disabled_help' => 'Configure AI settings',
'settings_class' => AIExtractorSettings::class,
];
}
public function getProviderKey(): string
{
return 'ai_web';
}
public function isActive(): bool
{
return $this->settings->platform !== null && $this->settings->model !== null && $this->settings->model !== '';
}
public function searchByKeyword(string $keyword, array $options = []): array
{
$url = $this->fixAndValidateURL($keyword);
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
//Before loading the page, try to delegate to another provider
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProvider($url, $this);
if ($delegatedPart !== null) {
return [$delegatedPart];
}
}
try {
$new_options = $options;
$new_options[self::OPTION_SKIP_DELEGATION] = true; //Skip delegation for the getDetails call to prevent infinite loops
return [
$this->getDetails($keyword, $new_options)
]; } catch (ProviderIDNotSupportedException $e) {
return [];
}
}
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$url = $this->fixAndValidateURL($id);
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
//Before loading the page, try to delegate to another provider
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProviderDetails($url, $this);
if ($delegatedPart !== null) {
return $delegatedPart;
}
}
//Check if we have a cached result for this URL, to avoid unnecessary LLM calls, which can be slow and costly.
$cacheKey = 'ai_web_'.hash('xxh3', $url);
//If ignore cache option is set, skip cache and fetch fresh data
if ($options[self::OPTION_NO_CACHE] ?? false) {
$this->partInfoCache->deleteItem($cacheKey);
}
//Return cached result if available
$cacheItem = $this->partInfoCache->getItem($cacheKey);
if ($cacheItem->isHit()) {
return $cacheItem->get();
}
// Fetch HTML content
$response = $this->httpClient->request('GET', $url);
$html = $response->getContent();
//Convert html to markdown, to provide a cleaner input to the LLM.
$markdown = $this->htmlToMarkdown($html);
//Truncate markdown to max content length, if needed
$markdown = u($markdown)->truncate($this->settings->maxContentLength, '... [truncated]')->toString();
//Extract structured data using traditional methods, to provide additional context to the LLM. This can help improve accuracy, especially for technical specifications that might be in tables or specific formats.
$structuredData = $this->extractStructuredData($html, $url);
// Call LLM
$llmResponse = $this->callLLM($markdown, $url, $structuredData);
// Build and return PartDetailDTO
$result = $this->jsonSchemaConverter->jsonToDTO($llmResponse, $this->getProviderKey(), $url, $url, self::DISTRIBUTOR_NAME);
// Cache the result for future use, to improve performance and reduce costs.
$cacheItem->set($result);
$cacheItem->expiresAfter(3600 * 2); //Cache for 2 hours, as web content can change frequently, but we still want to benefit from caching for repeated accesses.
$this->partInfoCache->save($cacheItem);
return $result;
}
/**
* Extracts structured data from the HTML using microformats.
* @param string $html
* @param string $url
* @return string JSON encoded structured data
*/
private function extractStructuredData(string $html, string $url): string
{
$micrometa = new Micrometa\Ports\Parser();
$items = $micrometa($url, $html);
return json_encode($items->toObject(), JSON_THROW_ON_ERROR);
}
private function htmlToMarkdown(string $html): string
{
//Extract only the main content of the page to avoid overwhelming the LLM with irrelevant information.
$crawler = new Crawler($html);
$mainContent = $crawler->filter('main, article, #content');
// If we found a specific content area, get its HTML; otherwise, use the whole body.
//Concat the html of all matched nodes, to provide more context to the LLM, especially for pages that use multiple sections for product info.
if ($mainContent->count() > 0) {
$htmlToConvert = '';
foreach ($mainContent as $node) {
$htmlToConvert .= $node->ownerDocument->saveHTML($node);
$htmlToConvert .= "\n\n"; // Add some spacing between sections
}
} else {
//Use the whole body content, as it might contain relevant information, especially for simpler pages that don't have a clear main/content section.
$htmlToConvert = $html;
}
//Concert to markdown
$converter = new HtmlConverter([
'strip_tags' => true, // Removes tags that aren't Markdown-compatible (like <div>)
'hard_break' => true, // Preserves line breaks
'remove_nodes' => 'nav footer script style' // Extra safety layer
]);
return $converter->convert($htmlToConvert);
}
public function getCapabilities(): array
{
return [
ProviderCapabilities::BASIC,
ProviderCapabilities::PICTURE,
ProviderCapabilities::DATASHEET,
ProviderCapabilities::PRICE,
ProviderCapabilities::PARAMETERS,
];
}
private function callLLM(string $htmlContent, string $url, ?string $structuredData = null): array
{
$input = new MessageBag(
Message::forSystem($this->buildSystemPrompt()),
Message::ofUser("Extract part information from this webpage content:\n\nURL: $url\n\n$htmlContent")
);
if ($structuredData) {
$input->add(Message::ofUser("Following data was extracted using traditional methods, but might be incomplete or inaccurate.
Enrich it with the actual website data:\n\n".$structuredData));
}
try {
$aiPlatform = $this->AIPlatformRegistry->getPlatform($this->settings->platform ?? throw new \RuntimeException('No AI platform selected') );
//'openai/gpt-5-mini'
$result = $aiPlatform->invoke($this->settings->model ?? throw new \RuntimeException('No model selected'), $input, [
'response_format' => [
'type' => 'json_schema',
'json_schema' => $this->jsonSchemaConverter->getJSONSchema(),
]
]);
} catch (\Throwable $e) {
throw new \RuntimeException('LLM invocation failed: '.$e->getMessage(), previous: $e);
}
return $result->getResult()->getContent();
}
private function buildSystemPrompt(): string
{
$tmp = <<<'PROMPT'
You are an expert at extracting electronic component information from web pages. Extract structured data in JSON format, from markdown extracted from a product page.
Focus on the main content of the page, such as product descriptions, specifications, and tables. Ignore navigation menus, footers, and sidebars.
Rules:
- manufacturing_status: Use "active", "obsolete", "nrfnd" (not recommended for new designs), "discontinued", or null
- parameters: Extract technical specs like voltage, current, temperature, etc. and put them into the fields according to the JSON schema. Include units if available.
- prices: Extract pricing tiers with minimum_quantity, price, and currency code
- URLs must be absolute (include https://...)
- If information is not found, use null
- Try to avoid duplicating parameters, if the same parameter is mentioned multiple times, or if it is already used in another field.
- Include only the 1 to 3 most relevant images, such as the main product image or important diagrams. Ignore decorative images, logos, or icons.
PROMPT;
if ($this->settings->outputLanguage === null) {
$tmp .= "\n\nProvide the response in the same language of the webpage.";
} else {
$tmp .= "\n\nThe response must be in ". Languages::getName($this->settings->outputLanguage, 'en') ." language. Translate texts if needed.";
}
if ($this->settings->additionalInstructions) {
$tmp .= "\n\nAdditional instructions:\n" . $this->settings->additionalInstructions;
}
return $tmp;
}
}

View file

@ -34,7 +34,8 @@ interface BatchInfoProviderInterface extends InfoProviderInterface
* Search for multiple keywords in a single batch operation and return the results, ordered by the keywords.
* This allows for a more efficient search compared to running multiple single searches.
* @param string[] $keywords
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
* @return array<string, SearchResultDTO[]> An associative array where the key is the keyword and the value is the search results for that keyword
*/
public function searchByKeywordsBatch(array $keywords): array;
public function searchByKeywordsBatch(array $keywords, array $options = []): array;
}

View file

@ -120,7 +120,7 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
];
}
private function getProduct(string $code): array
private function getProduct(string $code, bool $use_cache = true): array
{
$code = strtoupper(trim($code));
if ($code === '') {
@ -132,6 +132,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
md5($code . '|' . $this->settings->language . '|' . $this->settings->currency)
);
if (!$use_cache) {
$this->partInfoCache->deleteItem($cacheKey);
unset($this->productCache[$cacheKey]);
}
if (isset($this->productCache[$cacheKey])) {
return $this->productCache[$cacheKey];
}
@ -461,9 +466,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
}
/**
* @param string $keyword
* @param array $options
* @return PartDetailDTO[]
*/
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$keyword = strtoupper(trim($keyword));
if ($keyword === '') {
@ -486,17 +493,18 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
// Fallback: try direct lookup by code
try {
$product = $this->getProduct($keyword);
$product = $this->getProduct($keyword, use_cache: !($options[self::OPTION_NO_CACHE] ?? false));
return [$this->getPartDetail($product)];
} catch (\Throwable $e) {
return [];
}
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
// Detail endpoint is /products/{code}/
$response = $this->getProduct($id);
//By default use cache for details, but allow bypassing cache with option (e.g. for refresh)
$response = $this->getProduct($id, use_cache: !($options[self::OPTION_NO_CACHE] ?? false));
return $this->getPartDetail($response);
}
@ -588,10 +596,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
}
/**
* @param string[] $keywords
* @param array $keywords
* @param array $options
* @return array<string, SearchResultDTO[]>
*/
public function searchByKeywordsBatch(array $keywords): array
public function searchByKeywordsBatch(array $keywords, array $options = []): array
{
/** @var array<string, SearchResultDTO[]> $results */
$results = [];
@ -643,27 +652,27 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
public function getIDFromURL(string $url): ?string
{
//Inputs:
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/
//Inputs:
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/
//https://www.buerklin.com/de/p/40F1332/
//https://www.buerklin.com/en/p/bkl-electronic/dc-connectors/072341-l/40F1332/
//https://www.buerklin.com/en/p/40F1332/
//The ID is the last part after the manufacturer/category/mpn segment and before the final slash
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/#download should also work
$path = parse_url($url, PHP_URL_PATH);
if (!$path) {
return null;
}
// Ensure it's actually a product URL
if (strpos($path, '/p/') === false) {
return null;
}
$id = basename(rtrim($path, '/'));
return $id !== '' && $id !== 'p' ? $id : null;
}

View file

@ -111,7 +111,7 @@ class CanopyProvider implements InfoProviderInterface
return null;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$response = $this->httpClient->request('GET', self::SEARCH_API_URL, [
'query' => [
@ -177,15 +177,17 @@ class CanopyProvider implements InfoProviderInterface
return new PurchaseInfoDTO(self::DISTRIBUTOR_NAME, order_number: $asin, prices: $priceDtos, product_url: $this->productPageFromASIN($asin));
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
//Check that the id is a valid ASIN (10 characters, letters and numbers)
if (!preg_match('/^[A-Z0-9]{10}$/', $id)) {
throw new \InvalidArgumentException("The id must be a valid ASIN (10 characters, letters and numbers)");
}
$do_not_cache = ($options[self::OPTION_NO_CACHE] ?? false) || $this->settings->alwaysGetDetails;
//Use cached details if available and the settings allow it, to avoid unnecessary API requests, since the search results already contain most of the details
if(!$this->settings->alwaysGetDetails && ($cached = $this->getFromCache($id)) !== null) {
if(!$do_not_cache && ($cached = $this->getFromCache($id)) !== null) {
return $cached;
}

View file

@ -88,7 +88,7 @@ readonly class ConradProvider implements InfoProviderInterface, URLHandlerInfoPr
return null;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$url = $this->settings->shopID->getAPIRoot() . self::SEARCH_ENDPOINT . '/'
. $this->settings->shopID->getDomainEnd() . '/' . $this->settings->shopID->getLanguage()
@ -279,7 +279,7 @@ readonly class ConradProvider implements InfoProviderInterface, URLHandlerInfoPr
);
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$productInfoURL = $this->settings->shopID->getAPIRoot() . '/product/1/service/' . $this->settings->shopID->getShopID()
. '/product/' . $id;

View file

@ -106,7 +106,7 @@ class DigikeyProvider implements InfoProviderInterface
return $this->settings->clientId !== null && $this->settings->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$request = [
'Keywords' => $keyword,
@ -159,7 +159,7 @@ class DigikeyProvider implements InfoProviderInterface
return $result;
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
try {
$response = $this->digikeyClient->request('GET', '/products/v4/search/' . urlencode($id) . '/productdetails', [

View file

@ -282,12 +282,12 @@ class Element14Provider implements InfoProviderInterface, URLHandlerInfoProvider
};
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
return $this->queryByTerm('any:' . $keyword);
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$tmp = $this->queryByTerm('id:' . $id);
if (count($tmp) === 0) {

View file

@ -54,7 +54,7 @@ class EmptyProvider implements InfoProviderInterface
return true;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
return [
@ -69,7 +69,7 @@ class EmptyProvider implements InfoProviderInterface
];
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
throw new \RuntimeException('No part details available');
}

View file

@ -0,0 +1,58 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Services\InfoProviderSystem\Providers;
use App\Exceptions\ProviderIDNotSupportedException;
trait FixAndValidateUrlTrait
{
private function fixAndValidateURL(string $url): string
{
$originalUrl = $url;
//Add scheme if missing
if (!preg_match('/^https?:\/\//', $url)) {
//Remove any leading slashes
$url = ltrim($url, '/');
//If the URL starts with https:/ or http:/, add the missing slash
//Traefik removes the double slash as secruity measure, so we want to be forgiving and add it back if needed
//See https://github.com/Part-DB/Part-DB-server/issues/1296
if (preg_match('/^https?:\/[^\/]/', $url)) {
$url = preg_replace('/^(https?:)\/([^\/])/', '$1//$2', $url);
} else {
$url = 'https://'.$url;
}
}
//If this is not a valid URL with host, domain and path, throw an exception
if (filter_var($url, FILTER_VALIDATE_URL) === false ||
parse_url($url, PHP_URL_HOST) === null ||
parse_url($url, PHP_URL_PATH) === null) {
throw new ProviderIDNotSupportedException("The given ID is not a valid URL: ".$originalUrl);
}
return $url;
}
}

View file

@ -25,6 +25,7 @@ namespace App\Services\InfoProviderSystem\Providers;
use App\Exceptions\ProviderIDNotSupportedException;
use App\Helpers\RandomizeUseragentHttpClient;
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
@ -48,12 +49,14 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class GenericWebProvider implements InfoProviderInterface
{
use FixAndValidateUrlTrait;
public const DISTRIBUTOR_NAME = 'Website';
private readonly HttpClientInterface $httpClient;
public function __construct(HttpClientInterface $httpClient, private readonly GenericWebProviderSettings $settings,
private readonly ProviderRegistry $providerRegistry, private readonly PartInfoRetriever $infoRetriever,
private readonly CreateFromUrlHelper $createFromUrlHelper,
)
{
//Use NoPrivateNetworkHttpClient to prevent SSRF vulnerabilities, and RandomizeUseragentHttpClient to make it harder for servers to block us
@ -85,19 +88,23 @@ class GenericWebProvider implements InfoProviderInterface
return $this->settings->enabled;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$url = $this->fixAndValidateURL($keyword);
//Before loading the page, try to delegate to another provider
$delegatedPart = $this->delegateToOtherProvider($url);
if ($delegatedPart !== null) {
return [$delegatedPart];
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
//Before loading the page, try to delegate to another provider
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProvider($url, $this);
if ($delegatedPart !== null) {
return [$delegatedPart];
}
}
try {
$new_options = $options;
$new_options[self::OPTION_SKIP_DELEGATION] = true; //Skip delegation for the getDetails call to prevent infinite loops
return [
$this->getDetails($keyword, false) //We already tried delegation
$this->getDetails($keyword, $new_options)
]; } catch (ProviderIDNotSupportedException $e) {
return [];
}
@ -274,78 +281,16 @@ class GenericWebProvider implements InfoProviderInterface
return null;
}
/**
* Delegates the URL to another provider if possible, otherwise return null
* @param string $url
* @return SearchResultDTO|null
*/
private function delegateToOtherProvider(string $url): ?SearchResultDTO
{
//Extract domain from url:
$host = parse_url($url, PHP_URL_HOST);
if ($host === false || $host === null) {
return null;
}
$provider = $this->providerRegistry->getProviderHandlingDomain($host);
if ($provider !== null && $provider->isActive() && $provider->getProviderKey() !== $this->getProviderKey()) {
try {
$id = $provider->getIDFromURL($url);
if ($id !== null) {
$results = $this->infoRetriever->searchByKeyword($id, [$provider]);
if (count($results) > 0) {
return $results[0];
}
}
return null;
} catch (ProviderIDNotSupportedException $e) {
//Ignore and continue
return null;
}
}
return null;
}
private function fixAndValidateURL(string $url): string
{
$originalUrl = $url;
//Add scheme if missing
if (!preg_match('/^https?:\/\//', $url)) {
//Remove any leading slashes
$url = ltrim($url, '/');
//If the URL starts with https:/ or http:/, add the missing slash
//Traefik removes the double slash as secruity measure, so we want to be forgiving and add it back if needed
//See https://github.com/Part-DB/Part-DB-server/issues/1296
if (preg_match('/^https?:\/[^\/]/', $url)) {
$url = preg_replace('/^(https?:)\/([^\/])/', '$1//$2', $url);
} else {
$url = 'https://'.$url;
}
}
//If this is not a valid URL with host, domain and path, throw an exception
if (filter_var($url, FILTER_VALIDATE_URL) === false ||
parse_url($url, PHP_URL_HOST) === null ||
parse_url($url, PHP_URL_PATH) === null) {
throw new ProviderIDNotSupportedException("The given ID is not a valid URL: ".$originalUrl);
}
return $url;
}
public function getDetails(string $id, bool $check_for_delegation = true): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$url = $this->fixAndValidateURL($id);
if ($check_for_delegation) {
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
//Before loading the page, try to delegate to another provider
$delegatedPart = $this->delegateToOtherProvider($url);
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProviderDetails($url, $this);
if ($delegatedPart !== null) {
return $this->infoRetriever->getDetailsForSearchResult($delegatedPart);
return $delegatedPart;
}
}

View file

@ -28,6 +28,8 @@ use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
interface InfoProviderInterface
{
public const OPTION_NO_CACHE = 'no_cache'; // if set to true, the provider should not use any cache and retrieve fresh data from the source
public const OPTION_SKIP_DELEGATION = 'skip_delegation'; // if set to true, the provider should not delegate the request to other providers, even if it supports delegation.
/**
* Get information about this provider
@ -61,16 +63,18 @@ interface InfoProviderInterface
/**
* Searches for a keyword and returns a list of search results
* @param string $keyword The keyword to search for
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
* @return SearchResultDTO[] A list of search results
*/
public function searchByKeyword(string $keyword): array;
public function searchByKeyword(string $keyword, array $options = []): array;
/**
* Returns detailed information about the part with the given id
* @param string $id
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
* @return PartDetailDTO
*/
public function getDetails(string $id): PartDetailDTO;
public function getDetails(string $id, array $options = []): PartDetailDTO;
/**
* A list of capabilities this provider supports (which kind of data it can provide).

View file

@ -349,17 +349,18 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
return $result;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
return $this->queryByTerm($keyword, true); // Use lightweight mode for search
}
/**
* Batch search multiple keywords asynchronously (like JavaScript Promise.all)
* @param array $keywords Array of keywords to search
* @param array $keywords
* @param array $options
* @return array Results indexed by keyword
*/
public function searchByKeywordsBatch(array $keywords): array
public function searchByKeywordsBatch(array $keywords, array $options = []): array
{
if (empty($keywords)) {
return [];
@ -428,7 +429,7 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
return $result;
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$tmp = $this->queryByTerm($id, false);
if (count($tmp) === 0) {

View file

@ -76,7 +76,7 @@ class MouserProvider implements InfoProviderInterface
return $this->settings->apiKey !== '' && $this->settings->apiKey !== null;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
/*
SearchByKeywordRequest description:
@ -144,7 +144,7 @@ class MouserProvider implements InfoProviderInterface
return $this->responseToDTOArray($response);
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
/*
SearchByPartRequest description:

View file

@ -278,12 +278,13 @@ class OEMSecretsProvider implements InfoProviderInterface
* and debugging with local JSON files. The results are processed, cached, and then sorted based
* on the keyword and specified criteria.
*
* @param string $keyword The part number to search for
* @param string $keyword
* @param array $options
* @return array An array of processed product details, sorted by relevance and additional criteria.
*
* @throws \Exception If the JSON file used for debugging is not found or contains errors.
*/
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
/*
oemsecrets Part Search API 3.0.1
@ -414,14 +415,20 @@ class OEMSecretsProvider implements InfoProviderInterface
* found in the cache, they are returned. If not, an exception is thrown indicating that
* the details could not be found.
*
* @param string $id The unique identifier of the provider or part.
* @param string $id
* @param array $options
* @return PartDetailDTO The detailed information about the part.
*
* @throws \Exception If no details are found for the given provider ID.
*/
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$cacheKey = $this->getCacheKey($id);
if ($options[self::OPTION_NO_CACHE] ?? false) {
$this->partInfoCache->deleteItem($cacheKey);
}
$cacheItem = $this->partInfoCache->getItem($cacheKey);
if ($cacheItem->isHit()) {

View file

@ -326,7 +326,7 @@ class OctopartProvider implements InfoProviderInterface
);
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$graphQL = sprintf(<<<'GRAPHQL'
query partSearch($keyword: String, $limit: Int, $currency: String!, $country: String!, $authorizedOnly: Boolean!) {
@ -367,11 +367,13 @@ class OctopartProvider implements InfoProviderInterface
return $tmp;
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$no_cache = $options[self::OPTION_NO_CACHE] ?? false;
//Check if we have the part cached
$cached = $this->getFromCache($id);
if ($cached !== null) {
if (!$no_cache && $cached !== null) {
return $cached;
}

View file

@ -66,7 +66,7 @@ class PollinProvider implements InfoProviderInterface, URLHandlerInfoProviderInt
return $this->settings->enabled;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$response = $this->client->request('GET', 'https://www.pollin.de/search', [
'query' => [
@ -110,7 +110,7 @@ class PollinProvider implements InfoProviderInterface, URLHandlerInfoProviderInt
};
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
//Ensure that $id is numeric
if (!is_numeric($id)) {

View file

@ -46,6 +46,9 @@ enum ProviderCapabilities
/** Provider can provide GTIN for a part */
case GTIN;
/** Provider can provide parameters/specifications for a part */
case PARAMETERS;
/**
* Get the order index for displaying capabilities in a stable order.
* @return int
@ -59,6 +62,7 @@ enum ProviderCapabilities
self::PRICE => 4,
self::FOOTPRINT => 5,
self::GTIN => 6,
self::PARAMETERS => 7,
};
}
@ -71,6 +75,7 @@ enum ProviderCapabilities
self::DATASHEET => 'datasheet',
self::PRICE => 'price',
self::GTIN => 'gtin',
self::PARAMETERS => 'parameters',
};
}
@ -83,6 +88,7 @@ enum ProviderCapabilities
self::DATASHEET => 'fa-file-alt',
self::PRICE => 'fa-money-bill-wave',
self::GTIN => 'fa-barcode',
self::PARAMETERS => 'fa-list-ul',
};
}
}

View file

@ -69,7 +69,7 @@ class ReicheltProvider implements InfoProviderInterface
return $this->settings->enabled;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$response = $this->client->request('GET', sprintf($this->getBaseURL() . '/shop/search/%s', $keyword));
$html = $response->getContent();
@ -108,7 +108,7 @@ class ReicheltProvider implements InfoProviderInterface
return $results;
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
//Check that the ID is a number
if (!is_numeric($id)) {

View file

@ -69,7 +69,7 @@ class TMEProvider implements InfoProviderInterface, URLHandlerInfoProviderInterf
return $this->tmeClient->isUsable();
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
$response = $this->tmeClient->makeRequest('Products/Search', [
'Country' => $this->settings->country,
@ -99,7 +99,7 @@ class TMEProvider implements InfoProviderInterface, URLHandlerInfoProviderInterf
return $result;
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
$response = $this->tmeClient->makeRequest('Products/GetProducts', [
'Country' => $this->settings->country,

View file

@ -55,7 +55,7 @@ class TestProvider implements InfoProviderInterface
return true;
}
public function searchByKeyword(string $keyword): array
public function searchByKeyword(string $keyword, array $options = []): array
{
return [
new SearchResultDTO(provider_key: $this->getProviderKey(), provider_id: 'element1', name: 'Element 1', description: 'fd'),
@ -72,7 +72,7 @@ class TestProvider implements InfoProviderInterface
];
}
public function getDetails(string $id): PartDetailDTO
public function getDetails(string $id, array $options = []): PartDetailDTO
{
return new PartDetailDTO(
provider_key: $this->getProviderKey(),
@ -92,4 +92,4 @@ class TestProvider implements InfoProviderInterface
]
);
}
}
}

View file

@ -105,6 +105,6 @@ class UpdateAvailableFacade
return $this->updateCache->get(self::CACHE_KEY, function (ItemInterface $item) {
$item->expiresAfter(self::CACHE_TTL);
return $this->updateChecker->getLatestVersion();
});
}) ?? ['version' => '0.0.1', 'url' => 'update-checking-failed'];
}
}

View file

@ -0,0 +1,43 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\AISettings;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Settings\EmbeddedSettings;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings(label: new TM("settings.ai"))]
#[SettingsIcon("fa-brain")]
class AISettings
{
use SettingsTrait;
#[EmbeddedSettings]
public ?OpenRouterSettings $openRouter = null;
#[EmbeddedSettings]
public ?LMStudioSettings $lmstudio = null;
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\AISettings;
use App\Form\Type\APIKeyType;
use App\Services\AI\AIPlatformSettingsInterface;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Translation\StaticMessage;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings(name: 'ai_lmstudio', label: new TM("settings.ai.lmstudio"))]
#[SettingsIcon("fa-robot")]
class LMStudioSettings implements AIPlatformSettingsInterface
{
use SettingsTrait;
#[SettingsParameter(label: new TM("settings.ai.lmstudio.hosturl"),
formType: UrlType::class,
formOptions: ["attr" => ["placeholder" => new StaticMessage("http://localhost:1234")]],
envVar: "AI_LMSTUDIO_HOSTURL", envVarMode: EnvVarMode::OVERWRITE)]
public ?string $hostURL = null;
public function isAIPlatformEnabled(): bool
{
return $this->hostURL !== null && $this->hostURL !== "";
}
}

View file

@ -0,0 +1,50 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\AISettings;
use App\Form\Type\APIKeyType;
use App\Services\AI\AIPlatformSettingsInterface;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings(name: 'ai_openrouter', label: new TM("settings.ai.openrouter"), description: "settings.ai.openrouter.help")]
#[SettingsIcon("fa-robot")]
class OpenRouterSettings implements AIPlatformSettingsInterface
{
use SettingsTrait;
#[SettingsParameter(label: new TM("settings.ips.element14.apiKey"),
formType: APIKeyType::class,
formOptions: ["help_html" => true], envVar: "AI_OPENROUTER_KEY", envVarMode: EnvVarMode::OVERWRITE)]
public ?string $apiKey = null;
public function isAIPlatformEnabled(): bool
{
return $this->apiKey !== null && $this->apiKey !== "";
}
}

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Settings;
use App\Settings\AISettings\AISettings;
use App\Settings\BehaviorSettings\BehaviorSettings;
use App\Settings\InfoProviderSystem\InfoProviderSettings;
use App\Settings\MiscSettings\MiscSettings;
@ -50,6 +51,9 @@ class AppSettings
#[EmbeddedSettings]
public ?SynonymSettings $synonyms = null;
#[EmbeddedSettings]
public ?AISettings $ai = null;
#[EmbeddedSettings()]
public ?MiscSettings $miscSettings = null;

View file

@ -0,0 +1,73 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\InfoProviderSystem;
use App\Form\Settings\AiModelsType;
use App\Form\Settings\AiPlatformChoiceType;
use App\Services\AI\AIPlatforms;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\AI\Platform\Capability;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Translation\TranslatableMessage as TM;
use Symfony\Component\Validator\Constraints\Language;
#[Settings(name: "ai_extractor", label: new TM("settings.ips.ai_extractor"), description: new TM("settings.ips.ai_extractor.description"))]
#[SettingsIcon("fa-plug")]
class AIExtractorSettings
{
private const MODEL_SELECTOR_LABEL = 'ai_extractor';
use SettingsTrait;
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.ai_platform"),
formType: AiPlatformChoiceType::class, formOptions: ['platform_selector_label' => self::MODEL_SELECTOR_LABEL],
)]
public ?AIPlatforms $platform = null;
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.model"), description: new TM("settings.ips.ai_extractor.model.help"),
formType: AiModelsType::class, formOptions: ['platform_selector' => self::MODEL_SELECTOR_LABEL, 'filter_capability' => Capability::OUTPUT_STRUCTURED],
)]
public ?string $model = null;
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.max_content_length"),
description: new TM("settings.ips.ai_extractor.max_content_length.description"),
)]
public int $maxContentLength = 50000;
#[Language]
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.output_language"), description: new TM("settings.ips.ai_extractor.output_language.description"),
formType: LanguageType::class,
)]
public ?string $outputLanguage = null;
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.additional_instructions"), description: new TM("settings.ips.ai_extractor.additional_instructions.description"),
formType: TextareaType::class,
)]
public ?string $additionalInstructions = null;
}

View file

@ -72,7 +72,7 @@ class CanopySettings
/**
* @var string The domain used internally for the API requests. This is not necessarily the same as the domain shown to the user, which is determined by the keys of the ALLOWED_DOMAINS constant
*/
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: ChoiceType::class, formOptions: ["choices" => self::ALLOWED_DOMAINS])]
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: ChoiceType::class, formOptions: ["choices" => self::ALLOWED_DOMAINS, 'translation_domain' => false])]
public string $domain = "DE";
/**

View file

@ -40,6 +40,9 @@ class InfoProviderSettings
#[EmbeddedSettings]
public ?GenericWebProviderSettings $genericWebProvider = null;
#[EmbeddedSettings]
public ?AIExtractorSettings $aiExtractor = null;
#[EmbeddedSettings]
public ?DigikeySettings $digikey = null;
@ -75,4 +78,5 @@ class InfoProviderSettings
#[EmbeddedSettings]
public ?CanopySettings $canopy = null;
}

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Twig;
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
use Twig\Attribute\AsTwigFunction;
use App\Settings\SettingsIcon;
use Symfony\Component\HttpFoundation\Request;
@ -34,7 +35,7 @@ use Twig\Extension\AbstractExtension;
final readonly class MiscExtension
{
public function __construct(private EventCommentNeededHelper $eventCommentNeededHelper)
public function __construct(private EventCommentNeededHelper $eventCommentNeededHelper, private CreateFromUrlHelper $fromUrlHelper)
{
}
@ -84,4 +85,14 @@ final readonly class MiscExtension
return $request->getBaseUrl().$request->getPathInfo().$qs;
}
/**
* Returns true if the from url provider is active, false otherwise.
* @return bool
*/
#[AsTwigFunction(name: 'create_from_url_active')]
public function create_from_url_active(): bool
{
return $this->fromUrlHelper->canCreateFromUrl();
}
}

View file

@ -375,6 +375,54 @@
"shivas/versioning-bundle": {
"version": "4.0.3"
},
"symfony/ai-bundle": {
"version": "0.8",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "0.1",
"ref": "2be6ccd77335c2631fdf12d1680649b072efb8ad"
},
"files": [
"config/packages/ai.yaml"
]
},
"symfony/ai-generic-platform": {
"version": "0.8",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "0.1",
"ref": "f38913b87380322d4c40c302b41626e811516bc4"
},
"files": [
"config/packages/ai_generic_platform.yaml"
]
},
"symfony/ai-lm-studio-platform": {
"version": "0.8",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "0.1",
"ref": "e35cced28f6559fc5effccb8f22597f309fedfdf"
},
"files": [
"config/packages/ai_lm_studio_platform.yaml"
]
},
"symfony/ai-open-router-platform": {
"version": "0.8",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "0.1",
"ref": "c39a146c6ec3df8b874accf6ce1cccbda431a688"
},
"files": [
"config/packages/ai_open_router_platform.yaml"
]
},
"symfony/apache-pack": {
"version": "1.0",
"recipe": {
@ -393,12 +441,6 @@
"symfony/browser-kit": {
"version": "v4.2.3"
},
"symfony/cache": {
"version": "v4.2.3"
},
"symfony/cache-contracts": {
"version": "v1.1.5"
},
"symfony/config": {
"version": "v4.2.3"
},

View file

@ -52,7 +52,7 @@
{% trans %}info_providers.search.title{% endtrans %}
</a>
</li>
{% if settings_instance('generic_web_provider').enabled %}
{% if create_from_url_active() %}
<li>
<a class="dropdown-item" href="{{ path('info_providers_from_url') }}">
<i class="fa-fw fa-solid fa-book-atlas"></i>

View file

@ -16,6 +16,22 @@
{{ form_start(form) }}
{{ form_row(form.url) }}
{{ form_row(form.method) }}
<div class="row mb-2">
<div class="{{ col_input }} {{ offset_label }}">
<a data-bs-toggle="collapse" href="#infoSearchAdvancedPanel">{% trans %}info_providers.search.advanced_options{% endtrans %}</a>
</div>
</div>
<div class="collapse" id="infoSearchAdvancedPanel">
<div class="card card-body mb-2">
{{ form_row(form.no_cache) }}
{{ form_row(form.skip_delegation) }}
</div>
</div>
{{ form_row(form.submit) }}
{{ form_end(form) }}
{% endblock %}

View file

@ -33,6 +33,19 @@
</div>
</div>
<div class="row mb-2">
<div class="{{ col_input }} {{ offset_label }}">
<a data-bs-toggle="collapse" href="#infoSearchAdvancedPanel">{% trans %}info_providers.search.advanced_options{% endtrans %}</a>
</div>
</div>
<div class="collapse" id="infoSearchAdvancedPanel">
<div class="card card-body mb-2">
{{ form_row(form.no_cache_search) }}
{{ form_row(form.no_cache_details) }}
</div>
</div>
{{ form_row(form.submit) }}
{{ form_end(form) }}
@ -116,16 +129,16 @@
{% if update_target %} {# We update an existing part #}
{% set href = path('info_providers_update_part',
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD}) %}
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD, 'no_cache': no_cache_details ? 1 : null}) %}
{% else %} {# Create a fresh part #}
{% set href = path('info_providers_create_part',
{'providerKey': dto.provider_key, 'providerId': dto.provider_id}) %}
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null}) %}
{% endif %}
{# If we have no local part, then we can just show the create button #}
{% if localPart is null %}
<a class="btn btn-primary" href="{{ href }}"
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
<i class="fa-solid fa-plus-square"></i>
</a>
{% else %} {# Otherwise add a button group with all three buttons #}
@ -139,7 +152,7 @@
target="_blank" title="{% trans %}info_providers.search.show_existing_part{% endtrans %}">
<i class="fa-solid fa-search"></i>
</a>
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id}) }}"
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null }) }}"
target="_blank" title="{% trans %}info_providers.search.update_existing_part{% endtrans %}">
<i class="fa-solid fa-arrows-rotate"></i>
</a>

View file

@ -0,0 +1,99 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Tests for App\Services\AI\AIPlatformRegistry
*/
declare(strict_types=1);
namespace App\Tests\Services\AI;
use App\Services\AI\AIPlatformRegistry;
use App\Services\AI\AIPlatforms;
use App\Services\AI\AIPlatformSettingsInterface;
use Jbtronics\SettingsBundle\Manager\SettingsManagerInterface;
use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\PlatformInterface;
class AIPlatformRegistryTest extends TestCase
{
public function testRegistersEnabledPlatformsAndReturnsPlatform(): void
{
// Create a platform mock and expose it under the service tag name (openrouter)
$platformMock = $this->createMock(PlatformInterface::class);
// Settings for OpenRouter -> enabled
$openRouterSettings = $this->createMock(AIPlatformSettingsInterface::class);
$openRouterSettings->method('isAIPlatformEnabled')->willReturn(true);
// Settings for LMStudio -> disabled
$lmSettings = $this->createMock(AIPlatformSettingsInterface::class);
$lmSettings->method('isAIPlatformEnabled')->willReturn(false);
// Settings manager should return the corresponding settings object depending on the requested class name
$settingsManager = $this->createMock(SettingsManagerInterface::class);
$settingsManager->method('get')->willReturnMap([
[AIPlatforms::OPENROUTER->toSettingsClass(), $openRouterSettings],
[AIPlatforms::LMSTUDIO->toSettingsClass(), $lmSettings],
]);
$platforms = new \ArrayIterator([
AIPlatforms::OPENROUTER->toServiceTagName() => $platformMock,
]);
$registry = new AIPlatformRegistry($settingsManager, $platforms);
// OPENROUTER should be enabled and retrievable
$this->assertTrue($registry->isEnabled(AIPlatforms::OPENROUTER));
$this->assertSame($platformMock, $registry->getPlatform(AIPlatforms::OPENROUTER));
// LMSTUDIO is either not registered or disabled -> should not be enabled
$this->assertFalse($registry->isEnabled(AIPlatforms::LMSTUDIO));
$this->expectException(\InvalidArgumentException::class);
$registry->getPlatform(AIPlatforms::LMSTUDIO);
}
public function testGetEnabledPlatformsReturnsIndexedArray(): void
{
$platformMock = $this->createMock(PlatformInterface::class);
$openRouterSettings = $this->createMock(AIPlatformSettingsInterface::class);
$openRouterSettings->method('isAIPlatformEnabled')->willReturn(true);
$settingsManager = $this->createMock(SettingsManagerInterface::class);
$settingsManager->method('get')->willReturnMap([
[AIPlatforms::OPENROUTER->toSettingsClass(), $openRouterSettings],
[AIPlatforms::LMSTUDIO->toSettingsClass(), $this->createMock(AIPlatformSettingsInterface::class)],
]);
$platforms = new \ArrayIterator([
AIPlatforms::OPENROUTER->toServiceTagName() => $platformMock,
// lmstudio not registered
]);
$registry = new AIPlatformRegistry($settingsManager, $platforms);
$enabled = $registry->getEnabledPlatforms();
$this->assertArrayHasKey(AIPlatforms::OPENROUTER->value, $enabled);
$this->assertSame($platformMock, $enabled[AIPlatforms::OPENROUTER->value]);
}
}

View file

@ -2780,7 +2780,7 @@ If you have done this incorrectly or if a computer is no longer trusted, you can
<target>Name</target>
</segment>
</unit>
<unit id="sIvAlUe" name="part.table.si_value">
<unit id="A1bHPnR" name="part.table.si_value">
<segment state="translated">
<source>part.table.si_value</source>
<target>SI Value</target>
@ -7218,13 +7218,13 @@ Element 1 -&gt; Element 1.2</target>
<target>Subprojects</target>
</segment>
</unit>
<unit id="prjTtlBP" name="project.info.total_build_price">
<unit id="_NstC62" name="project.info.total_build_price">
<segment state="translated">
<source>project.info.total_build_price</source>
<target>Total build price</target>
</segment>
</unit>
<unit id="prjUntBP" name="project.info.per_unit_price">
<unit id="Oof1G0D" name="project.info.per_unit_price">
<segment state="translated">
<source>project.info.per_unit_price</source>
<target>per unit</target>
@ -7254,7 +7254,7 @@ Element 1 -&gt; Element 1.2</target>
<target>Price</target>
</segment>
</unit>
<unit id="bomExPrc" name="project.bom.ext_price">
<unit id="gLWQ4cF" name="project.bom.ext_price">
<segment state="translated">
<source>project.bom.ext_price</source>
<target>Extended Price</target>
@ -10053,85 +10053,85 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>When enabled, the datasheet field in KiCad will link to the actual PDF file (if found). When disabled, it will link to the Part-DB page instead. The Part-DB page link is always available as a separate "Part-DB URL" field.</target>
</segment>
</unit>
<unit id="e2e7mR1" name="settings.misc.kicad_eda.editor.title">
<unit id="h2ChJ6Y" name="settings.misc.kicad_eda.editor.title">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.title</source>
<target>KiCad autocomplete lists</target>
</segment>
</unit>
<unit id="qjv1VVx" name="settings.misc.kicad_eda.editor.link">
<unit id="C97hNXL" name="settings.misc.kicad_eda.editor.link">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.link</source>
<target>Autocomplete settings</target>
</segment>
</unit>
<unit id="f0qkcqg" name="settings.misc.kicad_eda.editor.description">
<unit id="pJeX5wZ" name="settings.misc.kicad_eda.editor.description">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.description</source>
<target>Configure whether KiCad autocomplete uses the autogenerated default lists or your custom override files. The custom files are editable here, while the default files are shown read-only for reference.</target>
</segment>
</unit>
<unit id="AS3yDlb" name="settings.misc.kicad_eda.editor.footprints">
<unit id="mumlQUV" name="settings.misc.kicad_eda.editor.footprints">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.footprints</source>
<target>Footprints list</target>
</segment>
</unit>
<unit id="Jj_YR7n" name="settings.misc.kicad_eda.editor.footprints.help">
<unit id="6VCC6T8" name="settings.misc.kicad_eda.editor.footprints.help">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.footprints.help</source>
<target>One entry per line. Used as autocomplete suggestions for KiCad footprint fields.</target>
</segment>
</unit>
<unit id="ELd3KQK" name="settings.misc.kicad_eda.editor.symbols">
<unit id="3EPsJaG" name="settings.misc.kicad_eda.editor.symbols">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.symbols</source>
<target>Symbols list</target>
</segment>
</unit>
<unit id="A9TOJgM" name="settings.misc.kicad_eda.editor.symbols.help">
<unit id="8JyqD1f" name="settings.misc.kicad_eda.editor.symbols.help">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.symbols.help</source>
<target>One entry per line. Used as autocomplete suggestions for KiCad symbol fields.</target>
</segment>
</unit>
<unit id="tWYlL0u" name="settings.misc.kicad_eda.use_custom_list">
<unit id="Ops1y13" name="settings.misc.kicad_eda.use_custom_list">
<segment state="translated">
<source>settings.misc.kicad_eda.use_custom_list</source>
<target>Use custom autocomplete lists</target>
</segment>
</unit>
<unit id="v0LK7n6" name="settings.misc.kicad_eda.use_custom_list.help">
<unit id="AjQJzDB" name="settings.misc.kicad_eda.use_custom_list.help">
<segment state="translated">
<source>settings.misc.kicad_eda.use_custom_list.help</source>
<target>When enabled, KiCad autocomplete uses public/kicad/footprints_custom.txt and public/kicad/symbols_custom.txt instead of the autogenerated default files.</target>
</segment>
</unit>
<unit id="Yl_fqfV" name="settings.misc.kicad_eda.editor.custom_footprints">
<unit id="TfJvNLm" name="settings.misc.kicad_eda.editor.custom_footprints">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.custom_footprints</source>
<target>Custom footprints list</target>
</segment>
</unit>
<unit id="GuD2JcQ" name="settings.misc.kicad_eda.editor.custom_symbols">
<unit id="6nsnYiB" name="settings.misc.kicad_eda.editor.custom_symbols">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.custom_symbols</source>
<target>Custom symbols list</target>
</segment>
</unit>
<unit id="k6m9b5F" name="settings.misc.kicad_eda.editor.default_footprints">
<unit id="bABze6_" name="settings.misc.kicad_eda.editor.default_footprints">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.default_footprints</source>
<target>Default footprints list</target>
</segment>
</unit>
<unit id="bKkF8mM" name="settings.misc.kicad_eda.editor.default_symbols">
<unit id="3Ycxg5M" name="settings.misc.kicad_eda.editor.default_symbols">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.default_symbols</source>
<target>Default symbols list</target>
</segment>
</unit>
<unit id="mIj_i4E" name="settings.misc.kicad_eda.editor.default_files_help">
<unit id="ADK3.8x" name="settings.misc.kicad_eda.editor.default_files_help">
<segment state="translated">
<source>settings.misc.kicad_eda.editor.default_files_help</source>
<target>Autogenerated file shown for reference only. Changes must be made in the custom list.</target>
@ -13067,5 +13067,149 @@ Buerklin-API Authentication server:
<target>Mapping error: Check if you have selected the right delimiter!</target>
</segment>
</unit>
<unit id="zl1XJq0" name="settings.ai">
<segment>
<source>settings.ai</source>
<target>AI</target>
</segment>
</unit>
<unit id="NqxqdyX" name="settings.ai.openrouter">
<segment>
<source>settings.ai.openrouter</source>
<target>OpenRouter</target>
</segment>
</unit>
<unit id="tWtvoDT" name="settings.ai.lmstudio">
<segment>
<source>settings.ai.lmstudio</source>
<target>LMStudio</target>
</segment>
</unit>
<unit id="foBzBG2" name="settings.ips.ai_extractor.model">
<segment>
<source>settings.ips.ai_extractor.model</source>
<target>AI Model</target>
</segment>
</unit>
<unit id="PbXBTZO" name="settings.ips.ai_extractor.ai_platform">
<segment>
<source>settings.ips.ai_extractor.ai_platform</source>
<target>AI Platform</target>
</segment>
</unit>
<unit id="axA7_TL" name="settings.ips.ai_extractor.model.help">
<segment>
<source>settings.ips.ai_extractor.model.help</source>
<target>The AI model that should be used for extraction. Must support structured output.</target>
</segment>
</unit>
<unit id="H1SYgGs" name="settings.ips.ai_extractor.max_content_length">
<segment>
<source>settings.ips.ai_extractor.max_content_length</source>
<target>Max. Website Content length</target>
</segment>
</unit>
<unit id="SZWiZE3" name="settings.ips.ai_extractor.max_content_length.description">
<segment>
<source>settings.ips.ai_extractor.max_content_length.description</source>
<target>The maximum number of characters of the website that are sent to the AI service.</target>
</segment>
</unit>
<unit id="pCsAHOv" name="settings.ips.ai_extractor.output_language">
<segment>
<source>settings.ips.ai_extractor.output_language</source>
<target>Output language</target>
</segment>
</unit>
<unit id="NVHHgpD" name="settings.ips.ai_extractor.output_language.description">
<segment>
<source>settings.ips.ai_extractor.output_language.description</source>
<target>By default, the providers returns information in the same language as the website. With that option you can ask the AI to translate it for you. Might only work with certain models.</target>
</segment>
</unit>
<unit id="CAeeZlL" name="settings.ips.ai_extractor.additional_instructions">
<segment>
<source>settings.ips.ai_extractor.additional_instructions</source>
<target>Additional instructions</target>
</segment>
</unit>
<unit id=".UaUMk1" name="settings.ips.ai_extractor.additional_instructions.description">
<segment>
<source>settings.ips.ai_extractor.additional_instructions.description</source>
<target>The additional instructions will be appended to the system prompt.</target>
</segment>
</unit>
<unit id="Ycfssj2" name="info_providers.search.advanced_options">
<segment>
<source>info_providers.search.advanced_options</source>
<target>Advanced options</target>
</segment>
</unit>
<unit id="xfxZrXn" name="info_providers.no_cache_search">
<segment>
<source>info_providers.no_cache_search</source>
<target>Do not cache search results / Force fresh search</target>
</segment>
</unit>
<unit id="b_oc3T1" name="info_providers.no_cache_details">
<segment>
<source>info_providers.no_cache_details</source>
<target>Do not cache result details / Force fresh part detail retrieval</target>
</segment>
</unit>
<unit id="Ja8CCDb" name="info_providers.from_url.method.generic_web">
<segment>
<source>info_providers.from_url.method.generic_web</source>
<target>Classic Web Scraper</target>
</segment>
</unit>
<unit id="s0kUzFW" name="info_providers.from_url.method.ai_web">
<segment>
<source>info_providers.from_url.method.ai_web</source>
<target>AI Web Scraper</target>
</segment>
</unit>
<unit id="HEFB1OC" name="info_providers.from_url.method">
<segment>
<source>info_providers.from_url.method</source>
<target>Method</target>
</segment>
</unit>
<unit id="9pG0VtU" name="info_providers.from_url.no_cache">
<segment>
<source>info_providers.from_url.no_cache</source>
<target>Ignore cache / Force fresh info retrieval</target>
</segment>
</unit>
<unit id="302Jgvm" name="info_providers.from_url.skip_delegation">
<segment>
<source>info_providers.from_url.skip_delegation</source>
<target>Do not delegate to specialized info providers</target>
</segment>
</unit>
<unit id="pruvlK8" name="settings.ips.ai_extractor">
<segment>
<source>settings.ips.ai_extractor</source>
<target>AI Web Extractor</target>
</segment>
</unit>
<unit id="wILs7pS" name="settings.ips.ai_extractor.description">
<segment>
<source>settings.ips.ai_extractor.description</source>
<target>This info provider uses an large language model (LLM) to extract detailed part information from arbitary shop URLs.</target>
</segment>
</unit>
<unit id="1ShZ.1i" name="settings.ai.openrouter.help">
<segment>
<source>settings.ai.openrouter.help</source>
<target>Access to many AI models via openrouter.ai</target>
</segment>
</unit>
<unit id="kRcgIf0" name="settings.ai.lmstudio.hosturl">
<segment>
<source>settings.ai.lmstudio.hosturl</source>
<target>Host URL</target>
</segment>
</unit>
</file>
</xliff>