Improved parameter extraction & extraction of other infos

This commit is contained in:
Jan Böhmer 2026-04-26 23:15:29 +02:00
parent 0ca5a41298
commit ad096aa6ff
2 changed files with 20 additions and 13 deletions

View file

@ -63,13 +63,19 @@ final class DTOJsonSchemaConverter
'type' => 'object', 'type' => 'object',
'properties' => [ 'properties' => [
'name' => ['type' => 'string'], 'name' => ['type' => 'string'],
'value' => ['type' => 'string'], 'symbol' => ['type' => ['string', 'null'], 'description' => 'An optional quantity symbol for the parameter in latex code, like R_1'],
'unit' => ['type' => ['string', 'null']], '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'], 'required' => ['name', 'value_typical', 'value_min', 'value_max', 'value_text']
], ],
], ],
'datasheets' => [ 'datasheets' => [
'description' => 'A list of datasheets, manuals, or other technical documents related to the product. Not images, but actual documents, preferably PDFs.',
'type' => 'array', 'type' => 'array',
'items' => [ 'items' => [
'type' => 'object', 'type' => 'object',
@ -145,13 +151,15 @@ final class DTOJsonSchemaConverter
$parameters = []; $parameters = [];
foreach ($data['parameters'] as $p) { foreach ($data['parameters'] as $p) {
if (!empty($p['name'])) { if (!empty($p['name'])) {
$value = $p['value'] ?? ''; $parameters[] = new ParameterDTO(
$unit = $p['unit'] ?? null;
// Combine value and unit for parsing
$valueWithUnit = $unit ? $value . ' ' . $unit : $value;
$parameters[] = ParameterDTO::parseValueField(
name: $p['name'], name: $p['name'],
value: $valueWithUnit 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,
); );
} }
} }

View file

@ -217,13 +217,12 @@ Focus on the main content of the page, such as product descriptions, specificati
Rules: Rules:
- manufacturing_status: Use "active", "obsolete", "nrfnd" (not recommended for new designs), "discontinued", or null - manufacturing_status: Use "active", "obsolete", "nrfnd" (not recommended for new designs), "discontinued", or null
- parameters: Extract technical specs like voltage, current, temperature, etc. - 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 - prices: Extract pricing tiers with minimum_quantity, price, and currency code
- URLs must be absolute (include https://...) - URLs must be absolute (include https://...)
- If information is not found, use null - If information is not found, use null
- Return ONLY the JSON, no explanation text - 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.
For parameters, combine name, value, and unit. The unit should be separate if possible.
PROMPT; PROMPT;
if ($this->settings->outputLanguage === null) { if ($this->settings->outputLanguage === null) {