v1.0.21: промпт на сервере (prompt.cfm + БД)
This commit is contained in:
@@ -64,7 +64,7 @@
|
||||
<body>
|
||||
<div class="topbar">
|
||||
<img src="/nubes-logo.svg" alt="Nubes">
|
||||
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.20 — Lucee</span></span>
|
||||
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.21 — Lucee</span></span>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
@@ -431,9 +431,30 @@ document.getElementById('btnFull').addEventListener('click', async function() {
|
||||
|
||||
// ── Промпт ─────────────────────────────────────────────────
|
||||
var promptEditor = document.getElementById('promptEditor');
|
||||
promptEditor.value = localStorage.getItem('llm_prompt') || '';
|
||||
// Загружаем промпт с сервера при появлении contract_id
|
||||
var origUploadNext = null;
|
||||
(function() {
|
||||
var checkPrompt = setInterval(function() {
|
||||
if (contractId) {
|
||||
clearInterval(checkPrompt);
|
||||
fetch('/prompt.cfm?contract_id=' + contractId)
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(d) { if (d.OK) promptEditor.value = d.PROMPT || ''; });
|
||||
}
|
||||
}, 500);
|
||||
})();
|
||||
// Автосохранение на сервер при изменении
|
||||
var promptTimer = null;
|
||||
promptEditor.addEventListener('input', function() {
|
||||
localStorage.setItem('llm_prompt', this.value);
|
||||
clearTimeout(promptTimer);
|
||||
promptTimer = setTimeout(function() {
|
||||
if (!contractId) return;
|
||||
fetch('/prompt.cfm?contract_id=' + contractId, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({prompt: promptEditor.value})
|
||||
});
|
||||
}, 800);
|
||||
});
|
||||
|
||||
// ── Чат ───────────────────────────────────────────────────
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<cfsetting showdebugoutput="no" enablecfoutputonly="true">
|
||||
<cfheader name="Content-Type" value="application/json; charset=utf-8">
|
||||
<cfheader name="Access-Control-Allow-Origin" value="*">
|
||||
|
||||
<cfif cgi.request_method EQ "OPTIONS"><cfoutput>OK</cfoutput><cfabort></cfif>
|
||||
|
||||
<!--- Создать таблицу при первом обращении --->
|
||||
<cftry>
|
||||
<cfquery datasource="baza">
|
||||
CREATE TABLE IF NOT EXISTS prompts (
|
||||
contract_id UUID PRIMARY KEY REFERENCES contracts(id),
|
||||
prompt_text TEXT NOT NULL
|
||||
)
|
||||
</cfquery>
|
||||
<cfcatch></cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfparam name="url.contract_id" default="">
|
||||
|
||||
<cfset result = {ok: false, error: ""}>
|
||||
|
||||
<cftry>
|
||||
<cfif NOT len(url.contract_id)>
|
||||
<cfset result.error = "contract_id required">
|
||||
<cfelseif cgi.request_method EQ "POST">
|
||||
<!--- Сохранить промпт --->
|
||||
<cfset body = toString(getHttpRequestData().content)>
|
||||
<cfset data = deserializeJSON(body)>
|
||||
<cfset prompt = structKeyExists(data, "prompt") ? data.prompt : "">
|
||||
|
||||
<cfquery datasource="baza">
|
||||
DELETE FROM prompts WHERE contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
|
||||
</cfquery>
|
||||
<cfif len(trim(prompt))>
|
||||
<cfquery datasource="baza">
|
||||
INSERT INTO prompts (contract_id, prompt_text) VALUES (
|
||||
<cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">,
|
||||
<cfqueryparam value="#prompt#" cfsqltype="cf_sql_varchar">
|
||||
)
|
||||
</cfquery>
|
||||
</cfif>
|
||||
<cfset result = {ok: true, saved: len(trim(prompt)) GT 0}>
|
||||
<cfelse>
|
||||
<!--- Получить промпт --->
|
||||
<cfquery name="q" datasource="baza">
|
||||
SELECT prompt_text FROM prompts
|
||||
WHERE contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
|
||||
</cfquery>
|
||||
<cfset result = {ok: true, prompt: q.recordCount GT 0 ? q.prompt_text : ""}>
|
||||
</cfif>
|
||||
<cfcatch>
|
||||
<cfset result = {ok: false, error: cfcatch.message}>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfoutput>#serializeJSON(result)#</cfoutput>
|
||||
Reference in New Issue
Block a user