v1.0.9: extractor.cfm — lowercase JSON keys + fix JSON parsing
This commit is contained in:
+30
-12
@@ -79,10 +79,10 @@
|
|||||||
<!--- Вызов LLM --->
|
<!--- Вызов LLM --->
|
||||||
<cfset apiKey = "sk-ucI5YvOticoOQ9Kuj5K9mQ">
|
<cfset apiKey = "sk-ucI5YvOticoOQ9Kuj5K9mQ">
|
||||||
<cfset llmPayload = {
|
<cfset llmPayload = {
|
||||||
model: "gpt-oss-120b",
|
"model": "gpt-oss-120b",
|
||||||
messages: [{role: "user", content: prompt}],
|
"messages": [{"role": "user", "content": prompt}],
|
||||||
max_tokens: 8000,
|
"max_tokens": 8000,
|
||||||
temperature: 0.1
|
"temperature": 0.1
|
||||||
}>
|
}>
|
||||||
|
|
||||||
<cfhttp url="https://api.aillm.ru/v1/chat/completions" method="POST" timeout="120">
|
<cfhttp url="https://api.aillm.ru/v1/chat/completions" method="POST" timeout="120">
|
||||||
@@ -97,8 +97,19 @@
|
|||||||
|
|
||||||
<!--- Вытаскиваем JSON из ответа --->
|
<!--- Вытаскиваем JSON из ответа --->
|
||||||
<cfset jsonText = llmText>
|
<cfset jsonText = llmText>
|
||||||
<cfif find("```json", jsonText)>
|
<cfset p1 = find("```json", jsonText)>
|
||||||
<cfset jsonText = listLast(listFirst(jsonText, "```"), "```json")>
|
<cfif p1 GT 0>
|
||||||
|
<cfset jsonText = mid(jsonText, p1 + 7, len(jsonText))>
|
||||||
|
<cfset p2 = find("```", jsonText)>
|
||||||
|
<cfif p2 GT 0>
|
||||||
|
<cfset jsonText = left(jsonText, p2 - 1)>
|
||||||
|
</cfif>
|
||||||
|
<cfelse>
|
||||||
|
<cfset p1 = find("{", jsonText)>
|
||||||
|
<cfset p2 = find("}", reverse(jsonText))>
|
||||||
|
<cfif p1 GT 0 AND p2 GT 0>
|
||||||
|
<cfset jsonText = mid(jsonText, p1, len(jsonText) - p2 - p1 + 2)>
|
||||||
|
</cfif>
|
||||||
</cfif>
|
</cfif>
|
||||||
<cfset jsonText = trim(jsonText)>
|
<cfset jsonText = trim(jsonText)>
|
||||||
|
|
||||||
@@ -117,16 +128,23 @@
|
|||||||
<cfset savedRows = []>
|
<cfset savedRows = []>
|
||||||
<cfloop array="#rows#" index="row">
|
<cfloop array="#rows#" index="row">
|
||||||
<cftry>
|
<cftry>
|
||||||
|
<cfset rn = structKeyExists(row, 'row_num') ? row.row_num : 0>
|
||||||
|
<cfset nm = structKeyExists(row, 'name') ? row.name : ''>
|
||||||
|
<cfset pr = (structKeyExists(row, 'price') AND len(row.price)) ? row.price : ''>
|
||||||
|
<cfset qt = (structKeyExists(row, 'qty') AND len(row.qty)) ? row.qty : ''>
|
||||||
|
<cfset sm = (structKeyExists(row, 'sum') AND len(row.sum)) ? row.sum : ''>
|
||||||
|
<cfset ds = (structKeyExists(row, 'date_start') AND len(row.date_start)) ? row.date_start : ''>
|
||||||
|
|
||||||
<cfquery datasource="baza">
|
<cfquery datasource="baza">
|
||||||
INSERT INTO spec_rows (supplement_id, row_num, name, price, qty, sum, date_start)
|
INSERT INTO spec_rows (supplement_id, row_num, name, price, qty, sum, date_start)
|
||||||
VALUES (
|
VALUES (
|
||||||
<cfqueryparam value="#sup.id#" cfsqltype="cf_sql_varchar">,
|
<cfqueryparam value="#sup.id#" cfsqltype="cf_sql_varchar">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'row_num') ? row.row_num : 0#" cfsqltype="cf_sql_integer">,
|
<cfqueryparam value="#rn#" cfsqltype="cf_sql_integer">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'name') ? row.name : ''#" cfsqltype="cf_sql_varchar">,
|
<cfqueryparam value="#nm#" cfsqltype="cf_sql_varchar">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'price') AND NOT isNull(row.price) ? row.price : ''#" cfsqltype="cf_sql_float" null="#NOT structKeyExists(row, 'price') OR isNull(row.price)#">,
|
<cfqueryparam value="#pr#" cfsqltype="cf_sql_float" null="#len(pr) EQ 0#">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'qty') AND NOT isNull(row.qty) ? row.qty : ''#" cfsqltype="cf_sql_float" null="#NOT structKeyExists(row, 'qty') OR isNull(row.qty)#">,
|
<cfqueryparam value="#qt#" cfsqltype="cf_sql_float" null="#len(qt) EQ 0#">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'sum') AND NOT isNull(row.sum) ? row.sum : ''#" cfsqltype="cf_sql_float" null="#NOT structKeyExists(row, 'sum') OR isNull(row.sum)#">,
|
<cfqueryparam value="#sm#" cfsqltype="cf_sql_float" null="#len(sm) EQ 0#">,
|
||||||
<cfqueryparam value="#structKeyExists(row, 'date_start') AND NOT isNull(row.date_start) ? row.date_start : ''#" cfsqltype="cf_sql_varchar" null="#NOT structKeyExists(row, 'date_start') OR isNull(row.date_start)#">
|
<cfqueryparam value="#ds#" cfsqltype="cf_sql_varchar" null="#len(ds) EQ 0#">
|
||||||
)
|
)
|
||||||
</cfquery>
|
</cfquery>
|
||||||
<cfset arrayAppend(savedRows, row)>
|
<cfset arrayAppend(savedRows, row)>
|
||||||
|
|||||||
Reference in New Issue
Block a user